6 Replies Latest reply on Jul 22, 2020 3:16 PM by Andreas Moeller

    #variables# in code templates


      In code templates can someone explain how to use the substitution variables that appear in the lower half of the preferences screen (e.g. #date#, #user#, #for#) ?


      Also, what does the "Auroreplace" checkbox actually control ?

        • 1. Re: #variables# in code templates
          Glen Conway

          With repect to "Autoreplace", thatJeffSmith-Oracle talks about it in a recent update (April 17, 2020) to an old blog post:




          Basically, if checked, Code Insight will work properly to replace the template ID with the template value using only the keyboard's space bar rather than having to select it from the popup list.


          In the same blog post, if you search for "Can you explain how to use #time#, #date#" in the Comments section, Jeff said a  few years ago (and I assume it hasn't been fixed since I've never figured it out either!)

          I’ve never been told how that’s supposed to work. As far as I’m concerned they’re unusable.

          What can be done to work around that limitation?  Just add a few more template IDs:

          dt = to_char(sysdate, 'YYYY-MM-DD') as "Date"

          tm = to_char(sysdate, 'HH24:MI:SS') as "Time",

          us = user as "User"



          1 person found this helpful
          • 2. Re: #variables# in code templates
            Glen Conway

            But it seems there exist old discussions on this forum claiming #variables# used to work, but not for me...

                SQL Editor Code template: Date format of Id #date# #time#

            and even older...

                SQLDEV 4EA1: code editor: code templates don't work


            But I suppose we should be looking forward, rather than backward!

            • 3. Re: #variables# in code templates
              Mike Kutz

              Just jumping in:


              The only variable I'd want/need working is #OWNER#.  This would allow me to make sure my Object Creation scripts will work when used in an APEX App.


              My $0.02



              • 4. Re: #variables# in code templates

                To get the #date# style templates to work, you have to use your mouse to activate the code template, the insight (ctrl+space) doesn't work - I've filed a bug



                1 person found this helpful
                • 5. Re: #variables# in code templates

                  Thanks. Appears rather broken, though. If i select a query in a worksheet (any query, it seems), and select "code template" from that right-click menu, i get a for loop based on said query, even though i am not using a template nor have i mentioned #for# anywhere in the worksheet. Odd, but unimportant, i was mostly curious.

                  • 6. Re: #variables# in code templates
                    Andreas Moeller

                    I'm working with SQL Developer

                    The use of #variables# in templates is possible, but unsatisfactory. If variables like #user# or #date# are added to a template, my expectation is that these will be substituted directly when the template is loaded. Unfortunately, you have to select the variable or select the entire code block and then select Code_Template in the context menu. At this moment the template loses the substitution fields that can be reached via the tab. Very unfortunate! The following procedure is possible when dealing with templates:

                    * Load a template with [substitution fields] and #variables#

                    * Jump through the substitution fields with the tab and fill them

                    * Mark the whole block of code

                    * Replace the variables by executing Code_Template from the context menu


                    Incidentally, the variable #osuser# is missing and would be very helpful here for documentation purpose

                    1 person found this helpful