How to pass strings for IN Clause in REF Cursor

I have following query;
SELECT 1 INTO L
FROM test_po_apprvlines
where '4020' between NVL(approval_cost_centre_from, '0000') and
nvl (approval_cost_centre_to, '9999')
and req_approval_type IN ('BUS', 'FIN') and 10500 >= approval_amount
and NVL(req_line_type, 'X') = 'X'
AND ROWNUM =1;
Now the values for req_approval_type should be dynamic, based on approval_amount. If approval_amout > 10000 then
req_approval_type should have 'BUS' and 'FIN' , other wise only 'BUS'.
I have tried with the following code using ref cursor. But i'm not getting the result.
Any help. The problem is how to concatenate those two values to get the result.
in the following code, strings are not recoginised properly. Valid data exists in the table.
DECLARE
l_approva_type1 VARCHAR2(20) := 'FIN';
l_approva_type2 VARCHAR2(10) := 'BUS';
l_approva_type VARCHAR2(20) := '''FIN'''||','||'''BUS''';
L NUMBER;
TYPE TEST_REF IS REF CURSOR;
cur_ref TEST_REF;
L_str varchar2(1000) := 'SELECT 1'||
' FROM test_po_apprvlines'
||' where '||'''4020'''||' between NVL(approval_cost_centre_from, '||'''0000'''||') and nvl(approval_cost_centre_to, '|| '''9999'''||')'
||' and req_approval_type IN ( :bi_approva_type)'||
' and 10500 >= approval_amount '||
' and req_line_type IS NULL '||
'AND ROWNUM =1';
L_flg varchar2(1);
BEGIN
DBMS_OUTPUT.PUT_LINE (l_approva_type);
open cur_ref for l_str USING l_approva_type;
fetch cur_ref INTO l_flg;
close cur_ref;
DBMS_OUTPUT.PUT_LINE (nvl(L_flg, 'x'));
EXCEPTION
WHEN OTHERS THEN
if cur_ref%isopen then
     close cur_ref;
     end if;
DBMS_OUTPUT.PUT_LINE (SQLERRM);
END;

You cant "Bind" here.
One way..
SQL> var a refcursor
SQL> declare
  2   str varchar2(100) := '''SALESMAN'',''ANALYST''';
  3  begin
  4   open :a for 'select ename from emp
  5                where job in ('||str||')';
  6  end;
  7  /
PL/SQL procedure successfully completed.
SQL> print :a
ENAME
WARD
SCOTT
Message was edited by:
        jeneesh
Results in More parsing...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How  to Pass String array from Java to PL/SQL  and this use in CURSOR

    hi,
    I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
    This array containing like (SYMPTOM ) to be returned from the java to the
    pl/sql (I am not querying the database to retrieve the information).
    I cannot find an example on this. I will give the PL/SQL block
    create or replace procedure DISEASE_DTL<*** String Array ***> as
    v_SYMPTOM number(5);
    CURSOR C1 is
    select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
    where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
    group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
    order by a.DISEASE_NAME ;
    begin
    for C1rec IN C1 loop
    select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
    insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
    values (SL_ID_SEQ.nextval,
    C1rec.DISEASE_NAME,
    (4/v_SYMPTOM), --------**** 4 is no of array element (n)************
    (1-(4/v_SYMPTOM)));
    end loop;
    commit;
    end DISEASE_DTL;
    Please give the proper solution and step ..
    Thanking you,
    Asish

    I've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
    http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/

  • How to pass (String[] args), as a parameter.

    * StringMethods
    * @author (Robin)
    * @version (1)
    public class StringMethods
        private String[] args;
        private int numArgs;
        public void printIt(String[] args)
            System.out.print ("You have entered " + numArgs + " Strings");
                if (numArgs > 10)
                    int temp = numArgs;
                    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
                    numArgs = temp;
            for (int i = 0; (i < numArgs) && (i < 10); i++)
            System.out.println ("[" + i + "] : " + args[i] + " is " + (args).length() + " characters long.");
    public void getArgs(String[] input)
    numArgs = input.length;
    arraycopy(input, 0, args, 0, numArgs-1);
    arraycopy(input, 0, args, 0, numArgs-1)This is my method class for my main method StringArray.
    What I want to know is how to pass command line arguments, i.e. {"example1", "example2", "example3"} from my main method to my method class?

    * StringMethods
    * @author (Robin)
    * @version (1)
    public class ArgMethods
    private String[] args = new String[0];
    private int numArgs;
    public String[] input = {"null", "null"};
    // constructor that takes string args to be manipulated by methods
    public ArgMethods(String[] input)
    numArgs = input.length;
    String[] args = new String[numArgs];
    System.arraycopy(input, 0, args, 0, input.length);
    public void printIt()
    if (args.length > 0)
    System.out.print ("You have entered " + numArgs + " Strings");
    if (numArgs > 10)
    int temp = numArgs;
    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
    numArgs = temp;
    for (int i = 0; (i < numArgs) && (i < 10); i++)
    System.out.println ("[" + i + "] : " + args[i] + " is " + (args).length() + " characters long.");
    else
    System.out.println ("You must enter at least one String at the command line.");
    public void reverseIt()
    if(args.length > 0)
    int next = args.length-1;
    for (int index = 0; index < args.length/2; index++)
    String temp = args[index];
    args[index] = args[next];
    args[next] = temp;
    next--;
    * StringArray
    * @author (Robin)
    * @version (1)
    public class stringArray
    public static void main (String[] args)
    int numArgs = args.length;
    // correct for output if strings less than 10 and greater than 0
    if (numArgs > 0)
    System.out.print ("You have entered " + numArgs + " Strings");
    if (numArgs > 10)
    int temp = numArgs;
    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
    numArgs = temp;
    for (int i = 0; (i < numArgs) && (i < 10); i++)
    System.out.println ("[" + i + "] : " + args[i] + " is " + (args[i]).length() + " characters long.");
    else
    System.out.println ("You must enter at least one String at the command line.");
    ArgMethods test = new ArgMethods( args );
    // test.printIt();
    // test.reverseIt();
    // test.printIt();
    *almost finished -- posting this up here so i can get it at home ((only accessible e-mail down plus can't find pen drive))..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to pass string from a class to another on button click

    Hai forum i'm developing an application in which i have frame1(seperate class without main) where i get a excel files and get the tablenames of it(sheets).
    There i choose a sheet from availabe sheets and i have to pass it frame2 on clicking a button on frame1.
    The sheet name is chosen from a JComboBox in frame1:(code)
    sheetcombo.addActionListener(new java.awt.event.ActionListener()     
                        public void actionPerformed(java.awt.event.ActionEvent e)
                                  JComboBox cb = (JComboBox)e.getSource();
                                  String sheetname = (String)cb.getSelectedItem();
    I dont get how to pass this String sheetname to frame2 where i call the constructor of frame1 initialize it. Help me out. Thanks in advance...

    1 write a set method in frame 2 class
    2 create a instance of frame 2 class in frame 1
    3 in actionaPerformed method write code as follows
    frame2obj.set(sheetname)
    this should work :-)

  • How to pass values for compound primary keys for updating the record in db.

    i have a entity bean in my ejb with two primary keys to it...eg. roleid,rolename...
    when iam retriving the record i use only one primary key ...so again to modify and update he same record which i retrived is a pbm..
    i cannot set the values for the compoundpk,,,
    but i can do the update for the bean with single primary key..
    i need to know how to pass the values/parameters for the coumpound primary key in my update method...
    thanx in advance...
    Arjun.G

    I istantiated a object for the pk class and assign the values for the primary key fields...
    Arjun.G

  • How to pass values for the checkbox

    Hi all,
    We all have seen the functionality of selecting a check box and then click the button and it performs the task(i.e in the hotmail when you select a line/lines by selecting the checkbox for that line and click the delete button those all mails are deleted). we are trying to implement this functionality. I have written the following code for that, but i get the values for the selected box if the box is the first one but if I did not select the first line and select the second line, i get the values for first line as well as for the secondline separated by comma . In other word it concatinates all values. Can I have some pointers?
    <INPUT TYPE="CHECKBOX" NAME="selectedBoxes" UNCHECKED value=<%out.println(" \"" + boxValues + "\" ");
    And also I don't know how to use the oncheck event for the check box...
    Thanks in advance...
    Ameeta

    Thanks Kan,
    But I am littlebit confuse about how does multiple values have been passed. For Example, i have selected 3 check boxes to delete the record. The value for each check box I need is name, event and hours...Each of these record is separated by '*'. I have three sets of values...for three records..
    1) Ameeta*overTime*5.00
    2) Ameeta*holiday*6.00
    3) Ameeta*weekends*8.00
    I have total 5 or 6 records for this person(Ameeta) and I want to delete these listed three...some how if I use the following coding it gives me all records before the last checked box...
    while(rs1.next())
    isEmpty = false;
    eventType = rs1.getString("EVENT_TYPE" ) ; ;
    eventDate = rs1.getString("EVENT_DATE" ) ;
    hours = rs1.getString("HOURS" ) ;
    hash += Double.parseDouble(hours) ;
    boxValues += eventDate + "*" + hours + "*" shortEvents "#";
    userId = rs1.getString("USER_ID" ) ;
    // employeeId = rs1.getString("EMP_ID" ) ;
    confirmFlg = rs1.getString("CONFIRM_FLAG");
    // out.println("\nrecordQuery:\n" + recordQuery ) ;
    %>
    <tr>
    <td colspan=5 width=100>
    <INPUT TYPE="CHECKBOX" NAME="selectedBoxes" value=<%out.println(" \"" + boxValues + "\" "); %>>
    <td width="150"><%=eventDate%></td>
    <td width="150"><%=eventType%></td>
    <td width="150"><%=hours%></td>
    <td width="150"><%=location%></td>
    <td width="150"><%=confirmFlg%></td>
    </tr>
    **************************************In this code basically I am concatinating so it is obvious that I get every thing before the check box..so I did the following change by adding the line below in the code
    while(rs1.next())
    boxValues = "";
    everything else is same....
    but now I get only the last one that is true too because I am asigning it to the null but I don't know how to pass all checked one.........can anybody help me?      
    Thanks in advance...
    Ameeta

  • How to pass parameter for table name in  form6i.

    Hi ,
    I am facing the problem to pass parameter for table name in form6i.
    If any solution please infirm me earliest to my mail id.
    ([email protected])
    example:
    begin
    select ename into :ename
    from :tab_name
    where empno =7788;
    end;
    It gives error as bad bind variable 'tab_name'
    *** where :ename and :tab_name are form fields
    Thanking you,
    Balasaheb

    object name not taken as table --> what do u mean by
    this?
    Please be more clear..
    Regards
    PriyaI have two block. First block I am displaying all the table using user_objects table. Another block I want display, user which table selected, corresponding table all the records.

  • How to pass jv for ED missing in excise invoice

    Hi Experts
    Could you pls tell me how to pass ED( Excise Duty ) entry through JV ( J1ih).
    Case: When the outgoing Excise Invoice was created one of the excise Duty was missing.
    Now i want to pass the ED against that invoice through JV .
    N pls also suggest how to assure that the jv passed correctly against the Previous invoice.

    NOW SOLVED BY PASSING jv THROUGH j1IH.

  • How to pass MIRO for imported material

    Dear  all
    HI
    i want to make a miro for imported material
    all the custom,cvd,cess,frw charges etc were alredy paid by clearing agent
    i want to pass miro for that agent
    material supplier vendor is diffrent one i want to pass miro for it also
    ple tell me the procedure for  MIRO
    thanks
    prakash

    Dear Prakash,
    While Creating Import PO, u have to maintain the Condition for clearing agent. Go for the Item detail -> condition tab,select condition one by one for which u want to pay amount to clearing agent like condition custom,cvd,cess,Freight,etc, go for detail icon and maintain the vendor (Clearing agent) .
    After Receipt of goods,while making Miro, for Clearing agent ,select Planned delivery cost at right side and select Purchase order no.it shows all the condition amount for clearing agent.clear the amount by posting MIRO.
    and for main vendor make the Miro by normal process ,it shows only basic amount and condition amont for which u did not maintain vendor(Clearing agent) at condition detail tab.
    This is the right process,I was allready work by this way.
    Rewards.....
    Regards
    Sanjay L

  • How to populate table name dynamically to a ref cursor

    Hi,
    I came accross with a requirement that in ref cursor how can i pass the table name
    for ex
    open ref_cur for select * from emp;Like that i've some 100 tables , instead of typing each and every time the table name
    that should be dynamically changed
    Like below
    open ref_cur for select * from &tbl_nm;How can i do that??
    Thank you

    I assume you are using SQL*Plus:
    SQL> variable ref_cur refcursor;
    SQL> begin
      2      open :ref_cur for select * from &tbl_nm;
      3  end;
      4  /
    Enter value for tbl_nm: emp
    old   2:     open :ref_cur for select * from &tbl_nm;
    new   2:     open :ref_cur for select * from emp;
    PL/SQL procedure successfully completed.
    SQL> print ref_cur
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 12/17/1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 02/20/1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 02/22/1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 04/02/1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 09/28/1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 05/01/1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 06/09/1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 04/19/1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            11/17/1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 09/08/1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 05/23/1987 00:00:00       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 12/03/1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 12/03/1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 01/23/1982 00:00:00       1300                    10
    14 rows selected.
    SQL> begin
      2      open :ref_cur for select * from &tbl_nm;
      3  end;
      4  /
    Enter value for tbl_nm: dept
    old   2:     open :ref_cur for select * from &tbl_nm;
    new   2:     open :ref_cur for select * from dept;
    PL/SQL procedure successfully completed.
    SQL> print ref_cur
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> SY.

  • How to call a Stored Procedure with a REF CURSOR output parameter

    I am looking forward an example that call a stored function/procedure with a REF CURSOR output parameter and get the result.
    In other words, I have a stored function/procedure that execute a SELECT statement using the OCI library and then it could get the values of each column and each row.
    I put a code snippet, it have only the main thing to call a simple stored procedure and print the name of each column of the cursor, but I couldn´t to print out the values in the table that call the stored procedure.
    I understand that the next step, it is to call a OCIStmtFetch.
    How to associate the cursor with the OCIStmtFetch?
    If you need more information, only tell me.
    I am using ANSI C with HP-UX Operative System (C for HP-UX) and Oracle 10g.
    Regards.
    Antonio Garcia
    /* callOracleSP */
    #include <stdio.h>
    #include <string.h>
    #include <oci.h>
    #include <stdlib.h>
    char* pConnectChar ="server";
    char* pUsernameChar = "user";
    char* pPasswordChar = "passwd";
    char* sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :c); END;";
    int retval;
    ub4 parmcnt=0;
    ub4 pos2=0;
    text *pcoln[20];
    ub4 namelen[20];
    char state_key[5];
    OCIStmt* pOciStatement;
    OCIStmt* pOciStatCursor;
    OCIError* pOciError;
    OCIEnv* pOciEnviron;
    OCIServer* pOciServer;
    OCISession* pOciSession;
    OCISvcCtx* pOciServiceContext;
    OCIBind* pOciBind[500];
    OCIParam* pOciParam;
    int main()
    retval = OCIEnvCreate(&pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL,0,NULL);
    retval = OCIEnvInit(&pOciEnviron, OCI_DEFAULT, 0, NULL);
    retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
    retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
    retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatement, OCI_HTYPE_STMT, 0, NULL);
    retval = OCILogon(pOciEnviron,pOciError,&pOciServiceContext,(unsigned char *)pUsernameChar,
         strlen(pUsernameChar), (unsigned char *)pPasswordChar, strlen(pPasswordChar),
                   (unsigned char *)pConnectChar,strlen(pConnectChar));
    printf("OCILogon retval=%d\n",retval);
    retval = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray1,strlen(sqlCharArray1),
         OCI_NTV_SYNTAX, OCI_DEFAULT);
    printf("StmtPrepare retval=%d\n",retval);
    retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
    retval = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
         (sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
    printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
    retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *)&pOciStatCursor,
         (sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
    printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
    strcpy(state_key,"CA");
    retval = OCIStmtExecute(pOciServiceContext, pOciStatement, pOciError, (ub4)1, (ub4) 0,
         (OCISnapshot *)NULL, (OCISnapshot *)NULL, (ub4) OCI_DEFAULT);
    printf("StmtExecute retval=%d\n",retval);
    /* How to get the values of the cursor? */
    /* Get number of parameters of the Cursor */
    OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
         (ub4)OCI_ATTR_PARAM_COUNT, pOciError);
    printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
    for (int pos = 1; pos <= (int)parmcnt; pos++)
         OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
              (ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
         retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,
              (ub4) pos );
         OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &pcoln[pos-1],(ub4 *) &namelen[pos-1],
              (ub4) OCI_ATTR_NAME,(OCIError *)pOciError );
    for (int i = 1; i <=(int)parmcnt; i++)
    printf("Column %i\tNAME = %.*s\n",i,namelen[i-1],pcoln[i-1]);
    return 0;
    This is the script that create the table, insert records and create the stored procedure
    CREATE TABLE CITIES (
         STATE_CODE     VARCHAR2(2) NULL,
         CITY_CODE      NUMBER(15,5) NULL,
         CITY_NAME      VARCHAR2(30) NULL
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('CA', 30, 'SAN DIEGO')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('CA', 40, 'SACRAMENTO')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('FL', 10, 'MIAMI')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('FL', 20, 'ORLANDO')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('NY', 10, 'NEW YORK')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('NY', 20, 'ALBANY')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('CA', 10, 'LOS ANGELES')
    INSERT INTO CITIES(STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES('CA', 20, 'SAN FRANCISCO')
    CREATE OR REPLACE PACKAGE globalPkg AUTHID CURRENT_USER AS
    /* The following are T/SQL specific global variables. */
    TYPE RCT1 IS REF CURSOR;/*new weak cursor definition*/
    END globalPkg;
    CREATE OR REPLACE PROCEDURE SP_ADDCITY(
    P_STATE_CODE IN VARCHAR,
    P_CITY_CODE      IN NUMBER,
    P_CITY_NAME      IN VARCHAR2,
    P_RETURN IN OUT NUMBER)
    AS
    StoO_error INTEGER;
    StoO_selcnt INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
         BEGIN
    StoO_rowcnt := 0;
    StoO_error := 0;
    StoO_selcnt := 0;
    P_RETURN := 0;
    INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
    VALUES (P_STATE_CODE, P_CITY_CODE, P_CITY_NAME);
    StoO_rowcnt := SQL%ROWCOUNT;
    EXCEPTION
    WHEN TOO_MANY_ROWS THEN
    StoO_rowcnt := 2;
    WHEN OTHERS THEN
    StoO_rowcnt := 0;
    StoO_selcnt := 0;
    StoO_error := SQLCODE;
    StoO_errmsg := SQLERRM;
              IF StoO_error != 0 THEN
    BEGIN
                   P_RETURN := 1;
         RETURN;
         END;
              END IF;
         END;
    CREATE OR REPLACE PROCEDURE SP_GETCITIES(
    STATE_KEY IN VARCHAR,
    RC1      IN OUT globalPkg.RCT1)
    AS
    StoO_error INTEGER;
    StoO_selcnt INTEGER;
    StoO_rowcnt INTEGER;
    StoO_errmsg VARCHAR2(255);
    BEGIN
    StoO_rowcnt := 0;
    StoO_error := 0;
    StoO_selcnt := 0;
    OPEN RC1 FOR
    SELECT STATE_CODE, CITY_CODE, CITY_NAME
    FROM CITIES
    WHERE STATE_CODE = STATE_KEY
    ORDER BY CITY_CODE;
    StoO_rowcnt := SQL%ROWCOUNT;
    EXCEPTION
    WHEN OTHERS THEN
    StoO_rowcnt := 0;
    StoO_error := SQLCODE;
    StoO_errmsg := SQLERRM;
         END;
    /

    Hi Mark,
    Thanks for your recommendations.
    I change the code with OCIDefineByPos, one for each parameter from cursor and then use the OCIStmtFetch.
    I don´t receive a error when call OCIDefineByPos, but when I call OCIStmtFetch receive a -1 error number.
    What is wrong with the code?
    The script is the same.
    I need your help!
    Best Regards!
    Antonio Garcia (Mexico)
    This the new code:
    #include <stdio.h>
    #include <string.h>
    #include <oci.h>
    #include <stdlib.h>
      char*   pConnectChar ="ORAC617";
      char*   pUsernameChar = "C617_005_DBO_01";
      char*   pPasswordChar = "Tempora1";
      char*   sqlCharArray1 = "BEGIN SP_GETCITIES(:s, :c); END;";
      int     retval;
      ub4 parmcnt=0;
      ub4 pos2=0;
      sb2   *c_indp;
      text *pcoln[20], *name,*name2;
      ub4 namelen[20],len;
      ub2 type,size;
      char state_key[5];
      OCIDefine        *pdef;
      OCIBind          *p_bnd;
      ub1          **c_buf;
      OCIStmt*     pOciStatement;      /* Statement handle */
      OCIStmt*     pOciStatCursor;     /* Statement handle */   
      OCIError*    pOciError;          /* Error handle */
      OCIEnv*      pOciEnviron;        /* Environment handle */
      OCIServer*   pOciServer;         /* Server handle */  
      OCISession*  pOciSession;        /* Session handle */
      OCISvcCtx*   pOciServiceContext; /* Service Context handle */
      OCIBind*     pOciBind[500];      /* Bind handle */
      OCIParam*    pOciParam;          /* Param handle */
      int OCI_Fetch(OCIStmt *p_select,OCIError *p_err, int *piOcc)
      int iOcc, rc; 
      rc=OCIStmtFetch(p_select,p_err,1,OCI_FETCH_NEXT,OCI_DEFAULT);
      printf("rc fetch %i",rc);
      if(rc==0&&piOcc!=NULL){
           printf("entro al if");
        iOcc=*piOcc;
        *piOcc=iOcc+1;
      return rc;
    int main()
    int pos,i=0,rc;
      retval = OCIEnvCreate(&pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL,0,NULL);
      printf("EnvCreate retval=%d\n", retval);
      retval = OCIEnvInit(&pOciEnviron, OCI_DEFAULT, 0, NULL);
      printf("EnvInit retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_ERROR retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_SVCCTX retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatement, OCI_HTYPE_STMT, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
      retval = OCILogon(pOciEnviron,pOciError,&pOciServiceContext,(unsigned char *)pUsernameChar,
                  strlen(pUsernameChar), (unsigned char *)pPasswordChar, strlen(pPasswordChar),
                    (unsigned char *)pConnectChar,strlen(pConnectChar));
      printf("OCILogon retval=%d\n",retval);
      retval = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray1,strlen(sqlCharArray1),
                 OCI_NTV_SYNTAX, OCI_DEFAULT);
      printf("StmtPrepare retval=%d\n",retval);
      retval = OCIHandleAlloc(pOciEnviron, (void **)&pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
      printf("HandleAlloc OCI_HTYPE_STMT retval=%d\n",retval);
      retval = OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4) 1, (void *)&state_key,
                 (sb4) sizeof(state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
      printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
      retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *)&pOciStatCursor,
                 (sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *)0,(ub4)0, (ub4 *)0, (ub4) OCI_DEFAULT);
      printf("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
      strcpy(state_key,"CA");
      retval = OCIStmtExecute(pOciServiceContext, pOciStatement, pOciError, (ub4)1, (ub4) 0,
                   (OCISnapshot *)NULL, (OCISnapshot *)NULL, (ub4) OCI_DEFAULT);
      printf("StmtExecute retval=%d\n",retval);
      c_buf=(ub1 **)calloc(sizeof(ub1 *),3);
      c_indp=(sb2 *)calloc(sizeof(sb2 *),3);
      // Get number of parameters of the Cursor
      OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &parmcnt,(ub4 *) 0,
                  (ub4)OCI_ATTR_PARAM_COUNT, pOciError);
      printf("\nNumber of parameters of the cursor = %d\n",parmcnt);
      for (pos = 1; pos <= (int)parmcnt; pos++)
           OCIAttrGet((void *) pOciStatCursor, (ub4)OCI_HTYPE_STMT, (void*) &pos2,(ub4 *) 0,
                (ub4)OCI_ATTR_CURRENT_POSITION, pOciError);
           retval = OCIParamGet((void *)pOciStatCursor, (ub4)OCI_HTYPE_STMT, pOciError, (void **)&pOciParam,(ub4) pos );
           // Get the column name
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &name,(ub4 *) &len, (ub4) OCI_ATTR_NAME,(OCIError *)pOciError );
            // Get the column datatype
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &type,(ub4 *)0,(ub4)OCI_ATTR_DATA_TYPE,(OCIError *)pOciError);      
            // Get the column size
           OCIAttrGet((void*) pOciParam, (ub4) OCI_DTYPE_PARAM,(void*) &size,(ub4 *)0,(ub4)OCI_ATTR_DATA_SIZE,(OCIError *)pOciError);
           printf("Column %i\tNAME = %.*s \ttype %d \tsize %d\n",pos,len,name,type,size);
           // OCIDefine ByPos, one for each parameter
           // c_buf store the STATE_CODE, CITY_CODE and CITY_NAME columns from the cursor
           rc=OCIDefineByPos(pOciStatCursor,&pdef,(OCIError *)pOciError,pos,c_buf[pos-1],size+1,(ub2)type,(dvoid *)c_indp[pos-1],(ub2 *)0,(ub2 *)0,OCI_DEFAULT);     
          printf("OCIDefineByPos retval=%d\n,rc);
      // call OCIStmtFetch. In the next line, I receive the error
      rc=OCIStmtFetch(pOciStatCursor,pOciError,1,OCI_FETCH_NEXT,OCI_DEFAULT);
      printf("rc fetch %i",rc);
      return 0;
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to access variable number of columns using ref cursor !

    Hi,
    I am trying to get variable number of columns using ref cursor.
    Declare
    mySzSql varchar2(2000);
    Type dynSqlRC is Ref cursor;
    current_cur dynSqlRC;
    tbl_rec alt_42_consolidated%Rowtype;
    Begin:
    /* This works */
    mySzSql := 'select *
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    /* i want something like this to work, this is not working, giving missing variable name error */
    mySzSql := 'select col1, col2, col3
    from
    Table1
    Where
    rowid = ''AAEWNEABXAAAAkxAAA''';
    open current_cur for mySzSql;
    fetch current_cur into tbl_rec;
    close current_cur;
    End;
    I do have the list of desired columns which I am looking to fetch, so after taking that in the record type, how should i get their values. Is it possible to traverse tbl_rec declared above and if column name matches then I will store the value in the array and finally return this array.
    Can somebody please tell me how to do this.
    Thanks

    It appears that this is a followup to How to loop through columns selected by select clause which is itself a followup to [url="
    How to execute dynamic sql"]this earlier thread.
    Assuming these are intended to be followup questions, can we please stick to a single thread? That makes it a lot easier to understand the situation and follow the conversation. Starting multiple threads makes it harder to follow the conversation.
    Thanks,
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to fetch NO DATA FOUND exception in Ref Cursor.

    In my procedure ref cursor is out parameter with returns dataset. in my proceudre
    its like...
    OPEN pPymtCur FOR
    select.....
    when I call this procedure from report to get dataset it causes NO DATA FOUND exception.
    How to fetch this exception in my oracle procedure so I can get some other data.
    Any Idea to do this?
    Edited by: Meghna on 17-Jun-2009 22:28

    Mass25 wrote:
    Correct me if I am wrong.
    So if I do something as follows in my stored proc, I do not have to check for NO_DATA_FOUND?
    OPEN my_CuRSR FOR
          SELECT DISTINCT blah blah blahmy_cursr is what I am returning as OUT param in my SP.Correct. At the point you open the cursor, oracle has not attempted any 'fetch' against the data so it won't know if there is any data or no data. that only occurs when a fetch is attempted.
    Take a read of this:
    [PL/SQL 101 : Understanding Ref Cursors|http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0]

  • How can I see the contents in a Ref Cursor

    I have this code:
    CREATE OR REPLACE PACKAGE APOD_LOG.APOD_C3_LOG_API_PKG
    AUTHID CURRENT_USER
    AS
    type rc is ref cursor;
    PROCEDURE Fetch_Log_Spec
    in_LOCAL_IP_VALUE IN BINARY_INTEGER,
    out_RESULT_SET OUT rc
    END APOD_C3_LOG_API_PKG;
    CREATE OR REPLACE PACKAGE BODY APOD_LOG.APOD_C3_LOG_API_PKG
    AS
    PROCEDURE Fetch_Log_Spec
    in_LOCAL_IP_VALUE IN BINARY_INTEGER,
    out_RESULT_SET OUT rc
    IS
    BEGIN
    DBMS_APPLICATION_INFO.set_module(module_name => 'APOD_LOG.API_PKG',action_name => 'Fetch_Log_Spec');
    DBMS_APPLICATION_INFO.set_client_info(client_info => 'Calling with in_LOCAL_IP_VALUE = ' ||to_char(in_LOCAL_IP_VALUE));
    open out_RESULT_SET for
    select
    in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
    10002 as PORT,
    APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.100.1''') as MULTICAST_IP_VALUE
    from
    dual
    union
    select
    in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
    10002 as PORT,
    APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.200.1''') as MULTICAST_IP_VALUE
    from
    dual
    union
    select
    in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
    10002 as PORT,
    APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.100.123''') as MULTICAST_IP_VALUE
    from
    dual
    union
    select
    in_LOCAL_IP_VALUE as IN_LOCAL_IP_VALUE,
    10002 as PORT,
    APOD_CORE.UTIL_IP_PKG.IPAddressToIPValue2('''224.168.200.123''') as MULTICAST_IP_VALUE
    from
    dual;
    DBMS_APPLICATION_INFO.set_client_info(client_info => 'Called Fetch_Log_Spec '||to_char(SQL%ROWCOUNT)||' row(s) returned with in_LOCAL_IP_VALUE = '||to_char(in_LOCAL_IP_VALUE) );
    END Fetch_Log_Spec;
    END APOD_C3_LOG_API_PKG;
    And I am trying to test it like this:
    DECLARE
    IN_LOCAL_IP_VALUE BINARY_INTEGER;
    OUT_RESULT_SET APOD_LOG.APOD_C3_LOG_API_PKG.rc;
    BEGIN
    IN_LOCAL_IP_VALUE := 23374048;
    -- OUT_RESULT_SET := NULL; How do I see this
    APOD_LOG.APOD_C3_LOG_API_PKG.FETCH_LOG_SPEC ( IN_LOCAL_IP_VALUE, OUT_RESULT_SET );
    END;
    How can I see the dataset returnd by the OUT_RESULT_SET in SQLPlus or Quest ScriptRunner?

    A ref cursor doesn't really contain rows but you can use them to reference a SQL statement that fetches the rows.
    Re: returning resultset from procedure...or pkg

  • How to clear the run time error in ref cursor

    good morning every one,
    the code as follows
    create or replace
    procedure Country_sel(key in varchar2)
    as
    cc Res_RelcountryLan.countrycode%type;
    len Res_Language.langname_en%type;
    lid Res_Language.langid%type;
    ab Res_Language.Abrivation%type;
    type refcursorr is ref cursor;
    cur refcursorr;
    d_stmt varchar2(100);
    begin
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',
    RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId';
    open cur for d_stmt;
    loop
    fetch cur into cc,lid,len,ab;
    if cur%found then
    dbms_output.put_line(cc||lid||len||ab);
    else
    exit;
    end if;
    end loop;
    close cur;
    commit;
    end  Country_sel;when i am running this code im getting
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "RASOOL.COUNTRY_SEL", line 11
    ORA-06512: at line 6can you please help me in getting rid of this problem.
    thanking you,
    prakash

    d_stmt varchar2(100); Increase the size of d_stmt. Your a assigning a larger string
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId'; The size of the above string is more than 100 characters.

Maybe you are looking for

  • Excise Invoice No. from Delivery Note in GR

    Hi.. We enter Invoice No. in 'Delivery Note' field while posting GR and after we do capturing Excise invoice w r t GR in J1IEX. Is there any setting to get 'Delivery Note'  number flows/copied into 'Excise Invoice No.' in J1IEX. or How to it can be a

  • System Cache Issues with Windows Server 2008R2

    Hi, I'm trying to deploy Java version 1.5.0 (build 1.5.0_14-b03) on a new Windows Server 2008R2 installation. I want to use the system cache feature and have used it successfully on Windows XP workstations and Windows 2003 servers in the past. I even

  • Black ink cartridge will not print

    I just finished a one hour online chat with HP Support. The black cartridge of my C6180 will not print. After going through many steps the Support tech stated "I appreciate your patience and efforts in performing all the troubleshooting steps provide

  • How to create a datablock at run time?

    I want to create a datablock with database item at runtime. Is it possible? plz help.

  • Creating a new database with oracle express

    how to create a database with oracle express. the web based interface for managing oracle sucks and it is too slow, they'd bet better of developing a rich client application for managing XE. Oracle XE comapraed to SQL Express is very poor.