Error retrieving REF CURSOR

Hi,
I have a problem retrieving a ResultSet from a REF CURSOR. I am using and OCI driver and Oracle 9i.
Mi Code is like this:
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:oci:@XXXXX", "login", "password");
CallableStatement cs = conn.prepareCall("{?=call package.name(P_CODIGO => ?)}");
cs.registerOutParameter(1,OracleTypes.CURSOR);
cs.setInt(2,16782);
cs.executeQuery();
ResultSet result = ((OracleCallableStatement)cs).getCursor(1);
result.next();
ResultSetMetaData rsmd = result.getMetaData();
for(int i = 0; i < rsmd.getColumnCount();i++){
System.out.println(rsmd.getColumnName(i) + ": " + (result.getObject(i)).toString());
cs.close();
conn.close();
Whe I try to get the ResultSet:
ResultSet result = ((OracleCallableStatement)cs).getCursor(1);
I receive an error like this:
java.lang.UnsatisfiedLinkError: make_statement
     at oracle.jdbc.oci8.OCIDBAccess.make_statement(Native Method)
     at oracle.jdbc.oci8.OCIDBAccess.RefCursorBytesToDBStatement(OCIDBAccess.java:2401)
     at oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:3865)
     at oracle.jdbc.driver.OracleCallableStatement.getCursor(OracleCallableStatement.java:793)
     at pruebas.Callable.main(Callable.java:44)
Exception in thread "main"
In the web I found some examples but using a thin driver. In my case I must use the OCI driver.
If somebody have any idea about the cause of this problem, please, tell me.
regards,
Alvaro

hi,
Mine is a standalone class which just calls a stored procedure which returns a REF CURSOR. When i try using getObject() method, i am getting the same error. i understand this is more of a configuration issue rather than a code issue. i have also called some other procedures from my class, which do some updates, etc and which are working fine. The error is as follows:-
Exception in thread "main" java.lang.UnsatisfiedLinkError: make_statement
at oracle.jdbc.oci8.OCIDBAccess.make_statement(Native Method)
at oracle.jdbc.oci8.OCIDBAccess.RefCursorBytesToDBStatement(OCIDBAccess.java:2419)
at oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:3836)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:6039)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:5827)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:698)
at com.fmr.fims.common.StagingDatabaseHandler.getBatchListForStatus(StagingDatabaseHandler.java:160)
at com.fmr.fims.common.StagingDatabaseHandler.main(StagingDatabaseHandler.java:39)
i am unable to get to any solution to this issue. Trying not to use ResulSet wont work because the cursor does have a variable number of records which need to be retrieved one by one.
Somebody please help. This is urgent.
My code snippet is :-
Connection conn = getConnection();
CallableStatement stmt = conn.prepareCall("{call FEBCHK_ACTIONS.SP_GET_FAILED_BATCH_DOCS(?)}");
stmt.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR);
boolean exec = stmt.execute();
if(exec){
ResultSet rs = (ResultSet)stmt.getObject(1);
while(rs.next()){.......
The line
ResultSet rs = (ResultSet)stmt.getObject(1);
gives the error.

Similar Messages

  • Error wrt Ref Cursor.

    Hi all,
    I have a package, and I am using the ref Cursor in my procedure. Here it is .....
    CREATE OR REPLACE PACKAGE BLABLA_PKG AS
    TYPE OUT_CURSOR IS REF CURSOR;
    PROCEDURE BLABLA_VIEW_PROCEDURE (BUS_ID IN VARCHAR2,
    XML_OUTPUT_CURSOR OUT OUT_CURSOR);
    END BLABLA_PKG;
    CREATE OR REPLACE PACKAGE BODY BLABLA_PKG AS
    PROCEDURE BLABLA_VIEW_PROCEDURE (BUS_ID IN VARCHAR2,
    XML_OUTPUT_CURSOR OUT OUT_CURSOR)
    IS
    V_CURSOR OUT_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT SYS.XMLTYPE.getClobVal(OBJECT_VALUE)
    FROM MBR_VIEW
    WHERE extractValue(OBJECT_VALUE, '/BLABLA_TYPE/BUS/BUS_ID') = 456451232;
    END V_CURSOR;
    END BLABLA_PKG;
    WHEN I try to run the procedure its throwing an error as...
    Error(12,9): PLS-00113: END identifier 'V_CURSOR' must match BLABLA_VIEW_PROCEDURE' at line 2, column 16
    Can anyone help me out from this please??

    Thank you Bakker and sorry for my ignorance.
    And I have modified my packagage and compiled. Now i would like to execute the package. How would i do that?
    CREATE OR REPLACE PACKAGE BLABLA_PKG AS
    PROCEDURE BLABLA_VIEW_PROCEDURE (BLABLA_XML_RS OUT SYS_REFCURSOR, BUS_ID IN VARCHAR2
    END BLABLA_PKG;
    CREATE OR REPLACE PACKAGE BODY BLABLA_PKG AS
    PROCEDURE BLABLA_VIEW_PROCEDURE (BLABLA_XML_RS OUT SYS_REFCURSOR, BUS_ID IN VARCHAR2
    IS
    BEGIN
    OPEN BLABLA_XML_RS FOR
    SELECT SYS.XMLTYPE.getClobVal(OBJECT_VALUE)
    FROM BLABLA_VIEW
    WHERE extractValue(OBJECT_VALUE, '/BLABLA_TYPE/BUS/BUS_ID') = BUS_ID;
    END BLABLA_VIEW_PROCEDURE;
    END BLABLA_PKG;
    I am trying to execute it in the fallowing way, which is not working
    Execute BLABLA_PKG.BLABLA_VIEW_PROCEDURE(1111222, BLABLA_XML_RS);
    Could you please help me out....

  • Error Returning REF CURSOR

    I'm trying to return a REF CURSOR from a function and get the following error:
    ORA-00932: inconsistent datatypes: expected CURSER got NUMBER
    ORA-06512: at "CERTS.JIMMY", line 17
    ORA-06512: at line 10
    Here is my function:
    CREATE OR REPLACE PACKAGE jimmy
    AS
    TYPE refc IS REF CURSOR
    RETURN equipment%rowtype;
    FUNCTION getresults(p_ssan_in IN equipment.ssan%TYPE,
                             p_type_in IN equipment.equip_type%TYPE)
         RETURN refc;
    END jimmy;
    CREATE OR REPLACE PACKAGE BODY jimmy
    AS
    FUNCTION getresults( p_ssan_in IN equipment.ssan%TYPE,
                                  p_type_in IN equipment.equip_type%TYPE)
    RETURN refc
    IS
    l_cursor refc;
    isretired equipment.retired%TYPE := 'N';
    qry varchar2(100) := 'SELECT * ' ||
                                  'FROM equipment ' ||
                                  'WHERE ssan = :b1 ' ||
                                  'AND equip_type = :b2 ' ||
                                  'AND retired = :b3';
    BEGIN
    EXECUTE IMMEDIATE qry
         INTO l_cursor
         USING p_ssan_in, p_type_in, isretired;
    RETURN l_cursor;
    END getresults;
    END jimmy;
    The data types for the parameters are all varchar2. I don't know why it says it is returning a number.

    I tried your suggestion:
    BEGIN
    OPEN l_cursor
         FOR qry
         USING p_ssan_in, p_type_in, isretired;
    RETURN l_cursor;
    END getresults;
    But I get an error:
    PLS-00455: cursor 'L_CURSOR' cannot be used in dynamic SQL OPEN statement

  • 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.

  • Invalid SQL error using REF CURSOR

    I'm getting an "invalid SQL statement" in my function that is returning a REF CURSOR. I have tested this function in SQL*Plus and it works fine.
    -- package level variable
    TYPE t_cursor IS REF CURSOR;
    Function find_patient
         p_ssan IN varchar2,
         p_patient_details OUT t_cursor
         RETURN t_cursor
         IS
         v_cursor t_cursor;
         BEGIN
         OPEN v_cursor FOR
         SELECT name,sex,pay_grade,
              FLOOR(MONTHS_BETWEEN(sysdate,birthdate) / 12) AS age,
              patient_num
         FROM patient
         WHERE ssan = p_ssan;
         p_patient_details := v_cursor;
         RETURN p_patient_details;
         END find_patient;
    -- C# code
    OracleParameter ssan_in = new OracleParameter("p_ssan",OracleDbType.Varchar2);
    OracleParameter cursor_out = new OracleParameter("p_patient_details",OracleDbType.RefCursor);
    cmd.Parameters.Add(ssan_in).Direction = ParameterDirection.Input;
    cmd.Parameters.Add(cursor_out).Direction = ParameterDirection.Output;
    ssan_in.Value = "555555555";
    OracleRefCursor cur = (OracleRefCursor) cursor_out.Value;
    try
    dbconn.Open();
                        OracleDataReader dr = cmd.ExecuteReader();
                        while (dr.Read())
                             pat_name.Text = dr["NAME"].ToString();
                             age.Text = dr["AGE"].ToString();
                             rank.Text = dr["PAY_GRADE"].ToString();
                             gender.Text = dr["SEX"].ToString();
                             pat_num.Text = dr["PATIENT_NUM"].ToString();
    Any suggestions?

    First, you have an output parameter of type ref cursor and a return value. You shouldn't have both.
    Second, try CommandType.Text and a CommandText like:
    "begin :rc := find_patient(:ssan); end;"
    It's easier to see how to bind the parameters like that. Bind first a OracleRefCursor output parameter, then an ssan%type InputParameter.
    David

  • Error in ref cursor coding

    Error in refcursor
    Edited by: josh1612 on Feb 18, 2010 8:40 PM

    The code of that procedure is
    tId;
    Edited by: josh1612 on Feb 18, 2010 8:41 PM                                                                                                                                                                                           

  • How to retrieve data from a REF CURSOR using OCI 8.0?

    I found an example in Oracle docs (shown below) that discusses how to bind a REF CURSOR for later data retrieval, but it does not explain actually how to do the later data retrieval.
    I hope someone can explain it to me. Thanks
    The OCI provides the ability to bind and define PL/SQL REF CURSORs and nested tables. An application can use a statement handle to bind and define these types of variables. As an example, consider this PL/SQL block:
    static const text plsql_block = (text )
    "begin \
    OPEN :cursor1 FOR SELECT empno, ename, job, mgr, sal, deptno \
    FROM emp_rc WHERE job=:job ORDER BY empno; \
    OPEN :cursor2 FOR SELECT * FROM dept_rc ORDER BY deptno; \
    end;";
    An application would allocate a statement handle for binding, by calling OCIHandleAlloc(), and then bind the :cursor1 placeholder to the statement handle, as in the following code, where :cursor1 is bound to stm2p. Note that the handle allocation code is not included here.
    err = OCIStmtPrepare (stm1p, errhp, (text *) nst_tab, strlen(nst_tab),
    OCI_NTV_SYNTAX, OCI_DEFAULT);
    err = OCIBindByName (stm1p, (OCIBind **) bndp, errhp,
    (text *)":cursor1", (sb4)strlen((char *)":cursor1"),
    (dvoid *)&stm2p, (sb4) 0, SQLT_RSET, (dvoid *)0,
    (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT);
    In this code, stm1p is the statement handle for the PL/SQL block, while stm2p is the statement handle which is bound as a REF CURSOR for later data retrieval. A value of SQLT_RSET is passed for the dty parameter.

    ( sorry, i forgot the Link where i get this html fiLes, so i just copy-paste here )
    ( maybe it can heLp you a bit. -- it's heLp me, for sure )
    And the following is thanks to Brett Rosen :
    I noticed that you didn't have an OCI entry
    on http://osi.oracle.com/~tkyte/ResultSets/index.html .
    Here is OCI code to do this (Oracle 81) if you want to include it on
    that page.
    Some error checking and cleanup has been removed, but the below should
    work. (once dbname has been replaced appropriately)
    Brett
    int main(int argc, char* argv[])
    OCIError* pOciError;
    char* pConnectChar = "dbname";
    char* pUsernameChar = "scott";
    char* pPasswordChar = "tiger";
    int answer;
    OCIStmt* pOciStatement;
    char* sqlCharArray = "BEGIN :success := sp_ListEmp; END;";
    int id;
    char ename[40];
    OCIEnv* g_pOciEnvironment = NULL;
    OCIServer* g_pOciServer = NULL;
    OCISession* g_pOciSession = NULL;
    OCISvcCtx* g_pOciServiceContext = NULL;
    sb2* pIndicator=0;
    sb2* pIndicator2=0;
    sb2* pIndicator3=0;
    OCIDefine* pOciDefine;
    OCIDefine* pOciDefine2;
    OCIBind* pBind;
    OCIStmt* cursor;
    answer = OCIInitialize(OCI_THREADED, NULL, NULL, NULL, NULL);
    answer = OCIEnvInit(&g_pOciEnvironment, OCI_DEFAULT, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciSession, OCI_HTYPE_SESSION, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServer, OCI_HTYPE_SERVER, 0, NULL);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
    answer = OCIServerAttach(g_pOciServer, pOciError, (unsigned char *)pConnectChar, strlen(pConnectChar),
    OCI_DEFAULT);
    answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pUsernameChar, strlen(pUsernameChar),
    OCI_ATTR_USERNAME, pOciError);
    answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pPasswordChar, strlen(pPasswordChar),
    OCI_ATTR_PASSWORD, pOciError);
    answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciServer, 0, OCI_ATTR_SERVER, pOciError);
    answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciSession, 0, OCI_ATTR_SESSION, pOciError);
    answer = OCISessionBegin(g_pOciServiceContext, pOciError, g_pOciSession, OCI_CRED_RDBMS, OCI_DEFAULT);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&pOciStatement), OCI_HTYPE_STMT, 0, NULL);
    answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray, strlen(sqlCharArray),
    OCI_NTV_SYNTAX, OCI_DEFAULT);
    answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&cursor), OCI_HTYPE_STMT, 0, NULL);
    answer = OCIBindByPos(pOciStatement,&pBind, pOciError, 1, &cursor, 0,SQLT_RSET,
    pIndicator2, 0,NULL, 0,0,OCI_DEFAULT);
    answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
    OCI_COMMIT_ON_SUCCESS);
    answer = OCIDefineByPos(cursor,&pOciDefine, pOciError,2,&id,sizeof(int),
    SQLT_INT,pIndicator, 0, 0,OCI_DEFAULT);
    answer = OCIDefineByPos(cursor,&pOciDefine2, pOciError,1,ename,40,
    SQLT_STR,pIndicator3, 0, 0,OCI_DEFAULT);
    if (answer == 0)
    while ((answer = OCIStmtFetch(cursor,pOciError, 1,OCI_FETCH_NEXT,OCI_DEFAULT)) == 0)
    printf("fetched id %d and name %s\n",id,ename);
    answer = OCIHandleFree(pOciError, OCI_HTYPE_ERROR);
    return 0;
    }

  • Odd error while opening a ref cursor

    Hi.
    I have a procedure in a package that has both in and out parameters. One of those out parameters is a ref cursor. The procedure creates a dynamic query and then executes it, then it opens the cursor:
    PROCEDURE PROC(
    A IN VARCHAR2,
    B IN VARCHAR2,
    C OUT TYPES.cursorType; --(TYPES is a package whose only use is to declare a cursor type)
    ) IS
    --DECLARATIONS
    OPEN C FOR 'SELECT A, B, C, D...';
    END;
    When I execute the package in an anonymous block it throws the error:
    ORA-00938: not enough arguments for function, just in the line where the cursor is being opened.
    Any ideas?

    is everything defined correctly?
    create or replace package types  as
      type cursorType is ref cursor;
    end types;
    SQL> set serveroutput on
    SQL> declare
      2 
      3    ref_C types.cursorType;
      4   
      5    v_a varchar2(1);
      6    v_b varchar2(1);
      7    v_c varchar2(1);
      8    v_d varchar2(1);
      9   
    10    procedure Proc (a in varchar2
    11                   ,b in varchar2
    12                   ,C out types.cursorType) as
    13 
    14      begin
    15        open C for 'select :1, :2, ''c'', ''d'' from dual' using a, b;
    16    end  Proc;
    17  begin
    18 
    19 
    20    Proc('a', 'b', ref_C);
    21   
    22    fetch ref_C into v_a, v_b, v_c, v_d;
    23    if (ref_C%found) then
    24      dbms_output.put_line(v_a);
    25      dbms_output.put_line(v_b);
    26      dbms_output.put_line(v_c);
    27      dbms_output.put_line(v_d);
    28    end if;
    29   
    30   
    31  end;
    32  /
    a
    b
    c
    dP;
    Edited by: bluefrog on Feb 18, 2010 6:07 PM

  • Error while working with ref cursor

    Hi I tried the following but getting the err
    DECLARE
    TYPE ref_nm IS REF CURSOR;
    vref REF_NM;
    vemp emp%rowtype;
    BEGIN
    OPEN vref FOR SELECT ename ,sal FROM EMP;
    LOOP
      FETCH vref INTO vemp;
      EXIT WHEN vref%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE ( vemp.ename ||','||vemp.sal );
    END LOOP;
      CLOSE vref;
    END;Error is
    ORA-06504: PL/SQL: Return types of Result Set variables or query do not match

    Syntactically correct - but a horrible approach performance wise if you only need specific columns.
    The basic problem here is using the wrong tool. A ref cursor. Why? There's no reason in this code for using a ref cursor. Using a standard cursor data type addresses the requirement a lot better.
    As you can define the cursor:
    cursor myCursor is select c1, c2 from tab1;
    You can define an array data type for fetching that cursors data - and thus definition does not need to be touched when you change the cursor itself to include/exclude columns:
    type TMyCursorBuffer is table of myCursor%RowType;
    And finally you can define a bulk collection buffer for bulk processing the output of the cursor:
    myBuffer TMyCursorBuffer;

  • XSQL ERROR with bind-params in ref-cursor-function

    Hi Steve
    I always get the error
    ORA-01006 bind variable does not exist
    when using a bind variable in a <xsql:ref-cursor-function> action element.
    when I replace the bind variable with a @ - parameter substitution, all works fine.
    My configuration:
    XSQL 1.0.4.1 on Win200Pro ,Apache + Jserv + DB from ORA 8.1.7 installation
    My Source
    <xsql:ref-cursor-function
    dbconn="ekat"
    eblike="%"
    list="a0"
    bind-params="eblike"
    include-schema="no"
    null-indicator="no"
    id-attribute=""
    fetch-size="500"
    >
    {@dbconn}o.ekatkategcv.open_cv_ebh ('{@list}', :1)
    </xsql:ref-cursor-function>
    ( dbconn selects my schema, not changed often, which contains package ekatkategcv with
    function open_cv_ebh returning a cursor)
    Any fix would be appreciated to avoid reparsing on each call.
    BTW, is it right, that a ref-cursor funtion is reparsed whenever the content of
    a parameter used with @ changes?
    Best regards
    H.Buschmann ([email protected])
    null

    I have tried it using ? instead of :1, this method works fine.
    I haven't tried the name method (:bindvar) yet.
    Until now, I only used xsl:query and xsql:ref-cursor-function, so I didn't check
    the other action handlers with bind variables like :1
    null

  • In Ref cursor, user defined functions give "invalid column" error in EJB.

    Hello,
    I have written PL/SQL stored procedures/functions in Oracle 8i. They return the result set as a ref cursor.
    These procedures are accessed by EJB (weblogic) using Type 4 (100% Java) JDBC Driver.
    My problem is - if I use a user defined function to fetch a value in the select statement of the reference cursor, the EJB gives an error msg - invalid column name.
    If instead of using the function I get the value directly from the table, it works fine. Refer the code below :
    //In the PL/SQL function -
    //instead of writing :
    Open rc for
    Select empcode, empname
    from emp ;
    //If I write :
    Open rc for
    Select empcode, mypack.getempname(empcode)
    from emp ;
    //getempname(empcode) is a function in
    //in a package named 'mypack'
    //and returns name for empcode.
    //The java code gives error
    //error : invalid column name
    //While both are working fine and
    //returning currect result in SQL Navigator.
    Help me solve this mystery ?
    Thanks in advance.
    Swati.
    null

    Hi:
    When use inline Function to simplify the SQL statements, there is one thing that one should conside--Purity Level.
    if you create standalone stored pl/sql function. Oracle implicitly determines the PURITY level during compilation of the stored objects or at execution of an anonymous pl/sql block.
    if you implement Package inline Function( in your case),unlike standalone stored pl/sql functions, the PL?SQL Engine does not determine the purity level of package functions. Therefore, you must explicity assign the correct purity levels for the function to be called inline.
    the code like:
    create or replace package mypack is
    function getempname(empcode emp%empid%type)
    return varchar2;
    PRAGMA RESTRICT_REFERENCES(getempname,WNDS,WNPS,RNPS);
    end mypack;
    I think it can solve your problem if you use enough "pure"to be called inline function. Or you can create the standalone function to do it.
    good luck!
    Yali
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Swati Agrawal ([email protected]):
    Hello,
    I have written PL/SQL stored procedures/functions in Oracle 8i. They return the result set as a ref cursor.
    These procedures are accessed by EJB (weblogic) using Type 4 (100% Java) JDBC Driver.
    My problem is - if I use a user defined function to fetch a value in the select statement of the reference cursor, the EJB gives an error msg - invalid column name.
    If instead of using the function I get the value directly from the table, it works fine. Refer the code below :
    //In the PL/SQL function -
    //instead of writing :
    Open rc for
    Select empcode, empname
    from emp ;
    //If I write :
    Open rc for
    Select empcode, mypack.getempname(empcode)
    from emp ;
    //getempname(empcode) is a function in
    //in a package named 'mypack'
    //and returns name for empcode.
    //The java code gives error
    //error : invalid column name
    //While both are working fine and
    //returning currect result in SQL Navigator.
    Help me solve this mystery ?
    Thanks in advance.
    Swati.
    <HR></BLOCKQUOTE>
    null

  • Retrieving nested table columns through a REF CURSOR in php

    Hello.
    I have been able to execute REF CURSORS returned by pl/sql functions succesfully with php. I have also been able to bind collections to the input/output of pl/sql functions/procedures.
    However, what I am unable to do, is to execute a cursor returned by a pl/sql function that has one of the columns a named datatype (a simple one-dimensional nested table):
    create type stab is table of varchar2(255);
    create table lp_landing (
    token varchar2(255),
    text varchar2(512),
    country varchar2(255),
    creator varchar2(255),
    is_active char(1),
    css_file char(1),
    autofollowing stab default stab(),
    constraint lp_landing_pk primary key (token)) organization index
    nested table autofollowing store as lp_landings_af_nt
    (constraint autofollowing_pk primary key (nested_table_id,column_value)) organization index compress
    function landings_usercountry (in_uname in lp_users.uname%type, in_country in lp_country.cname%type) return Landing_curType
    is
    ret Landing_curType;
    begin
    open ret for
    select * --token,text,country,creator,is_active,css_file,tab2str(autofollowing) as autofollowing
    from lp_landing
    where country = (select country
    from lp_permissions
    where country = in_country and uname = in_uname);
    return ret;
    end landings_usercountry;
    here is the php:
    $sql = 'BEGIN :res := LP_PKG.landings_usercountry(:user, :country); END;';
    $stmt = oci_parse($c, $sql);
    $cursor = oci_new_cursor($c);
    oci_bind_by_name($stmt,':user',$name, 32);
    oci_bind_by_name($stmt,':country',$country, 32);
    oci_bind_by_name($stmt,':res', $cursor, -1, OCI_B_CURSOR);
    $name = "root";
    $country = "Spain";
    try {
       @oci_execute($stmt);
       $m = oci_error($stmt);
       if($m){
           throw new Exception($m['message'], $m['code']);
       }else{
           @oci_execute($cursor);
           $m = oci_error($cursor);
           if($m){
               throw new Exception($m['message'], $m['code']);
           }else{
               while ( $entry = oci_fetch_object($cursor) ) {
                    var_dump($entry);
    } catch (Exception $e) {
       print_r($e);
    With "select *" in the function, the autofollowing column (of datatype stab) fails to bind, giving an ORA-932 error. The workaround for the moment is to convert the nested table to a comma delimited string (via the tab2str function).
    However, I would like to be able to tell php to accept a collection within the cursor, but I cannot figure out how to do this.
    Any ideas?
    thx in advance

    yes, it is an ORA-932:
    Warning: oci_fetch_object() [function.oci-fetch-object]: ORA-00932: inconsistent datatypes: expected CHAR got ADT in /home/apolion/apache2/htdocs/old/test1.php on line 104

  • Different error messages from different env while fetching ref cursor

    Hi<br>
    I have a package where i need to call one of the procedure.I this <br>
    procedure i am returning a refcursor as out parameter.Before returning refcursor i <br>
    am doing i am checking a condition if it is satisfied then I am saying return or else<br>
    it will proceed and refcursor is assigned for out parameter.So i am speakig about <br>
    the condition where i am exiting from procedure before refcursor parameter is <br>
    assigned .And later i am tring to fetch from that cursor .So i am getting different <br>
    kinds of errors which i described as follows <br>
    <br>
    <br>
    So If execute that procedure from sqlplus uing <br>
    <br>
    <br>
    var m ref cursor<br>
    DECLARE<br>
    Y NUMBER;<br>
    Z NUMBER;<br>
    A NUMBER;<br>
    BEGIN<br>
    A:=campa.dtl_inq(2,100070875,'R',Y,Z,:M);<br>
    END;<br>
    <br>
    Then if say<br>
    Print m<br>
    It gives <br>
    <br>
    ORA-24338: statement handle not executed<br>
    <br>
    And if i execute this using vb application <br>
    <br>
    I am getting following error <br>
    <br>
    ORA-01023: Cursor context not found (Invalid cursor number)<br>
    <br>
    So i am serching the reason for different errors<br>
    <br>
    Regards<br>
    vamsi krishna<br>

    The error depends on exactly what OCI calls the client software makes in accessing this invalid (null) ref cursor variable.
    It would seem that SQL*Plus makes different calls than what your code and Visual Basic does - thus the different error messages returned by the two applications.

  • Error in dynamic ref cursor

    hi
    i tried the following but getting the error.. Could you help me in this please
    SQL> create or replace package curpack as
      2    type T_CUR is ref cursor;
      3    procedure CHECKDYNREF (io_cur out T_CUR);
      4  end curpack;
      5  /
    Package created.
    SQL>
    SQL> create or replace package body curpack as
      2    procedure CHECKDYNREF (io_cur out T_CUR);
      3    is
      4     begin
      5       open io_cur for 'SELECT * FROM EMP';
      6    end;
      7  end curpack;
      8  /
    Warning: Package Body created with compilation errors.
    SQL> sho err
    Errors for PACKAGE BODY CURPACK:
    LINE/COL ERROR
    3/3      PLS-00103: Encountered the symbol "IS" when expecting one of the
             following:
             begin end function package pragma procedure subtype type use
             <an identifier> <a double-quoted delimited-identifier> form
             current cursor
    7/1      PLS-00103: Encountered the symbol "END"Thanks...
    Edited by: josh1612 on Jan 24, 2010 9:05 PM

    Hi,
    There should not be a ';' (semi colon ) after the declaration of procedure in package body
    SQL> create or replace package body curpack as
          procedure CHECKDYNREF (io_cur out T_CUR);
          is
           begin
             open io_cur for 'SELECT * FROM EMP';
          end;
        end curpack;
        / Something like above
    Regards

  • Ref Cursor is invalid error

    Hi,
    I have written a jdbc application which return a ref cursor. I use ResultSet rset = ((OracleCallableStatement)call).getCursor (1); to get the result set according to jdbc user guide. Compilation is ok but when I run it, the error is:
    Exception in thread "main" java.sql.SQLException: Ref cursor is invalid
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Exception.java:42)
    at java.sql.SQLException.<init>(SQLException.java:43)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:219)
    at oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:2544)
    at oracle.jdbc.driver.OracleCallableStatement.getCursor(OracleCallableStatement.java:583)
    at useCursor.main(useCursor.java:41)
    I attach the code for ur reference. Pls point out to me what's wrong.
    import oracle.sql.*;
    import oracle.jdbc.oracore.Util;
    import java.sql.*;
    import java.io.*;
    import oracle.jdbc.driver.*;
    class useCursor{
    private static final String Server = "job.comp.edu.au:1521:testing";
    private static final String Username = "user";
    private static final String Password = "org";
    public static void main (String args [])
    throws SQLException
    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn = getConnection ();
    String elements[] = new String[1];
    elements[0] = "select * from product";
    // Create the stored procedure
    init (conn);
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STR_VARRAY3", conn);
    ARRAY newArray = new ARRAY(desc, conn, elements);
    // Prepare a PL/SQL call
    CallableStatement call =
    conn.prepareCall ("{ ? = call java_refcursor.job_listing (?)}");
    // Find out all the SALES person
    call.registerOutParameter (1, OracleTypes.CURSOR);
    ((OraclePreparedStatement)call).setARRAY(2, newArray);
    call.execute ();
    ResultSet rset = ((OracleCallableStatement)call).getCursor (1);
    // Dump the cursor
    while (rset.next ())
    System.out.println (rset.getString ("AUTHOR"));
    // Utility function to create the stored procedure
    static void init (Connection conn)
    throws SQLException
    Statement stmt = conn.createStatement ();
    try
    stmt.execute ("DROP TYPE str_varray3");
    catch (SQLException e)
    // the above drop statements will throw exceptions
    // if the types and tables did not exist before. Just ingore it.
    stmt.execute ("CREATE TYPE str_varray3 AS VARRAY(10) OF VARCHAR2(50)");
    stmt.execute ("create or replace package java_refcursor as " +
    " type myrctype is ref cursor; "+
    " function job_listing (sa str_varray3) return myrctype; " +
    "end java_refcursor;");
    stmt.execute ("create or replace package body java_refcursor as " +
    " function job_listing (sa str_varray3) return myrctype is " +
    " rc myrctype; " +
    " i number; " +
    " begin " +
    " while sa.COUNT >= i" +
    " loop " +
    " open rc for sa(1);" +
    " exit when rc%NOTFOUND; " +
    " i := i + 1; " +
    " end loop; " +
    " return rc; " +
    " end; " +
    "end java_refcursor;");
    public static Connection getConnection(){
    Connection con = null;
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    catch (SQLException sqlex ) {
    System.err.println("Unable register Oracle driver");
    sqlex.printStackTrace();
    try {
    con = DriverManager.getConnection("jdbc:oracle:thin:@" + Server, Username, Password);
    catch (SQLException sqlex) {
    System.err.println("Unable to connect");
    sqlex.printStackTrace();
    return con;
    Please advise me. Thank you very much.
    null

    i have found out my mistake
    it lacks of i := 0;
    my mind was not so ok then.. :)

Maybe you are looking for