2 Replies Latest reply on Oct 18, 2017 2:57 PM by 291771

    If/then formatting in sql developer

    291771

      The SQL Deveoper version 17.2 puts line breaks afre IF and THEN keywords whatever options i choose in formatting options. I would like to have IF condtion THEN in one line, how can I change that ?

       

      -- create_package_body.htm#LNPLS01381 

      CREATE OR REPLACE PACKAGE BODY emp_mgmt AS

       

       

          tot_emps    NUMBER;

          tot_depts   NUMBER;

       

       

          FUNCTION hire (

              last_name       IN VARCHAR2,

              job_id          IN VARCHAR2,

              manager_id      NUMBER,

              salary          NUMBER,

              department_id   NUMBER

          ) RETURN NUMBER IS

              new_empno   NUMBER;

          BEGIN

              IF

                  last_name IS NULL

              THEN

                  NULL;

              END IF;

          END;

       

       

      END emp_mgmt;

      /

      -

        • 1. Re: If/then formatting in sql developer
          Vadim Tropashko-Oracle

          There is advanced option for that (Line Breaks->IF->After IF). Unfortunately, it doesn't seem to have any effect.

           

          On custom format page comment the following:

           

          --> | [node) rel  & [node) condition

           

          and

           

          --> | [node) pls_expr & [node^) nonblock_compound_stmt  -- e.g. IF CASE a WHEN 3 THEN 4 ELSE a END > 7 THEN

           

          P.S. In 17.3 there are at least 3 alternative ways how to do that:

           

          i. Remove --> | [node) pls_expr ... in simple indents (Same as for 17.2)

           

          ii. Edit

          ignoreLineBreaksBeforeNode:

             !:breaksBeforeComma &    [node) ','

          |  [node) ';'

          | [node) pls_expr  &  [node-1) 'IF'

          -- | [node) ')'

          ->

          ;

          ignoreLineBreaksAfterNode:

             !:breaksAfterComma &    [node) ','

          | [node) pls_expr  &  [node-1) 'IF'

          ->

          ;

           

          How can you know that you are interested in pls_expr? Just paste the code fragment into the editor and see what is on the parse tree:

           

          line break after if.png

           

          iii.

          ignoreLineBreaksBeforeNode:

             !:breaksBeforeComma &    [node) ','

          |  [node) ';'

          | [node^) if_stmt  &  [node) 'THEN'

          -- | [node) ')'

          ->

          ;

          ignoreLineBreaksAfterNode:

             !:breaksAfterComma &    [node) ','

          | [node^) if_stmt  &  [node) 'IF'

          ->

          ;

           

          Please note that if you remove additional condition for the parent node being if_stmt, then it would remove breaks before THEN and after IF regardless of syntactic content.

          • 2. Re: If/then formatting in sql developer
            291771

            Thanks, I will try that