Bind Variables and using the keyword

In my dynamic SQL, I use the same variable in several places in my query. Is there a way to avoid rewriting the same value multiple times in the list of arguments to bind? It is something like that - only pseudo code.
DECLARE
tSQL VARCHAR2(99)
pVal INT := 2;

BEGIN
tSQL := 
           'SELECT * ' ||
           '  FROM dual ' ||
           ' WHERE col1 =: iVal ' ||
           '   AND col2 IN (SELECT col2 ' ||
           '                  FROM dual  ' ||
           '                 WHERE col1 =: iVal) ' ||
           ' UNION ' ||
           ' SELECT * ' ||
           '   FROM dual ' ||
           '  WHERE col1 =: iVal';

EXECUTE IMMEDIATE tSQL 
USING pVal, pVal, pVal;  -- Is there a way to avoid having to rewrite the same bind variable argument three times since the value is the same?

END;
Is there a way to avoid having to rewrite the same argument three times bind variable as the value is the same?

Etbin wrote:
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/dynamic.htm#BHCHIHEJ says:
Placeholders are associated with bind variable in the USING clause of position, and not by name.

Concerning

Etbin

The exception to this rule is if the SQL statement is an anonymous block or a call statement. In this case, the repetition of the names of the placeholder is significant.

http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/dynamic.htm#CHDFHEAG

For example, the following will fail with ORA-01008: not all variables

declare
 v_cnt number;
begin
  execute immediate 'select count(*) from dual where 1 = :B1 and 2 > :B1'
  into v_cnt using 1;
  dbms_output.put_line(v_cnt);
end;

However, the following will succeed because the SQL code is in fact an anonymous block:

begin
  execute immediate 'declare
                       v_cnt number;
                     begin
                       select count(*)
                       into v_cnt
                       from dual
                       where 1 = :B1 and 2 > :B1;
                       dbms_output.put_line(v_cnt);
                     end;'
  using 1;
end;

Pretty cool stuff.

Tags: Database

Similar Questions

  • SQL how to use a variable and use the result as a reference for the name of the table

    Hi all

    I have new in the declaration of Oracle, sorry in advance if something is easy for you all. BTW, I have this scenario:

    I have a table OL structured in this way:

    Date - it contains dates, for example 11/01/2015

    TableName - it contains strings, for example, OL1, OL2, OL3 and so on...

    Then I have a different table, the name of these tables are of the same name in the table of the OL, so I have table table, OL1, OL2, OL3 table and so on. The structure of these tables is the same. And Yes.

    table OL1

    ---------------------------------------------------------------

    ID LAST NAME FIRST NAME PHONE

    ---------------------------------------------------------------

    1 JOHN DOE 12345679

    2 PAUL 111111122 TIBBS

    table OL2

    ---------------------------------------------------------------

    ID LAST NAME FIRST NAME PHONE

    ---------------------------------------------------------------

    1 ANNA KRAIG (NULL)

    NATHAN FRESHMANN 111111133 2

    If the scenario is clear, I would like to retrieve the value (null), research in all the OL * tables by using the value of the OL table (tablename) max.

    If I'm going to do these simple steps, I got the result:

    Select max (TableName) OL

    the result will be OL2

    # I know not how to use the option set to avoid changing the table name in the sql statement all the time.

    set mytable = 'OL2.

    Select Name, family name

    of & mytable

    When the phone is null

    Any idea?

    Thank you very much in advance.

    Hello

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    bulk collect into v_result_set

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null';

    dbms_output.put_line (v_ol);

    end;

    Correct the code such as:

    run immediately "select dt.log_id, obj.presentation_name, dl.begin_time

    of ' | v_ol |' dt join internal ol_object obj on

    DT.object_type_id = obj.object_type_id

    inner join ol_chunk_log dl on

    DT.log_id = DL.log_id

    where dt.data_value is null' bulk collect into v_result_set;


    for i in v_result_set.first ... v_result_set. Last

    loop

    dbms_output.put_line ('LOG ID: ' | ) ( v_result_set.log_id (i)) ;

    dbms_output.put_line (' NAME CLOSELY: ' |) v_result_set.presentation_name (i));

    dbms_output.put_line (' START TIME: ' |) ( v_result_set.begin_time (i)) ;

    end loop;

    end;

    Kind regards.

  • definition of variables in packages and using the same variables in charge Plans as a case statement in Odi

    Hello

    I am trying to use a global variable 'Global.test' in my ODI "pkg_test" package and step declaration type as a variable that is defined with the value 1 when my package evaluates the condition successfully run and with 0 if the fails.now condition I will carry out the same "pkg_test" package in my load "LP_TEST" and using the variable 'Global.test' Plan as a case statement in terms of load "LP_TEST".

    It's workload Odi is unable to understand the value of the variable 'Global.test', which is defined in my pkg 'pkg_test' and my case statement is put down in my care Plan.

    Thank you

    Hi Santosh Pradhan,

    What kind of story do you have in your variable?

    If you have not selected any antecedent, the scope of the variable is limited to the session. As the execution of the package is a session in its own (independent of the workload performance), the value of the variable is not accessible after his execution.

    You can also try assigning / updating of the value of the variable directly from your plan, instead of in the package:

    It will be useful.

    Best regards

    JeromeFr

  • Hello experts, I use Adobe forms in SAP. My question is, is there a any restriction for additem keyword in JavaScript? I mean, even if I use the keyword additem to add the name and value of a drop-down list, it adds up to 10000 files only. Please s

    Hello experts,

    I use Adobe Forms in SAP.

    My question is, is there a any restriction for additem keyword in JavaScript?

    I mean, even if I use the keyword additem to add the name and value of a drop-down list, it adds up to 10000 files only.

    Please sugest

    A drop-down list is the bad INTERFACE design where an element can contain more than 100 entries. It is very good in tests, but absolutely unacceptable if the form must be used by a person busy doing their work. The choice of Acrobat forms are limited, but consider a list box. Despite this, there may be limits imposed by the system or the implementation.

    Better would be

    (a) stop filling after awhile the list and add an entry saying several elements not shown, running report or use better filter

    (b) be available for all filtering of course lists

  • href="file://f://myfile.ext would not specify the hard drive and use the same directory as my html file.

    When you use href="file://f://myfile.ext' it will open fine in Firefox 3.6.8. However, I wish NOT hard code hard drive and use the location of the same player if my html file that calls this href link.
    I tried to use href="file:///myfile.ext" and it does not work. I get an error message saying file not found.
    For ie browser I can just specify href = "" / myfile.ext "and it works very well."
    This is a simple html file that refers to several local files and I have everything on a usb key (IE my F drive). The memory stick will be sent to several people and their USB can be another letter.

    I found a solution to my problem. Found I could just specify
    href = "MyFile.ext" and he will see when he's in the same directory as the html code containing the reference. " No need for extra slashes!

  • My iMac cursor is stuck in the upper left corner of the login screen and I can't move it and now I can't use my iMac. What can I do? My iMac is a 27-inch 2014 release (one thin without retina display) and uses the keyboard and wireless mouse.

    My iMac cursor is stuck in the upper left corner of the login screen and I can't move it and now I can't use my iMac. What can I do? My iMac is a 27-inch 2014 release (one thin without retina display) and uses the keyboard and wireless mouse. It runs OSX Mountain Lion (not sure which version) and is a model 27 inches.

    have you tried to change the batteries in the mouse?

  • Can I connect my WiiU to my iMac and use the iMac is a screen to play games?

    Can I connect my WiiU to my iMac and use the iMac as a screen to play games WiiU on it?

    N °

  • Continue to try to turn on my firewall, but won't automatically and using the manual option does not work either.

    Continue to try to turn on my firewall, but won't automatically and using the manual option does not work either.  Can repair you.

    Hello
    Follow these instructions:
    Download and install Windows Repair:
    When the repair of Windows opens, click on the tab to start repairs, click Start. Uncheck all boxes except for the following:
    -Reset the registry permissions
    -Reset the permissions of files
    -WMI repair
    -Repair Windows Firewall
    Then click Start. Once it is finished, restart your computer. Let us know if that helps you.
    Brian
  • Buy server windows 2008 32 if I download the 64-bit and use the 32-bit key original that it will work?

    Buy server windows 2008 32 if I download the 64-bit and use the 32-bit key original that it will work?

    Hi George,.

    The issue of Windows is more complex than what is generally answered in the Microsoft Community Forums. Appropriate in the TechNet Forums. Please post your question in the TechNet Forums.

    You can check the link to post your question:

    http://social.technet.Microsoft.com/forums/en-us/category/WindowsServer

    I hope that helps!

  • When my battery is fully charged, what button I press to turn off the battery and use the DC

    When my battery is fully charged, what button I press to turn off the battery and use the DC. I need to know what to do to avoid the impoverishment of my battery. OR is it save to leave the computer on, even when the battery is fully charged

    Well, actually from what I read, it's correct exactly as it goes, but not a complete list of the maintenance of the batteries all the factors, methods, practices and details regarding the definition of periodicals.

    While he was just more info not really part of what has been requested, this is why I don't give him properly a collection, I appreciate that you expand on it with greater precision.

    It is not often that one of my messages is considered as not long enough.  :-)

    Thanks for the help.

  • How to activate and use the built-in webcam

    built in webcam

    How to activate and use the built in webcam on my desktop Dell Inspiron 1?

    MikeViklund,

    Try to read...

    Use and troubleshooting of the Webcam Dell and Dell Webcam Central Software

    Rick

  • How to select a cell in a multicolumn list box and use the horizontal scrollbar on th

    An event structure, how to select a cell in a multicolumn list box and use the horizontal scrollbar on the front panel at the same time.  I can select a cell in the multicolumn in a structure of the event, but I can't move the scroll bar on the front panel when the program is running.

    I guess that you are referring to the scroll bar in the control multi-column listbox. What does your code when you select a cell? Can you please your postal code so that we can see the behavior you describe? It is possible that you are blocked the structure of the event, as in performing an operation long in case the treatment cell selection. In this case, the structure of the event must wait until the event ends before being able to respond to the next event. You can configure the event to not lock the front panel until the event ends.

  • I use Windows 10 and use the Canon SX20 IS. How to use the function of Photo stich?

    I use Windows 10 and use the Canon SX20 IS. How to use the function of Photo stich?

    Is it possible to get the procedure to use feature stich photo?

    Will be Zoombrowser EX for windows 10 wotk?

    If any expert can guide me... that will be great.

    Hi Sat17,

    Thank you for your inquiry.

    For Windows 8 and beyond, ZoomBrowser EX has been replaced by EX. ImageBrowser

    Your software you will need to updated for Windows 10.

    You can access the software for your camera by clicking here.  Once on our site, scroll down to "Drivers and downloads", then use the drop down menu to choose "8.1 Windows" or "Windows 8.1 (x 64)".»  Your camera software has not been updated for Windows 10, but for Windows 8.1 software will run on your computer.

    To update your software, click the [Select] button to the right, then click on "How to download and install" for installation instructions.

  • Replace the HDD with SSD boot disk and use the disk HARD now as secondary storage

    I would like to replace my dv7 - 6143cl HDD with a SSD boot drive and using the OEM HARD drive as secondary storage.

    I have the SSD and the caddy

    I need to:

    delete the original OEM HD

    Install the SSD

    install OEM HARD drive in secondary Bay

    Install Win 7 (I don't have install disks - what is on the HARD drive in his backup partition)

    or I have to

    delete this HD

    Install the SSD

    go into the BIOS, and then assign him drive in AHCI (etc.)

    Install Win 7

    install OEM HARD drive in secondary Bay

    etc.

    I want to dual-boot, if possible, but I think that the second HD (start-up disk) does not start, even if I change the settings in the BIOS

    is this true?

    Pavilion dv7 - 6143cl

    I7

    8Gb

    Win7 (64)

    Thank you very much

    Hello:

    Your BIOS is set to AHCI (or RAID) by default. It cannot be changed.  Look in your device manager and in the IDE ATA/ATAPI controllers section, look to see if there is a controller SATA ACHI he.

    If so, you have an AHCI BIOS default.

    If you go further down the line in Device Manager and see a section of storage controllers, click on that, you would see a SATA RAID controller and your BIOS is set to default RAID.

    I don't have your model laptop so I don't know if HP has implemented some models double disk RAID or AHCI.

    So... First, copy your original C:\ drive SWSetup folder and save that to a portable hard drive. That must contain all the files installation for the drivers and the software provided with your PC. You can search this folder for programs that you may want to reinstall after your new SSD drive HARD primary.

    To install W7 on your SSD, check your own install of W7 disc.  Here's how:

    If you can read the Microsoft windows 7 25-character product key, you can download simple Windows 7 ISO files to burn on a DVD for the version of windows that is installed on your PC, and which is listed on the Microsoft COA sticker on your PC case.

    Burn the ISO with the option to burn the ISO on your DVD burning program and burn it at the slowest possible speed that will allow your program. This will create a bootable DVD.

    Or use the installation of Windows 7 USB/DVD tool to compile the ISO file that you download from Digital River. Link and instructions below. You need a 4 GB flash drive to use the USB compilation method.

    http://www.microsoftstore.com/store/msstore/HTML/pbPage.Help_Win7_usbdvd_dwnTool

    Use 25 characters on the PC product key to activate the installation.

    The key will activate a 32 or 64 bit installation.

    Then go to the support of the PC and driver page to install the drivers you need.

    Link to downloads ISO of W7 is below.

    http://www.mydigitallife.info/official-Windows-7-SP1-ISO-from-Digital-River/

    Can't answer your question on the dual boot as I never did before.

    Paul

  • where to find and use the (HCL) hardware compatibility list for Windows xp3

    Original title: where to find and use the Windows (HCL) hardware compatibility list

    HCL for Windows xp3

    That does not "response" from MS Support Engineer Umesh was particularly useless.

    Unfortunately for you, the HCL XP (or Windows Catalog or Windows Marketplace or whatever it is renamed) no longer exists.  I guess Microsoft is not particularly interested in letting you know what the material is compatible with an operating system that is no longer, it sells and supports only.

    The trail begins here: "the latest Windows XP Hardware Compatibility List" (314062 KB) that leads to theWindows 7 Compatibility Center.  KB 314062 is also linked to the http://www.windowsmarketplace.com/ which used to have a list of compatible with XP hardware and software, but now redirects to the Microsoft store, another dead end that XP is concerned.

    If you really want to dig, your best bet is probably used the Wayback Machine (archive.org) looking for old copies of

    http://www.microsoft.com/whdc/hcl/default.mspx - but a lot of links are broken or "not supported" unless you use Internet Explorer 6 (the message claims 6 'or more' but 8 does not work).

Maybe you are looking for

  • 10.11.6 to early 2016 new macbook os update problem

    Hello I recently buy a new macbook 12 ". So far the only problem I have is upgrade to the latest OS. I click on update for it in the App store and it shows the time it takes to complete the update. When she is close to completing the update, it stops

  • Service Control Manager: atapi PCIIde message occurs

    Hello I started having this problem now after changing the compatibility mode on AHCI (think it's like that lol) Ive reinstalled the thing from the site Web of Toshiba Intel Storage Manager, I even installed the one directly from the Intel Web site w

  • Missing keys

    I have a couple of missing keys. Do you sell individual keys or where I can buy?

  • Aurora R4 - adding an SSD with RAID 0 HHDs

    I have a R4 Aurora with stock HHDs in a RAID 0 configuration.  I'm not ready to replace the HHDs as MBR disks, but I want to add the SSD in an empty Bay.  After reading the forum several messages a BIOS setting must be in for the SSD AHCI mode to be

  • BlackBerry Smartphones bb apps 80003 world error

    I am able to load the apps UN world.