How do I use bind variables for the SQL statements having IN clause

SELECT id, name FROM t
WHERE id in (10,20,30)
As the IN list will have 'n' number of values, I am not able to specify fixed number of bind
variables like
SELECT id, name FROM t
WHERE id in (?,?,?....)

452051 wrote:
I am not able to specify fixed number of bind variablesYou could use collection:
SQL> create or replace force
  2    type NumList
  3      as
  4        table of number
  5  /
SQL> select ename from emp where deptno member of NumList(10)
  2  /
ENAME
CLARK
KING
MILLER
SQL> select ename from emp where deptno member of NumList(10,20,30)
  2  /
ENAME
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
ENAME
JAMES
FORD
MILLER
14 rows selected.
SQL> This way you have one bind variable - collection.
SY.

Similar Messages

  • How to use presentaion variable in the SQL statement

    Is there any special syntax to use a presentation variable in the SQL Statement?
    I am setting a presentation variable (Fscl_Qtr_Var)in the dashboard prompt.
    If i set the filter as ADD->VARIABLE->PRESENTATION, it shows the statement as 'Contract Request Fiscal Quarter is equal to / is in @{Fscl_Qtr_Var} '.
    And this works fine but when i convert this to SQL, it returns
    "Contract Request Date"."Contract Request Fiscal Quarter" = 'Fscl_Qtr_Var'
    And this does not work.It is not being set to the value in the prompt.
    I need to combine this condition with other conditions in the SQL Statement. Any help is appreciated. Thanks

    Try this: '@{Fscl_Qtr_Var}'

  • How do I use a variable within a sql statement

    I am trying to use a local variable within an open SQL step but I keep getting an error.
    My sql command looks like this "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  locals.CurrentSerialNo
    If I replace the locals.CurrentSerialNo with an actual value such as below the statement works fine.
    "SELECT BoardDetailID FROM BoardDetails WHERE SerialNumber = " +  " 'ABC001' " 
    Can someone tell me how to correctly format the statement to use a variable?

    Hi,
    Thanks for the reply. I have changed the required variable to a string, but with no success. I have reattached my updated sequence file and an image of the error.
    When looking at the Data operation step I see that the sql statement is missing everything after the last quotation mark.
    Thanks again,
    Stuart
    Attachments:
    Database Test Sequence.seq ‏10 KB
    TestStand error.JPG ‏37 KB

  • How to query using CGI path for 'IN' sql statement

    Some problems that requires help:
    I have a report that requires a query which has 'IN' statement in SQL query. For example: SELECT EMP_ADDRESS1 FROM EMPLOYEE WHERE EMP_NO IN (:EMP_NO).
    I am going to query the result of this query using CGI. My peoblem starts here - I can't be passing a list of parameter for ':EMP_NO' because the path does not accept escape characters. I can't be put a query path below:
    <HTML>http://172.188.2.7/dev60cgi/rwcgi60.exe?server=9iAS&mode=default&destype=localfile&desformat=\\pri_wnt\generic&report=gcgd1.rdf&userid=comm/comm@employee<B>&emp_no='A','B','C'<B></HTML>
    What I am doing is that I will have a front end written in JAVA and display a listing of Employee available in the company. The user will be able to choose whatever employee on the front end. Then, I will call the CGI path to display the result to the user.
    Pls help. Kindly email personally([email protected]) or reply here.
    Thank you

    You'll need to escape your single quotes using %XX where XX is the hex code corresponding to the special character you want to use. I'm not sure what the escape code is for quotes. I know that if you wanted to have a space, this:
    ....../rwcgi60.exe?key+P_city='San Francisco'+....
    would need to look like:
    .../rwcgi60.exe?key+p_city=San%20Francisco+...
    You'll need to find out what the number for quote is. HOpe that helps a bit.
    Toby

  • Using bind variables in Oracle SQL developer

    Hi all,
    i am using Oracle SQL developer. i want to use the bind variable in my sql.
    variable myid number :=1;
    select * from mds_3618_request where id = :myid;
    but i am getting the below error.
    Error starting at line 2 in command:
    select * from mds_3618_request where id = :myid
    Error report:
    SQL Error: Missing IN or OUT parameter at index:: 1
    Does Oracle SQL developer support bind variables in the SQL statements?
    thanks in Advance
    Vali Shaik

    You are probable going to get a quicker answer on this forum : SQL Developer
    -- Andy

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • Use a variable for the integer in Fmt offset modifier

    I'm trying to pluck values out of a long array of comma separated string
    values.
    I'm doing this within a loop and would like to use the loop interation to
    point to the starting point in the array.
    Here's what I have working so far:
    Fmt (scratch,"%s<%s[i0t44]",transmitBuf);
    Works great.
    Now if I go in and change i0 to i3 then my modifier doesn't start looking
    for a comma "," until after the 3rd character. Still working great. However....
    If I try to use an integer called "loop" instead of the literal offset
    value it blows up:
    Fmt (scratch,"%s<%s[iloopt44]",transmitBuf);
    Is there a way that I can use a variable for the integer portion of the
    offset modifer?
    Thanks All!

    Hi Roberto
    Thank you. I actually need to use a symbolic value for the interger section of the modifer vs. the specifier.
    So, in my example:
    Fmt (scratch,"%s<%s[i0t44]",transmitBuf); 
    I want to make the following substitution (Assume z=0)
    Fmt (scratch,"%s<%s[izt44]",transmitBuf);
    Some background...
    I'm looking to loop index through a long CSV string array (transmitBuf) that looks like this:
    1,PEEP,7,6,,,21,20,
    So on my first loop when I use the following:
    Fmt (scratch,"%s<%s[i0t44]",transmitBuf); 
    scratch = "1"
    ... Perfect. I now do a string length of scratch (which equals 1)
    and add 1 to it, I'm ready for my next loop which would
    literally read like this:
    Fmt (scratch,"%s<%s[i2t44]",transmitBuf); 
    However, I want to put this inside a loop, so I would like to
    increment a variable (++z) and use the following:
    Fmt (scratch,"%s<%s[izt44]",transmitBuf); ---- Ka-Boom!
    So it's the use of the variable in the modifer that blows up
    the Fmt command.
    appreciate any thoughts...
    Thanks
    Mark

  • How can I use a variable for an interface log and error fle

    I want to use a variable for the interface's log and error file so that when I migrate from Dev to QA to Prod I don't have to do a lot of editing.
    Specifically on the "flow" tab for the "target", I want a variable to be the first part of the path for the log (\\sundev1\fnd1-hypd1) and join this with the rest (\update\log\logfile.log) within the LOG_FILE_NAME field.
    Thank you!

    Hi,
    It is quite simple....
    just use the <%=odiRef.getSchemaName("D")%> before the file name and configure both path in the topology linked to each context.

  • How to enter bind variables in Calender SQL statement

    Hi,
    Anyone know how to include bind variables in Calender SQL statement. Let's say in sql statement below:
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    order by EMP.HIREDATE
    thanks.

    Hi,
    Here is the sql statement
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    where deptno = :dept
    order by EMP.HIREDATE
    Thanks,
    Sharmila

  • The number of reloads for the SQL statements

    Hi,
    in 10g R2, how to see the number of reloads for the SQL statements ? Any query ? Which value is high ? Which valu is low ?
    Thanks.

    thanks all.
    It was a test question for 1Z0-042 exam as follows :
    The users on your SALESDB are complaining of slow response to their queries. Using the SQL Tuning Advisor, you determine
    that the SQL statements are using the best optimization plan. Querying the dynamic views, you see that the number of reloads
    for the SQL statements is high, which can cause performance degradation.
    Which component of the SGA should you resize to reduce the number of reloads of the SQL statements?
    Answer :
    shared poolThen I wonder how to see the number of reloads for the SQL ?

  • 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 use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • How can I open a cursor for dynamic sql statement

    Hi,
    I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
    CREATE OR REPLACE FUNCTION DEMO
    (MN_I in VARCHAR)
    return AB_OWNER.ABC_Type.NonCurTyp is
    RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
    sql_stmt VARCHAR2(4000);
    BEGIN
    sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
    OPEN RESULT1 FOR sql_stmt;
    END IF;
    return RESULT1;
    END DEMO;
    What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.

    Gangadhar Reddy wrote:
    I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
    Because this is what will happen when it runs a lot.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
    http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
    And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
    Flushing Shared Pool regularly
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
    >
    Ok, this is an easy one to diagnose.
    You are not using bind variables. This is terrible. Flushing the shared pool is a bad
    solution -- you are literally killing the performance on your box by not using them.
    If I was to write a book on how to build “non scalable applications in Oracle”, this
    would be the first and last chapter. This is a major cause of performance issues and a
    major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
    important shared memory data structure) operates is predicated on developers using bind
    variables. If you want to make Oracle run slowly, even grind to a total halt – just
    refuse to use them.
    >
    But, please feel free to go ahead with this successful implementation.
    I just hope anyone else who reads this doesn't make the same mistake.

  • How to use a collection type of bind variable for execute dynamic statement

    Hi,
    We have a case where we copy selective data from Schema A To Schema B in one oracle database. The copy is achieved by using
    execute immediate 'insert into '||target_schema||'.tablea select * from '||from_schema||'.table a where a.id in (select test_id from '||from_schema||'.table c);';
    This works fine it takes an average of 10 seconds to copy around 14 tables. We have a requirement to bring this time to 2 seconds. One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts . Thus we were thinking to bulk fetch this set of tests ids and use a bind vatiable of collection type for the execute immediate clause. Any suggestions on how to achieve it?
    Thanks,
    Chandana

    >
    One observation has been the clause
    "select test_id from '||from_schema||'.table c" in the above sql statement repeats for many inserts
    >
    So what? Constructing a string for a table level insert and parsing it can't possibly be a performance problem. If you were creating a string in a loop to insert rows into a table by getting the data FROM a collection - that's a problem that keeps showing up in the forums.
    I'm with bravid and Nikolay on this one. First find out which side, select/insert, the problem is on.
    As they said you need to provide more information about the process.
    And using collections for your use case is definitely not the thing to do.
    1. How many rows are we talking about?
    2. Are the rows being inserted into an empty table?
    3. Are you running these queries during peak production hours or in a batch windows?
    Tune the SELECT if the problem is on that side.
    Post an execution plan for the SELECT part of a query you think should run faster.
    SET SERVEROUTPUT ON
    SET AUTOTRACE TRACEONLY
    SQL> select * from emp;
    Execution Plan
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    14 |   546 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMP  |    14 |   546 |     3   (0)| 00:00:01 |
    SQL>On the INSERT side you might be able to use bulk inserts
    ALTER TABLE myTable NOLOGGING;
    INSERT /*+ append */ INTO myTable . . .
    ALTER TABLE myTable LOGGINGIf the insert tables are always reused you could just leave them as NOLOGGING. Since you can't recover bulk data you need to make sure to get a good backup after the loads if you need to recover the data from the logs rather than just reload it yourself.

  • Using bind variables in the model view for master detail

    Hi all,
    I have a master-detail views setup on the following two queries.
    In the first query below - I use two bind variables to collect the start and end date.
    you have to add (and :startDate = :startDate and :endDate = :endDate) or you will get errors - bind not defined in sql
    I then use the viewQueryCriteria to collect the data on a search panel - so far so good. (Make the bind variables required) along with the other criteria.
    The bind variables are displayed in the search panel and the data is entered correctly.
    The query executes and all is happy.
    VIEWOBJECT1
    SELECT DepositAccounts.COA_ID,
    ... ChartOfAccounts.ACCOUNT_CODE || ' ' || ChartOfAccounts.ACCOUNT_TITLE as description
    FROM DEPOSIT_ACCOUNTS DepositAccounts, DEPOSIT_ACCOUNT_DETAILS DepositAccountDetails, CHART_OF_ACCOUNTS ChartOfAccounts
    WHERE DepositAccounts.ID = DepositAccountDetails.DEP_ACC_ID
    and ChartOfAccounts.id = DepositAccountDetails.COA_ID
    and :startDate = :startDate and :endDate = :endDate
    Now I add the summation of a value (AMOUNT) to the view object (java - create view impl) to the VOViewRowImpl
    and everything works - the value is shown in the transient attribute formatted and looking nice.
    VIEWOBJECT2
    SELECT PostingBatchAccounts.AMOUNT,
    FROM POSTING_BATCH_ACCOUNTS PostingBatchAccounts, POSTING_BATCHES PostingBatches
    where PostingBatchAccounts.PB_ID = PostingBatches.ID
    and PostingBatches.SOURCE_DATE between :startDate and :endDate
    Now I need to add the start date and end date to the child query - before the view executes (or the summation is calculated).
    The attributes are in the where clause (PostingBatches.SOURCE_DATE between :startDate and :endDate) in VIEWOBJECT2 which is the child.
    I need the child records and the summation to work with the date restrictions.
    I would assume you could get access to the child view in the VOViewImpl file and set the bind variables there.
    Everything I find is based on the JSF - not the model layer - this should be fairly easy (and common). can anyone give me a hand on this?

    Hi all,
    I have a master-detail views setup on the following two queries.
    In the first query below - I use two bind variables to collect the start and end date.
    you have to add (and :startDate = :startDate and :endDate = :endDate) or you will get errors - bind not defined in sql
    I then use the viewQueryCriteria to collect the data on a search panel - so far so good. (Make the bind variables required) along with the other criteria.
    The bind variables are displayed in the search panel and the data is entered correctly.
    The query executes and all is happy.
    VIEWOBJECT1
    SELECT DepositAccounts.COA_ID,
    ... ChartOfAccounts.ACCOUNT_CODE || ' ' || ChartOfAccounts.ACCOUNT_TITLE as description
    FROM DEPOSIT_ACCOUNTS DepositAccounts, DEPOSIT_ACCOUNT_DETAILS DepositAccountDetails, CHART_OF_ACCOUNTS ChartOfAccounts
    WHERE DepositAccounts.ID = DepositAccountDetails.DEP_ACC_ID
    and ChartOfAccounts.id = DepositAccountDetails.COA_ID
    and :startDate = :startDate and :endDate = :endDate
    Now I add the summation of a value (AMOUNT) to the view object (java - create view impl) to the VOViewRowImpl
    and everything works - the value is shown in the transient attribute formatted and looking nice.
    VIEWOBJECT2
    SELECT PostingBatchAccounts.AMOUNT,
    FROM POSTING_BATCH_ACCOUNTS PostingBatchAccounts, POSTING_BATCHES PostingBatches
    where PostingBatchAccounts.PB_ID = PostingBatches.ID
    and PostingBatches.SOURCE_DATE between :startDate and :endDate
    Now I need to add the start date and end date to the child query - before the view executes (or the summation is calculated).
    The attributes are in the where clause (PostingBatches.SOURCE_DATE between :startDate and :endDate) in VIEWOBJECT2 which is the child.
    I need the child records and the summation to work with the date restrictions.
    I would assume you could get access to the child view in the VOViewImpl file and set the bind variables there.
    Everything I find is based on the JSF - not the model layer - this should be fairly easy (and common). can anyone give me a hand on this?

Maybe you are looking for

  • Getting my Sharepoint data back

    Hi, I am still working on trying to get Sharepoint back running.    I had a SQL2005 crash when a disk got full and have since been able to move the data files and get SQL to recognize the files. The SQL databases are STS_config and STS_hca4_1 but I a

  • How do I get an iTunes gift redemption code to set up my new Apple ID?

    I have set up a new Apple ID for my iPhone.  I don't have a credit card, so I was trying to use the iTunes gift a friend bought me as my payment method.  But every time I click on the link to redeem the code, it takes me to iTunes, which tells me I h

  • Installation stuck now for four hours at "less than one minute remaining"

    I've seen this occasionally, but using a full OS X installer, I've now been stuck at the<1 minute mark for several hours. I'm going to give it through the night, but I've often not seen this resolve. Should I continue?

  • 3 Finger Swipe Feature doesnt work with Windows 7?

    Good Evening I've read a thread about this feature for Mac. But does this also work for 7 Trackpad Users? I've got a 2 years old Toshiba Notebook and use newest Synaptics Driver. It support 3 finger tap and swipe fuctions - both working great. 3 Fing

  • HP Elitepad 900 G1 won't boot from HP W8 usb Recovery media and mobo replaced

    I replaced the mobo on my HP ElitePad 900 G1and have the HP W8 usb Recovery stick. When docked with usb media,mouse /keyboard attached I see the "usb hard drive" in F9 Boot options. I select the usb drive as a boot device and the screen goes to black