1 2 Previous Next 15 Replies Latest reply on Aug 5, 2020 9:24 PM by Mike Kutz

    Code Formatter

    Carlos Cevallos

      Greetings SQLDev Team

      The TOAD tool has an excellent code formatter and I would like to know if with SQL Developer could I get the same result in the code format?

      If so, how could you obtain information to achieve the objective?

      Thank you so much !

        • 1. Re: Code Formatter
          thatJeffSmith-Oracle

          Please share your desired result.

           

          Also, what version of SQL Developer are you using?

          • 2. Re: Code Formatter
            Carlos Cevallos

            Good day,
            The version of SQ Developer I use is 20.2.0.175

             

            Thank you

            • 3. Re: Code Formatter
              thatJeffSmith-Oracle

              cool, now how would you like your sql formatted?

              • 4. Re: Code Formatter
                Carlos Cevallos

                Thanks for answering,

                 

                I pass an image of the differences in the format that can be obtained in both tools.

                 

                SQL Developer format:

                 

                TOAD for Oracle format:

                This is an example of how I have configured it now.

                 

                 

                In the TOAD tool, you can configure in advance the format you want to obtain for SQL and / or PLSQL statements.

                 

                I would like to know if I can achieve this kind of customization in the format for the SQL Developer tool

                 

                Thanks and have an excellent day.

                • 5. Re: Code Formatter
                  Vadim Tropashko-Oracle

                  format.png

                  Can you please export Advanced settings to see what other options have you changed? Also the misalignment that you exhibited might be caused by the rules at the end of program failing. Can you please reset the Custom Format?

                  • 6. Re: Code Formatter
                    thatJeffSmith-Oracle

                    there's not much we can do with screenshots of code

                    • 7. Re: Code Formatter
                      Carlos Cevallos

                      Good day,

                      Regarding code formatting, I must maintain a coding format that allows the developers team to understand the code as intuitively as possible (more readable and clean) for the identification of problems and improvements in the programs.

                      That is why formatting the code is very important to my team.

                      Attachment code formatted with the TOAD tool :

                      • 8. Re: Code Formatter
                        Carlos Cevallos

                        CREATE OR REPLACE PACKAGE BODY emp_mgmt

                        AS

                           tot_emps   NUMBER;

                           tot_depts  NUMBER;

                         

                         

                           FUNCTION hire(last_name       VARCHAR2

                                        ,job_id          VARCHAR2

                                        ,manager_id      NUMBER

                                        ,salary          NUMBER

                                        ,department_id   NUMBER)

                              RETURN NUMBER

                           IS

                              new_empno  NUMBER;

                           BEGIN

                              IF Monthly_Value <= 4000

                              THEN

                                 Ilevel  := 'Low Income';

                              ELSIF Monthly_Value > 4000 AND Monthly_Value <= 7000

                              THEN

                                 Ilevel  := 'Avg Income';

                              ELSE

                                 Ilevel  := 'High Income';

                              END IF;

                         

                         

                              CASE

                                 WHEN jobid = 'PU_CLE'

                                 THEN

                                    sal_raise  := .09;

                                 WHEN jobid = 'SH_CLERK'

                                 THEN

                                    sal_raise  := .08;

                                 ELSE

                                    sal_raise  := 0;

                                    DBMS_OUTPUT.PUT_LINE('sal_raise := 0');

                              END CASE;

                         

                         

                              SELECT CASE "1" WHEN 1 THEN 'XX' END

                              INTO   new_empno

                              FROM   emp, DUAL d1, DUAL d2

                              WHERE      (1 = 2 OR 3 = 4)

                                     AND 0 = 1 + 2

                                     AND EXISTS

                                            (SELECT 1, 2, 3

                                             FROM   wsh_new_deliveries wnd

                                                    JOIN wsh_delivery_assignments wda ON wnd.delivery_id = wda.delivery_id

                                                    JOIN hz_locations hl ON hps.location_id = hl.location_id);

                         

                         

                              INSERT INTO employees

                              VALUES      (new_empno

                                          ,'First' || 'Middle' || 'Last'

                                          ,'(415)555-0100'

                                          ,TO_DATE('18-JUN-2002', 'DD-MON-YYYY')

                                          ,'IT_PROG'

                                          ,90

                                          ,100

                                          ,110);

                         

                         

                              tot_emps              := tot_emps + 1; -- := alignment

                              out_rec.var_char1     := in_rec1.first_name;

                              out_rec.var_char2222  := in_rec1.last_name;

                             

                              proc1(p1111 => a1, p11 => a1, p2 => a2);

                             

                              RETURN (new_empno);

                           END;

                        END emp_mgmt;

                        /

                        • 9. Re: Code Formatter
                          Carlos Cevallos

                          The font that we use in the code is monospace.

                          • 10. Re: Code Formatter
                            Philipp Salvisberg
                            I would like to know if I can achieve this kind of customization in the format for the SQL Developer tool

                             

                            Yes you can. For that you need to change the Arbori program to format the code the way you like it. That's called "Custom Format" in SQL Developer

                             

                            However, If you do not want to write Arbori code then you have to live with what "Advanced Format" provides. You can configure some settings, but in the end the configuration is limited. Here's an example based on my Arbori program (I do not handle spaces after comma correctly, therefore I added a space, I also remove line-breaks before "THEN", because that's the way I like it in most cases):

                             

                            diff_toad_sqldev.png

                             

                            There are a lot of differences. No way you can make them 100% identical with "Advanced Format" only. You have either live with the differences or just bite the bullet and do all the necessary changes in the Arbori program to make the formatting result 100% identical. No magic here, but I'm sure it is possible. If you take the Arbori route, you may also decide to ignore all "Advanced Format" settings in the Arbori program and hard-code just the variant you want to support. This will make the Arbori program a bit simpler. Some configuration variants are really conflicting and this increases the complexity of the Arbori program.

                             

                            In the end you have to be aware that it's all about beautifying the code. And almost every developer has her/his own views on what makes code look good. So don't be surprised if some developer approach you with their view how the code should look like ;-)

                            2 people found this helpful
                            • 11. Re: Code Formatter
                              thatJeffSmith-Oracle

                              Custom formatting is for the most advanced users like you, Philipp

                               

                              Everyone else, get as close as you can with the actual preferences, and when you fall short, let us know here, and we can extend the preferences/features as necessary. We've been doing that with every release over the past several years.

                              • 12. Re: Code Formatter
                                Carlos Cevallos

                                Thank you very much for answering.

                                 

                                I am going to learn arbori to get the format I want.

                                Thank you for sending me material on arbori.

                                 

                                Thank you very much

                                • 13. Re: Code Formatter
                                  Philipp Salvisberg

                                  You're welcome.

                                   

                                  Please consider thatJeffSmith-Oracle's comment and do not underestimate the complexity of Arbori. It's one thing to add/change a condition here and there as a workaround until a solution is provided by the SQLDev team. But fundamentally changing the formatting result in a consistent manner and keeping up with grammar enhancements of new SQLDev versions is a lot of work.

                                   

                                  In any case I'm interested in the result. Could you please share it, e.g. on GitHub?

                                   

                                  Thank you,

                                  Philipp

                                  • 14. Re: Code Formatter
                                    Mike Kutz

                                    Philipp Salvisberg wrote:


                                    In any case I'm interested in the result. Could you please share it, e.g. on GitHub?

                                     

                                    Thank you,

                                    Philipp

                                    Ditto.

                                     

                                    (yeah.. i could just keep up with the response by "following" this thread)

                                    I share mine but I haven't moved my personal ones to GitHub yet.

                                    1 2 Previous Next