Is it possible to return a cursor as a HANA Stored Procedure OUT parameter?

Hi,
I have a use case where I need to return a record set from a HANA Stored Procedure to the caller based on a couple of input parameters to the procedure. However, the record set needs to be dynamic and may have different columns based on the input parameters.
I could achieve this by creating hdbstructures or using table types as OUT parameters. However, is it possible to return a cursor holding the result set of a SELECT query as an OUT parameter for a HANA stored procedure?
(I am looking for something similar to Oracle's SYS_REFCURSOR)
Best Regards,
Abhik

Did you try using EXECUTE IMMEDIATE
Have a look on this:
SAP HANA: Handling Dynamic Select Column List and Multiple values in input parameter
Regards,
Krishna Tangudu

Similar Messages

  • Command for "How to find Cursor Size" in Oracle Stored Procedure"

    Hi
    Can u tell me....
    How to find Cursor Size" in Oracle Stored Procedure........
    I want command for that........

    why don't you try select count(*) from your_table;That requires running the same query twice - or rather running two different queries twice. Besides it still doesn't guarantee anything, because Oracle's read consistency model only applies at the statement level (unless you're running in a serialized transaction).
    This is such a common requirement - users are wont to say "well Google does it" - it seems bizarre that Oracle cannot do it. The truth is that that Google cheats. Firstly it guesses the number on the basis of information in its indexes and refines the estimate as pages are returned. Secondly, Google is under no onus to kepp all its data and indexes synchronized - two simultaneous and identical queries which touch different Google servers can return different results. Oracle Text works the same way, which is why we can get a count with CTX_QUERY.COUNT_HITS in estimate mode.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com
    .

  • Return ref cursor from database link/stored proc? do-able?

    Is it possible to return a REF CURSOR from a stored procedure that is being called from a remote database via a database link???
    We are trying from Pro*Cobol on MVS (which has db link pointing to AIX thru db link) and get a 00993 error, which seems to say this is not possible.
    Before I give up, thought I would check with the experts....
    Thanks in advance.

    You can't return Java objects as stored procedure or query results.
    Douglas

  • Resultset returns null while calling a DB2 stored procedure using hibernat

    Hi All ,
    I am trying to call a db2 stored proc with cursor open from my java code but it always returns me null results though it executes fine when I call the procedure from the command line
    Java code....................
    CallableStatement stmt3 = EyeHibernateApp.getHibernateSession().connection().prepareCall("{call answers_select_id( ? )}");
    stmt3.setString(1,20);
    stmt3.execute();
    ResultSet rs1 = stmt3.getResultSet();
    System.out.println("rs1 " + rs1); --> returns null
    procedure-------------
    CREATE PROCEDURE answers_select_id (IN question_id bigint )
    P1:BEGIN
    DECLARE cursor1 CURSOR WITH RETURN TO CLIENT FOR
    SELECT a.answer_id from answers as a where a.question_id = question_id;
    open cursor1;
    END P1;
    I am using the same java code with mysql stored procs . It works fine there but I assume open cursors in db2 stored proc is causing the problem . If I can help it , I need to maintain the same java code for mysql ad db2 . Please help me ...
    Thanks,
    Av~

    Hi,
    I am trying to do something like this but with Oracle stored procedure which returns an associate array and a cursor and these are defined as INOUT. I am not finding a way how to do it with editable row set. Can you plese list the steps used to make things work.
    Thanks.

  • Resultset returns null while calling a DB2 stored procedure using hibernate

    Hi All ,
    I am trying to call a db2 stored proc with cursor open from my java code but it always returns me null results though it executes fine when I call the procedure from the command line
    Java code....................
    CallableStatement stmt3 = EyeHibernateApp.getHibernateSession().connection().prepareCall("{call answers_select_id( ? )}");
    stmt3.setString(1,20);
    stmt3.execute();
    ResultSet rs1 = stmt3.getResultSet();
    System.out.println("rs1 " + rs1); --> returns null
    procedure-------------
    CREATE PROCEDURE answers_select_id (IN question_id bigint )
    P1:BEGIN
    DECLARE cursor1 CURSOR WITH RETURN TO CLIENT FOR
    SELECT a.answer_id from answers as a where a.question_id = question_id;
    open cursor1;
    END P1;
    I am using the same java code with mysql stored procs . It works fine there but I assume open cursors in db2 stored proc is causing the problem . If I can help it , I need to maintain the same java code for mysql ad db2 . Please help me ...
    Thanks,
    Av~

    Hi,
    I am trying to do something like this but with Oracle stored procedure which returns an associate array and a cursor and these are defined as INOUT. I am not finding a way how to do it with editable row set. Can you plese list the steps used to make things work.
    Thanks.

  • Returning result set from procedure out parameter, display with anon block

    I'm trying to do something pretty simple (I think it should be simple at least). I want to use a pl/sql procedure to return a result set in an OUT parameter. If I run this code by itself (in the given anonymous block at the end, without trying to display any results), toad says that the PL/SQL procedure successfully completed.
    How can I display the results from this procedure? I am assuming that the result set should be stored in the O_RETURN_REDEEM_DTL, but how can I get anything out of it?
    I have this package with the following procedure:
    /* FUNCTION - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              --OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN, REGISTER_NBR_IN, TRANS_NBR_IN);
              OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;and call it in an anonymous block with:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RETURN_REDEEM_DTL_OUT PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ_CUR%rowtype;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
    REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN O_RETURN_REDEEM_DTL
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || item.ZL_DIVN_NBR);
      END LOOP;
    END; And end up with an error:
    ORA-06550: line 25, column 15:
    PLS-00221: 'O_RETURN_REDEEM_DTL' is not a procedure or is undefined
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredMessage was edited by:
    user607908

    Aha, I knew I forgot something!
    I actually had it defined as a REF CURSOR in PSAPP.CY_SALESPOSTING package spec:
    TYPE REDEEM_DTL_TYPE IS REF CURSOR;since I wasn't sure what to make it.
    Cursor used in procedure:
    CURSOR REDEEM_DTL_READ_CUR (
      zl_divn_nbr_in IN NUMBER,
      greg_date_in IN DATE,
      zl_store_nbr_in IN NUMBER,
      register_nbr_in IN NUMBER,
      trans_nbr_in IN NUMBER)
    IS
    SELECT ZL_DIVN_NBR, GREG_DATE, ZL_STORE_NBR, REGISTER_NBR, TRANS_NBR, PAYMENT_TYP_NBR
    FROM REDEEM_DTL
    WHERE ZL_DIVN_NBR = zl_divn_nbr_in AND GREG_DATE = greg_date_in AND
       ZL_STORE_NBR = zl_store_nbr_in AND REGISTER_NBR = register_nbr_in AND
       TRANS_NBR = trans_nbr_in;Updated code:
    /* PROCEDURE - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
                   REGISTER_NBR_IN, TRANS_NBR_IN);
              --OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
              LOOP
                  FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
                   EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
                   DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL.ZL_DIVN_NBR);
                END LOOP;
               CLOSE REDEEM_DTL_READ_CUR;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;the updated anon block:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
         REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN 1..O_RETURN_REDEEM_DTL.COUNT
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL(item).ZL_DIVN_NBR);
      END LOOP;
    END;and the new error:
    ORA-06550: line 25, column 38:
    PLS-00487: Invalid reference to variable 'O_RETURN_REDEEM_DTL'
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredAlso, it would be nice if the forums would put a box around code so that it would be easy to
    distinguish between what is supposed to be code and what should be regular text...
    Message was edited by:
    user607908

  • Cursor flow in a stored procedure

    Hi All,
    I am new to stored procedure. i just have a little doubt.
    i have created a stored procedure that will do the following.
    a cursor will be opened for some select values (select table2.col1 c1, table2.col2 c2, sum(table2.col3) sum1 from table1, table2 where some_constaints)
    later on, inside a for loop i am updating table1 columns with the sum selected from the previous select.(update table1.col1 = sum1 where table1.col1 = c1 and table1.col2 = c2).
    So my queries both Select and Update will include table1. (So i am selecting and updating the same table).
    what i want to know is when we open a cursor(OR when we fetch data from cursor), will it execute that select statement and stores that result into a temporary storage?
    OR will it fetches the data from the actual tables.
    i just want to know how a cursor works.
    Please help me.
    Thank you.

    the select:
    SELECT DIST.BUSINESS_UNIT BU  , DIST.VOUCHER_ID ID  , DIST.VOUCHER_LINE_NUM LN , DIST.TAX_CD_SUT_PCT UP
      FROM DISTRIB_LINE DIST
      , VOUCHER_LINE LINE
    WHERE LINE.SUT_APPLICABILITY IN ('S','U','D')
       AND LINE.TAX_CD_SUT_PCT = 0
       AND LINE.BUSINESS_UNIT = DIST.BUSINESS_UNIT
       AND LINE.VOUCHER_ID = DIST.VOUCHER_ID
       AND LINE.VOUCHER_LINE_NUM = DIST.VOUCHER_LINE_NUM
       AND DIST.TAX_CD_SUT_PCT <> 0
       AND DIST.DISTRIB_LINE_NUM = (SELECT MIN(DISTRIB_LINE_NUM)
                          FROM DISTRIB_LINE
                          WHERE BUSINESS_UNIT = DIST.BUSINESS_UNIT
                          AND VOUCHER_ID = DIST.VOUCHER_ID
                          AND VOUCHER_LINE_NUM = DIST.VOUCHER_LINE_NUM)the update:
    UPDATE VOUCHER_LINE
    SET TAX_CD_SUT_PCT = UP
    WHERE BUSINESS_UNIT = BU
    AND VOUCHER_ID = ID
    AND VOUCHER_LINE_NUM = LN
    the first one selects values by joining VOUCHER_LINE and DISTRIB_LINE for some where conditions. and we need update the VOUCHER_LINE only for those, which are selected from the select query.
    I have replaced those two(select and update) queries with single query as follows. but it needs same same select statement execute twice(which i have).
    UPDATE PS_VOUCHER_LINE LINE
        SET LINE.TAX_CD_SUT_PCT = (SELECT TAX_CD_SUT_PCT FROM PS_DISTRIB_LINE DIST
                                                     WHERE LINE.BUSINESS_UNIT = DIST.BUSINESS_UNIT
                                                     AND LINE.VOUCHER_ID = DIST.VOUCHER_ID
                                                     AND LINE.VOUCHER_LINE_NUM = DIST.VOUCHER_LINE_NUM
                                                     AND DIST.TAX_CD_SUT_PCT <> 0
                                                     AND DIST.DISTRIB_LINE_NUM = ( SELECT MIN(DISTRIB_LINE_NUM)
                                                                                                        FROM DISTRIB_LINE
                                                                                                        WHERE BUSINESS_UNIT = DIST.BUSINESS_UNIT
                                                                                                        AND VOUCHER_ID = DIST.VOUCHER_ID
                                                                                                        AND VOUCHER_LINE_NUM = DIST.VOUCHER_LINE_NUM)
         WHERE LINE.SUT_APPLICABILITY IN ('S','U','D')
            AND LINE.TAX_CD_SUT_PCT = 0
            AND EXISTS (SELECT 'X' FROM PS_DISTRIB_LINE DI WHERE LINE.BUSINESS_UNIT = DI.BUSINESS_UNIT
                                                      AND LINE.VOUCHER_ID = DI.VOUCHER_ID
                                                      AND LINE.VOUCHER_LINE_NUM = DI.VOUCHER_LINE_NUM
                                                      AND DI.TAX_CD_SUT_PCT <> 0
                                                      AND DI.DISTRIB_LINE_NUM = ( SELECT MIN(DISTRIB_LINE_NUM)
                                                                                                        FROM PS_DISTRIB_LINE
                                                                                                        WHERE BUSINESS_UNIT = DI.BUSINESS_UNIT
                                                                                                        AND VOUCHER_ID = DI.VOUCHER_ID
                                                                                                        AND VOUCHER_LINE_NUM = DI.VOUCHER_LINE_NUM)
        )if i don't put the EXISTS condition there is a danger like following.
    every line VOUCHER_LINE will be updated either with valid value(if the subquery(bold one) returns something) OR NULLs(if the subequery does not return any thing).
    If the sub qery does not return any thing It must keep the old value for the field TAX_CD_SUT_PCT. That is why i want to try it in stored procedure.
    Please click the image below to see for formatted queries.
    http://narchu.coolinc.info/selectandupdate.JPG

  • Invoke/Return Dataset from WebService in CLR Stored Procedure

    Hello,
    I am running SQL Server 2008 R2 or 2012 and Visual Studio 2010 Premium sp1. I have a stored procedure which currently returns a dataset which is used via SQLDataReader within a C# code-behind module in an ASP.NET application. This application uses the .NET
    4.0 framework. 
    I need to join the results from an external webservice (but within the same network) to this dataset. Instead of getting the data and putting it into a data table in code-behind (probably a HashTable which I could join with key/value pairs), I would like
    to get all of the data in the same stored procedure. I was thinking I could invoke the webservice and pass the input parms to the webservice then put the results into a temp table which I could then join with the query to the physical table.
    So, I have done quite a bit of researching online but have been unable to find any definitive answer or solution. I read the related forum thread "CLR Stored procedure consume webservice" but this does not address my versions of SQL Server / .NET
    framework.
    If someone could offer any suggestions or point in the right direction I would greatly appreciate it. Perhaps what I am trying to do is simply not possible?
    Regards,
    Buster

    Hello,
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated.
    Thank you for your understanding and support.
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here.
    Fanny Liu
    TechNet Community Support

  • Return national language strings from java stored procedures

    Hi, all.
    How does i can return String which contains national characters from java stored procedure? I.e. convert UTF java string to national language of database. It's does not processing automatically (why?).
    declaration of procedure:
    CREATE OR REPLACE FUNCTION TestNLSString RETURN VARCHAR2
    AS
    LANGUAGE JAVA
    NAME 'test.SomeClass.getNLSString() return java.lang.String';
    SELECT TestNLSString AS X FROM DUAL;
    X
    iiiii
    OS: Windows 2000 Server
    Oracle Server version: Oracle 8.1.7.1.4

    Ok. I had a specific problem.
    I want to use java stored procedure (function) to make a connection to remote db using supplied connection parameters make some quieries there end return results in a form of structured data - object.
    I have defined an object type in a database where the function will reside. I granted execute privilege to public user on this type, made public synonyms to both, the object type and the function, so anybody connected to the same database would have an access to this functionality.
    I supposed that if I supply connection parameters for some other user but the same database when running the function, everything should go smooth. Yeah.
    My java code executed ok: it made a connection to the db with some x user, it resolved object type descriptor given (oracle.sql.StructDescriptor), but pl/sql wrapper function reported the error I've mentioned. If I executed the function giving it the connection parameters for same account as where object type was declared, everything went fine.
    My final solution is:
    Make TWO! connection in java code: 1st for ("jdbc:default:connection:"), 2nd for remote database account.
    Use first connection to construct oracle.sql.StructDescriptor
    Use second connection to retreive data from remote db

  • Trouble referencing return values of a Function in Stored Procedure

    Hello all,
    I have the following Function and Stored Procedure (simplified for this post). The error I am getting is in the SELECT, WHERE clause of the UPDATE command. My function is returning a sys_refcursor and I am trying to reference column names but keep getting the error
    ORA-00904: "PUBLISHEDDOCVERSIONID": invalid identifier
    What am I doing wrong?
    Function
    CREATE OR REPLACE FUNCTION &HKDB_Schema_Name..QueryKnowdeDocVersion(aKGID int)
    RETURN sys_refcursor
    IS
    aCur sys_refcursor;
    BEGIN
    OPEN aCur FOR
    SELECT pkd.KnowdeID as "PublishedKnowdeID", pkd.DocumentID as "PublishedDocID", pkd.VersionID as "PublishedDocVersionID"
    FROM KnowdeDocument pkd
    WHERE pkd.KGID = aKGID;
    RETURN aCur;
    END;Stored Procedure
    UPDATE KnowdeDocument
    SET DocumentID = (SELECT PublishedDocID FROM (SELECT QueryKnowdeDocVersion(aKGID, aPublishedKGID, aTextVersionID) FROM DUAL)
                      WHERE PublishedKnowdeID = KnowdeDocument.KnowdeID
                      AND PublishedDocID = KnowdeDocument.DocumentID
                      AND ((PublishedDocVersionID is NULL and KnowdeDocument.VersionID is NULL) OR (PublishedDocVersionID is not NULL AND
                               PublishedDocVersionID = KnowdeDocument.VersionID)))Regards,
    Toby

    Hi redeye,
    Your select is from:
    (select queryknowdedocversion(akgid
                                  ,apublishedkgid
                                  ,atextversionid)
                         from dual)This has no publisheddocversionid. Unfortunately I cannot figure out what you are trying to do with that ref_cursor.
    Edit:
    Or perhaps publisheddocversionid is a column in KnowdeDocument? Could this be case sensitive as well? (Bad idea to use quotations when naming things)
    Regards
    Peter
    Edited by: Peter on Aug 24, 2009 3:39 AM

  • How to return varied no.of columns from Stored Procedure?

    Hi All,
    I have situation where I need to return with columns which will keep changing. At any given point of time I will be returning 10 columns. But there are some conditions where I need to add multiples of 4 no.of columns.
    Ex: Always 10 columns.
    If condition1
    return 10 + 4 columns
    if condition2
    return 10 + 4 + 4 columns
    How can I handle this?
    Can any one help me here.
    Thanks
    Vikram

    Change the stored procedure to a single column set return type like returning nulls if column is not applicable.
    Alternate, split the sp to single column set sp-s.
    You can get the returned column set by SELECT TOP(0) * INTO spxColumns FROM OPENQUERY..... method:
    http://sqlusa.com/bestpractices2005/selectfromsproc/
    http://www.sqlusa.com/bestpractices/select-into/
    Note, however, the OPENQUERY method is not completely clean.
    Kalman Toth Database & OLAP Architect
    Free T-SQL Scripts
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How to return a VARRAY datatype in a stored procedure

    I have declared a type using
    create type list1 as VARRAY(1000) of number(5);
    I want to return a list of values from a stored procedure. I created a stored procedure using
    create procedure getlist(mylist OUT list1) is
    begin
    end;
    The type and procedure creation was successful. But when I call this stored procedure from a PL/SQL module I get the following error.
    ORA-06531: Reference to uninitialized collection
    The PL/SQl module is
    declare
    s1 list1(1,2);
    begin
    getlist(s1);
    end;
    I want the procedure to return around 1000 values. Any solutions.
    Mohan
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by MOHAN [email protected]:
    I have declared a type using
    create type list1 as VARRAY(1000) of number(5);
    I want to return a list of values from a stored procedure. I created a stored procedure using
    create procedure getlist(mylist OUT list1) is
    begin
    end;
    The type and procedure creation was successful. But when I call this stored procedure from a PL/SQL module I get the following error.
    ORA-06531: Reference to uninitialized collection
    The PL/SQl module is
    declare
    s1 list1(1,2);
    begin
    getlist(s1);
    end;
    I want the procedure to return around 1000 values. Any solutions.
    Mohan<HR></BLOCKQUOTE>
    I am also having the same problem ..plzz help me someone
    null

  • ResultSet of a cursor as an out parameter

    How can you return a cursor or a resultSet as an OUT parameter? - Any info will be greatly appreciated. A code ex will be great
    vj

    Assuming you mean as an output parameter of pl/sql procedure being called from pl/sql...
    declare
      type refcur_type is ref cursor;
      type tab_user_tables_type is table of user_tables%rowtype index by binary_integer;
      refcur_user_tables refcur_type;
      tab_user_tables tab_user_tables_type;
      row_user_tables user_tables%rowtype;
      procedure get (
        out_refcur_user_tables out refcur_type,
        out_tab_user_tables out tab_user_tables_type) is
      begin
        for row_user_tables in (select * from user_tables) loop
          out_tab_user_tables(nvl(out_tab_user_tables.count, 0) + 1) := row_user_tables;
        end loop;
        open out_refcur_user_tables for select * from user_tables;
      end get;
    begin
      get(refcur_user_tables, tab_user_tables);
      dbms_output.put_line('from table ...');
      for i in 1 .. tab_user_tables.count loop
        dbms_output.put_line(tab_user_tables(i).table_name);
      end loop;
      dbms_output.put_line('from reference cursor ...');
      loop
        fetch refcur_user_tables into row_user_tables;
        exit when refcur_user_tables%notfound;
        dbms_output.put_line(row_user_tables.table_name);
      end loop;
    end;

  • How do I get the returned cursor from a stored procedure to an asp.

    Sorry if this topic has been answered before but I am new to Oracle and ASP. I have been asked to create some stored procedures and access the results from the ASP. I will be passing one variable in and could be getting upto 200 rows returned.
    I have no trouble with the stored procedure but have no clue how to retrieve the data returned by it.

    Assuming that the stored procedure has a single argument, an OUT cursor, you should be able to do
    SQLExecDirect
    {call <stored_proc>() }
    SQLFetch
    SQLGetData
    We'll handle all the 'magic' underneath.
    Justin Cave
    ODBC Development

  • OCI8: returning cursors from stored procedures

    The short version of my question is:
    In OCI8, how do open a cursor from the database stored procedure, return it to my C++ program and fetch from it, given that in OCI8 cursors and cursor functions are becoming obsoleted?
    The long version of the same question is:
    I am converting my C++ code from the Oracle 7.3 OCI driver to the Oracle8 OCI driver. One thing I did very frequently in Oracle 7.3 OCI code is open a multi-row select cursor within a stored procedure and return that cursor to my program. In the program, I would then do the fetching with the returned cursor. This was very useful, as it allows me to change the queries in the stored procedure (for example, to append information to certain columns or make some data in all uppercase) without recompiling the application due to a changed SQL string.
    My 7.3 psuedocode is as follows:
    stored procedure def:
    TYPE refCurTyp IS REF CURSOR;
    FUNCTION LoadEmployeeData RETURN refCurTyp;
    stored procedure body:
    FUNCTION LoadEmployeeData RETURN refCurTyp IS
    aCur refCurTyp;
    BEGIN
    OPEN aCur FOR
    SELECT emp_id, emp_name
    FROM employee_table
    ORDER BY emp_name;
    return aCur;
    END;
    OCI code: // all functions are simplified, not actual parameter listing
    // declare main cursor variable #1 and return cursor variable #2
    Cda_Def m_CDAstmt, m_CDAfunction;
    // open both cursors
    oopen(m_CDAstmt, ...);
    oopen(m_CDAfunction, ...);
    // bind cursor variable to cursor #2
    oparse(&m_CDAstmt, "BEGIN :CUR := MYPACKAGE.LoadEmployeeData; END;");
    obindps(&m_CDAstmt, SQLT_CUR, ":CUR", &m_CDAfunction);
    // run cursor #1
    oexn(&m_CDAstmt);
    // bind variables from cursor #2, and fetch
    odefineps(&m_CDAfunction, 1, SQLT_INT, &m_iEmpId);
    odefineps(&m_CDAfunction, 2, SQLT_CHAR, &m_pEmpName);
    while (!ofen(&m_CDAfunction))
    // loop: do something with fetch
    // values placed in m_iEmpID and m_pEmpName
    This works perfectly, and has really helped to make my code more maintainable. Problem is, in Oracle 8 OCI both cursors and the cursor functions (such as oopen()) are becoming obsoleted. Now it uses statement and environment handles. I know I can still use Cda_Def and cursors--for a while--within OCI8, but I need to know the official up-to-date method of returning a cursor from the database and fetching within my C++ code. Any code fragment, or explanation of what I need to do in OCI8 would be appreciated (perhaps I need to bind to a statement handle instead? But the stored procedure still returns a cursor.)
    The Oracle8 OCI has a new SQLT_ type, SQLT_RSET, which the header file defines as "result set type". Unfortunately, it's almost completely undocumented in the official documentation. Am I supposed to use this instead of the obsolete SQLT_CUR?
    Thanks,
    Glen Mazza

    Email me diorectly and I will get you some code that might help. I fail to see the relevance of posting this type of information in the JDeveloper forum.

Maybe you are looking for

  • After iTunes upgrade, iTunes not playing music in Windows 8.

    I just upgraded to the latest version of iTunes (ver. 1.1.2.31) on Windows 8.1. The prior version of iTunes worked fine, but after this upgrade, it won't play music. No error message, and it will play music videos. It says it's playing, and I can cli

  • Can't drag songs in iTunes DJ

    Initially discovered as I tried to rearrange songs within iTunes DJ, but with further attempts it seems I can't drag songs at all; within playlists, into playlists, nothing. No dragging.

  • Import .swf not working

    I need to convert some swf files to .flv.  I know there are converters out there that do this, but I don't currently have any so if I can do it with PremE 8 I'd like to.  I read that .swf can be imported into Premiere, but when I import these particu

  • Want to know about user, tcode,start of tcode time

    hi, I want to know who did it, which TCode and when time of excute of the particular transcation run by user. Do sap as any report or TCode which will give me the details of who(user),when(start time),which ( TCode) the user excuted the TCode, And wh

  • Apple TV no trailers no tv shows?

    Updated iTunes to 7.3.2, turned on the Apple TV for the first time in days. iTunes music is wonderful, iPhoto is amazing, but Trailers just spin with loading. No response, and TV shows is the same. Its as if there were no internet... Any ideas? Apple