Help setting Parameters using JDBC and Bind Variables for Oracle List

I fully understand the concept of using Bind Variables when using JDBC to avoid hard parses everytime my SQL statement is executed when only a certain value changes. For example, perhaps I have the following statement:
PreparedStatement ps = con.prepareStatement("select salary from employees where employee_id = ?");
I would then set the value of the question mark (the first and in this case only parameter) using:
ps.getStmt().setString(1,empId1);
That is assuming I have the variable empId1 populated with what I want. Anyway, my question has to do with Oracle lists. In other words, if I am just executing the statement against the db, it might look like:
select salary from employees where employee_id in ('123','456','789');
I still want to use bind variables and I can do it in JDBC with something like:
select salary from employees where employee_id in ('123','456','789');
ps.getStmt().setString(1,empId1);
ps.getStmt().setString(2,empId2);
ps.getStmt().setString(3,empId3);
BUT, what if I just want to construct my list of ids upfront as a string and do something like:
select salary from employees where employee_id in (?)
ps.getStmt().setString(1,listOfEmpIds);where listOfEmpIds would look something like '123','456','789'.
That's what I want to do but it doesn't work. It would be treating the list as a single parameter as opposed to lots of individual parameters. Can someone please tell me the syntax for this if it is possible? I have tried where XX in (?) and where XX in ? (and the string I substitute has the parenthesis in it), but neither work.
Thank you for your help.

I always build the list myself.
You could, however, pass the list as a varchar to a stored proc and then have the stored proc parse (or dynamically execute) using it.
The second method might even be faster although I would suspect that is only going to be the case if the list is very large. Or it might not.

Similar Messages

  • Why CBO don't use function-base index when I use like and bind variable

    Hello
    I have litle problem with function-base index and like with bind variable.
    When I use like with bind variable, the CBO don't use my function-base index.
    For example when I create table and index:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    alter session set nls_language='ENGLISH';
    -- DROP TABLE TEST1;
    CREATE TABLE TEST1 (K1 VARCHAR2(32));
    create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI'));
    INSERT INTO TEST1
    SELECT OBJECT_NAME FROM ALL_OBJECTS;
    COMMIT;
    When I run:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    SELECT * FROM TEST1 WHERE K1 = 'abcd';
    or
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%';
    CBO use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 4vrmp7cshbvqy, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%'
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 2 | 98 | 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 2 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$">=HEXTORAW('6162636400') AND
    "TEST1"."SYS_NC00002$"<HEXTORAW('6162636500') )
    but when I run
    SELECT * FROM TEST1 WHERE K1 LIKE :1;
    CBO don't use index
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 2 | 48 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    What should I change to force CBO to use index.
    I don't wont use index hint in query.
    My oracle version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    OK. But why if I create normal index (create index test1_idx on test1(K1)) and return to default nls settings this same query use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 598212486
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    |* 1 | INDEX RANGE SCAN| TEST1_IDX | 1 | 18 | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - access("K1" LIKE :1)
    filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when index is function-base (create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI')))
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 3 | 54 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when I create index with upper function "index test1_idx on test1(upper(K1))" the query use index
    SELECT * FROM TEST1 WHERE upper(K1) LIKE :1
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 4481 | 157K| 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 806 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$" LIKE :1)
    filter("TEST1"."SYS_NC00002$" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)

  • How to use Text and Image variables for printing

    I have been working on product configurator with AS3 for several months now.
    I am not proficient with AS3.
    Now, it seems that maybe my design is all wrong.
    Is there a proper way to do this?
    I have a main timeline that has movie clips showing images of different options for the product.
    On the first frame, I use buttons to select the choice for option 1 from the Option1_mc.
    Then I store the choice in a variable.
    I use a button to go to the next choice (frame 10.)
    On frame 10, I use buttons to select the choice for option 2 from the Option2_mc.
    This is stored in another variable.
    There are about 10 options that are selected and stored in variables.
    Some are text values and others are instances of images from the Option movie clips.
    I made a Print_mc to use for printjob.
    I can't get the values of the variables to display in the first frame for printing.
    Any helpl would be appreciated.

    you're welcome.
    you won't insert a variable into a textfield.  you'll assign the text property of your textfield to be the value one of your variables points to.
    so, for example, if you have:
    var var1:String="this is a test";
    you can use:
    tf.text=var1;

  • PreparedStatement and bind variable

    We are experiencing some werid performance break downs where database server looks healthy and our java applications are down to their knees.
    I was wondering if someone could help me clarify the comparison between PreparedStatement and bind variable. When I execute a PreparedStatement in java through the JDBC thin driver, would the database consider it a dynamic SQL or is it a SQL using bind variable? If this same statement is executed 100000 times, is it parsed 100000 times? We are using JDK131. How does it work?
    Is there any memory leak in PreparedStatement implementation in JDBC thin driver? Is there any known symptom to this problem? What is the recommended solution?
    Thank you very much!

    If PreparedStatement is parsed and cached, why is there setting to set implicit statement caching and explicit statement caching? Our DBA insists that it is parsed every single time. How would I find out for sure?
    The SQLs have not been changed. This sudden performance degradation started when a new client went live and we experienced higher than usual volumn. We are connecting using JDBC thin client from weblogic server to Oracle 8.1.7. It's been happening everyday since the client went live and the only way to get the performance back is to shutdown and restart the database server.
    I tried to search JDBC related issues. The only complain that I've found so far is that there may be some potential memory leak for a PreparedStatement. However, I have not found anything from Oracle's website that concurs to that.
    What is my best bet?

  • How to set bind variable for a VO ,

    Hi,
    i got a requirement in which i have to set bind variable for VO , But the Bind variable is coming from payload attribute,
    For example my query in VO is select * from Employee where emp_id="payload attribute"
    How to set this attribute value is from the payload
    Thanks Regard
    Rajendar

    Hi i am getting this exception " Cannot create an object of type:java.lang.Number from type:oracle.bpel.services.datacontrol.data.DataObject with value:21159"
    Actually i am getting Decimal Value from Payload of BPEl process and i am trying to set this to The bind variable
    is that a type cast exception where can i typeCast Those values You should this in a new thread.Dont ask questions out of the scope of this thread.
    Please mark this thread as answered or helpful if you got solution for this thread.
    Thanks!!!

  • Lexical and bind variables in RUN_PRODUCT

    Hi all,
    I have the following RUN_PRODUCT but it gives me "bad bind variable:
    DECLARE
    pl_id ParamList;
    BEGIN
    pl_id := Create_Parameter_List('tmpdata');
    Add_Parameter(pl_id,'CATEGORY',TEXT_PARAMETER,(:CATEGORY));
    Add_Parameter(pl_id, 'PARAMFORM', TEXT_PARAMETER, 'NO');
    Add_Parameter(pl_id, 'DESTYPE', TEXT_PARAMETER, 'Screen');
    Run_Product(REPORTS, 'C:\Pled', SYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id, NULL);
    Destroy_Parameter_List( pl_id );
    END;
    How can I define both lexical and bind variables in a RUN_PRODUCT. Please assist!

    Hello Nicky,
    The correct way to call Reports from Forms in 6i using the RUN_PRODUCT built-in using bind parameters would be something like the code given below. This example assumes that you have a form module parameter and a report parameter called 'category'.
    declare
    pl_id paramlist;
    begin
    pl_id := create_parameter_list('tmpdata');
    add_parameter(pl_id, 'category', text_parameter, :parameter.category);
    add_parameter(pl_id, 'paramform', text_parameter, 'no');
    add_parameter(pl_id, 'destype', text_parameter, 'screen');
    run_product(reports, 'c:\test_report.rdf', synchronous, runtime, filesystem, pl_id, null);
    destroy_parameter_list( pl_id );
    end;
    Thanks,
    The Oracle Reports Team.

  • How to set bind variables for child VO in hierarchy component?

    Hi,
    Recently I created a application with Hierarchy Component with Parent VO (Query based VO with Bind variables in it) and its Child VO along with Child-Child VO(Query based VO with bind variable in it)
    I am able to set bind variable of parent VO but unable to set bind variable for Child-Child VO. Can any one help me regarding this issue?

    Hi i am getting this exception " Cannot create an object of type:java.lang.Number from type:oracle.bpel.services.datacontrol.data.DataObject with value:21159"
    Actually i am getting Decimal Value from Payload of BPEl process and i am trying to set this to The bind variable
    is that a type cast exception where can i typeCast Those values You should this in a new thread.Dont ask questions out of the scope of this thread.
    Please mark this thread as answered or helpful if you got solution for this thread.
    Thanks!!!

  • Child reports and bind variables

    I'm working on a user defined parent/child report. What I'm having an issue with is using a parents bind variable value in a child. To simpify my example:
    The master query is:
    select count(*), document
    from download_audit
    where activity_date > sysdate-:DAYS
    group by document
    which returns a count of downloads for each document in the last :DAYS days. I want the child report to then list the person that downloaded a selected document:
    select document, user_id, activity_date from download_audit
    where activity_date > sysdate - :DAYS
    and document=:DOCUMENT
    This does not work because the initial :DAYS bind isn't sent to the child.
    If I add the :DAYS as a selected column to the master sql it works. e.g.
    select count(*), document, :DAYS days
    from download_audit
    where activity_date > sysdate-:DAYS
    group by document
    My question is, do child bind variables all have to be selected columns in the master query or is there a way to have a "global" bind variable that gets carried from master to child?
    I'm using SQL Developer 3.2.20.09 on OS X Lion
    Edited by: RoboMan on Nov 16, 2012 11:23 AM

    I agree whole heartedly :)
    If you want to make things even more interesting, create some 3rd generation child reports and carry the bind variables throughout the multiple levels - here's an example
    http://www.thatjeffsmith.com/archive/2012/09/grandparent-parent-child-reports-in-sql-developer/

  • V$Sqlarea, Audit, and Bind Variables

    I have enabled auditing to track down a problem. With the info in SYS.AUD$ tied to V$SESSION and V$SQLAREA I can see the actual statement that the user executed. The problem that I have is that everything is in bind variables.
    Does anybody know how to find the values within the bind variables for a session in $SQL_AREA?
    Thanks in advance,
    Chris S.

    Which version of the database are you using? Have you considered using Oracle9i's Fine Grained Audit functionality.
    Cheers, APC

  • My airport extreme (generation 5) was set up using wifi and has worked flawlessly (on macbook pro 2 iphones and window 7 HP pc)until recently. I have reset to factory defaults over and over but still cannot get on the internet. Any suggestions?

    My airport extreme (generation 5) was set up using wifi and has worked flawlessly (on macbook pro 2 iphones and window 7 HP pc)until recently. I have reset to factory defaults over and over but still cannot get on the internet. However I can then take my DSL cord and insert it in a different Ethernet port other than the WAN port and I can get internet on my Mac and iphones but only wifi on my husband's PC.  I hate to spend another $179 if this is just something I'm doing wrong. Please help

    I'm having a bit of trouble confirming that the ZyXEL is a combination modem & wireless-N router. If it is, then you really won't get any advantages of using the 802.11g AirPort.
    If the range of your ZyXEL is limited, you may find that doing either or both of the following will help: 1) Move the ZyXEL so that it is higher vs. lower in the room, that is away from any closed areas or placed in a metal cabinet, and 2) Changing radio channels. The latter is especially important in you live in an area where there are a number of competing Wi-Fi.
    A good utility to find out, is iStumbler. You would use this to find these other Wi-Fi and find which have the strongest signal value. Those that do, you would also want to note which channel they are operating on, and then, change yours to one that is at least 3-5 channels away. So, for example, if you find strong ones on channels 1 & 6, change yours to 11.

  • Help on RFC to JDBC and JDBC to RFC

    Help on RFC to JDBC and JDBC to RFC
    Hi Gurus
    I have the scenario where an RFC will be triggered in SAP , to write to a DB2 database and insert new records in a table
    and vice versa the JDBC has to read som data from a table based on a primary key, mark them as read for not be read next time and send the data to an RFC where a table in SAP will be updated.
    I have never worked with JDBC before , pls advice.
    is there any new issue to consider in PI 7.0 regarding JDBC
    Thanks.

    The requirement looks standard,
    SEARCH IN SDN FOR JDBC scenarios,you will find many docs for sender as well as Receiver.
    >
    > is there any new issue to consider in PI 7.0 regarding JDBC
    >
    no issue with PI7.0.
    Regards,
    Raj

  • So now i might ned u all help, currently im using ipad and i get some news abt ios 6.1 and im interested abt it so i updated wif my Ipad (ver. ios 5) and i checked some web said ipad1 cnt update to ios6 so i might ned u all help how to restore bck to ios5

    so now i might ned u all help, currently im using ipad and i get some news abt ios 6.1 and im interested abt it so i updated wif my Ipad (ver. ios 5) and i checked some web said ipad1 cnt update to ios6 so i might ned help how to restore bck to ios5 as normal be4

    If it's showing the connect to iTunes screen then you will need to do that.
    But Apple don't provide any method to update the first gen iPad to iOS 5 (nor do they support downgrading the iOS version).

  • I want to use system and job variables to make the information dynamic in the Email Subject Line

    Someone could mention the subject line character limitation needs to be expanded. 50 chars is not much to work with! 
    Is it possible to make SUBJECT Line to make , use system and job variables to make the information dynamic , Right now there is a limit for Characters in the Subject line ... is it possible to expand ???  

    I've encountered the same issue and worked around it by using generic variables that would always be the same for a certain email alert. eg =  "System XYZ -source file delay for :"
    So a sample subject would then be: 
    Where ENV = DEV/UAT etc.
    This functionality allows you to use generic alert templates for all filewait jobs, and just filling in the variables.
    A slight problem is that although this works very well, the use of group variables in email / alert actions is (/ wasn't) officially supported by Cisco when I last ran it past then. Cisco, any update in this?

  • How to substitute a bind variable for a IN condition?

    Dynamically I am setting the WHERE condition for one of my blocks using SET_BLOCK_PROPERTY Built in. The condition that I am attaching has two IN conditons..
    For Eg.,
    contracts_tbl.status_col IN ('NEW', 'OLD', 'EXPIRED', 'OPEN')
    AND contracts_tbl.id_col IN (1, 2, 3, 4)
    The number of choices in the IN condition will vary depending upon the user choice in my screen. Because of this the parsed SQL state is could not be shared and multiple of these are getting created in shared pool. To avoid this I would like to use bind variables.
    There are two ways I am trying to do this..
    1. Generating one bind variable for each value. i.e.,
    contracts_tbl.status_cod IN (:global.var1, :global.var2,
    :global.var3)
    Now this could result it memory error if no. of choices exceeds the avilable memory. Also its a tedious task to purge the variables after querying the block. Also because of multiple IN conditions, the chances of different set of selections are possible and then again sharing will be minimal.
    2. The second method is to set the one bind variable for each IN condition. i.e.,
    :GLOBAL.Var1 := '( 'NEW', 'OLD', 'EXPIRED', 'OPEN' )';
    :GLOBAL.Var2 := '(1, 2, 3)';
    contracts_tbl.status_col IN :GLOBAL.Var1
    AND contracts_tbl.id_col IN :GLOBAL.Var2
    In this case, forms is not querying as the IN condition takes the global variable value as one string and the query returns no rows though there are plenty available for each status. Also any NUMBER type condtions erroring out as the , and ( are invalid numerals.
    Q: Is there anyway you can make this work? or Is there any other better method to substitute bind variables in place to avoid creating new set of statements for each query in the shared pool?
    Your suggestions and pointers are higly appreciated. Please respond immediately as this is a P1.
    Thanks,
    -- Raam.

    2. The second method is to set the one bind variable for each >>IN condition. i.e.,
    :GLOBAL.Var1 := '( 'NEW', 'OLD', 'EXPIRED', 'OPEN' )';
    :GLOBAL.Var2 := '(1, 2, 3)';
    contracts_tbl.status_col IN :GLOBAL.Var1
    AND contracts_tbl.id_col IN :GLOBAL.Var2 This method should work - not sure if you put exact syntax in or not but your first assignment would cause a problem as everywhere you want one ' mark you would have to put two so that it does not close your quoted string
    Try the following syntax:
    :GLOBAL.Var1 := '( ''NEW'', ''OLD'', ''EXPIRED'', ''OPEN'' )';
    :GLOBAL.Var2 := '(1, 2, 3)';
    SET_BLOCK_PROPERTY('blk name',
    default_where,
    'contracts_tbl.status_col IN ' || :GLOBAL.Var1
    || ' AND contracts_tbl.id_col IN ' ||
    :GLOBAL.Var2);
    Hope this helps,
    Candace Stover
    Forms Product Management

  • How to pass bind variable into oracle reports 6i - Parameter form

    Hello All,
    I want to pass bind variable into Oracle Reports 6I - Parameters.
    I have tried out that but got the below error :-
    rep-0781 : Bind variables are not allowed in the select statement
    Kindly help me is there any option which allow me to pass bind variables into Oracle reports 6I.
    Thanks
    HARSH SHAH

    Hi,
    may be its not possible to use :P_PARAM1 in user parameter of oracle 6i reports
    but u can full fill user requirement using oracle forms
    create a form as like as report parameter window
    then create parameter list and run report
    PROCEDURE Run_Emp_Report IS
      pl_id ParamList;
    BEGIN
      pl_id := Get_Parameter_List('tmpdata');
      IF NOT Id_Null(pl_id) THEN
        Destroy_Parameter_List( pl_id );
      END IF;
      pl_id := Create_Parameter_List('tmpdata');
      Add_Parameter(pl_id, 'PARAMFORM', TEXT_PARAMETER, 'NO');
      Run_Product(REPORTS, 'empreport', SYNCHRONOUS, RUNTIME, FILESYSTEM, pl_id, NULL);
    END;
    thanks
    mostafiz mitul
    Dhaka Bangladesh

Maybe you are looking for

  • Default the sender name while sending email from discoverer 11g viewer

    Hi, Can we put a default value of a sender in the email which are sent from discoverer 11g viewer.??

  • Mac Book Pro -  The screen cannot display problem

    hi all, I have a very urgent problem with my Mac Book Pro Few days ago, when i were working with my laptop, suddenly the screen turned off but the hard drive still worked. I restarted but this problem still happen. Now when I turn on My laptop, i jus

  • Electric shock fom iPod touch....

    Hi Okay so I plugged my iPod into the wall to charge whilst doing so I went on to the Internet to check something out. Then I received a massive electric shock when I locked my iPod. Is there anything I can do to prevent this as it has happened lots

  • Solaris boot problem after Patch cluster install

    just wondering if anyone can assist. i have just installed solaris 10 x86 recommended patches on a 16 disks server. where first 2 disks are mirrored called rpool, and remaining 14 disks are raid z called spool. upon installing the patches successfull

  • Please Help Installing Printer

    so this summer i purchased an HP4140 printer which is said to be capable of running with Tiger 10.4.x. I tried to install the software and all i got was an error message. I contacted Hp and they said the problem was not on their side. So i went out a