1 Reply Latest reply on Feb 4, 2019 10:21 PM by Vadim Tropashko-Oracle

    SQL Developer - Code Format

    Cihan Eksi

      Hi,

       

      I have started to use Sql Developer. And i try/use  "Code Format template". i like using lines break on procedure arguments . but i don't want to do the same thing on some functions , for example NVL etc. What else can i do ? have you got any suggestions ?

       

       

                

        • 1. Re: SQL Developer - Code Format
          Vadim Tropashko-Oracle

          To amend the custom format arbori program let's examine parse tree first:

           

                [22,37)  if_stmt  labeled_nonblock_stmt  nonblock_compound_stmt  stmt  unlabeled_nonblock_stmt

                  [22,23)  'IF'

                  [23,31)  and_expr  boolean_primary  pls_expr  rel

                    [23,29)  arith_expr  factor  function_call  name  pri  procedure_call  sim_expr  term

                      [23,24)  identifier  name  name_wo_function_call

                      [24,29)  paren_expr_list

                        [24,25)  '('

                        [25,26)  and_expr  arg  arith_expr  boolean_primary  factor  identifier  name...

                        [26,28)  arg_list

                          [26,27)  ','

                          [27,28)  and_expr  arg  arith_expr  boolean_primary  factor  ...

                        [28,29)  ')'

                    [29,31)  relal_op_sim_expr_opt

                      [29,30)  '>'  relal_op

                      [30,31)  arith_expr  digits  factor  numeric_literal  pri  sim_expr  term

                  [31,32)  'THEN'

                  [32,34)  exit_stmt  labeled_nonblock_stmt  seq_of_stmts  sim_stmt  stmt  unlabeled_nonblock_stmt

                    [32,33)  'EXIT'

                    [33,34)  ';'

                  [34,35)  'END'

                  [35,36)  'IF'

                  [36,37)  ';'

           

          The nodes of interest are labeled with "procedure_call", "paren_expr_list". Let's spot all the conditions in the arbori format program that affect those nodes.

           

          simpleIndentConditions:

          ...

          | :breaksProcArgs & [node) arg & [node^) paren_expr_list & [node+1) arg_list & ! ?node^-1 = 'NVL'

          | :breaksProcArgs & [node) arg_list & [node^) paren_expr_list & [node-1) arg & ! ?node^-1 = 'NVL'

           

          This condition indents arguments inside the parenthesis list if the Advanced Format option to insert breaks for procedure arguments is set. I have added additional condition highlighted in green for that function not to be "NVL".

           

          The other formatting rule that inserts line breaks after the commas is the "extraBrkAfter". Here is the amended rule (together with auxiliary rule "commasInNVL"):

           

          commasInNVL: [node) ','

                 & args < node

                 & ( [args) "(x,y,z)" | [args) paren_expr_list )

                 & (?args-1 = 'NVL' | ?args-1 = 'other built in function')

          ;

           

          extraBrkAfter:

            ( _extraBrkAfter - commasInProc)

          | :breaksAfterComma & :breaksProcArgs & (commasInProc-commasInNVL)

          ->;

           

          The format output:

           

          BEGIN

              SELECT

                  nvl(x, 'NULL')

              FROM

                  dual;

           

              proc4(

                  1,

                  2,

                  3,

                  4

              );

              IF nvl(x, 'NULL') > 3 THEN

                  EXIT;

              END IF;

          END;