How to return a table to ref cursor?

My client has created a package stored procedure that takes in 2 parameters of VarChar2 and an out parameter which is a table
Following is the package header
CREATE OR REPLACE PACKAGE "PKG_TRAVEL_NEW_SUND" IS
---RECORD TYPE DELARATION
TYPE DIRECT_ALT_REC IS RECORD (SERVICE_NO CBG_DISTANCE_FARE.SERVICE_NO%TYPE,
DISTANCE CBG_DISTANCE_FARE.DISTANCE%TYPE,
CASH_FARE_AC CBG_DISTANCE_FARE.CASH_FARE_AC%TYPE,
CASH_FARE_NON_AC CBG_DISTANCE_FARE.CASH_FARE_NON_AC%TYPE,
CARD_FARE_AC CBG_DISTANCE_FARE.CARD_FARE_AC%TYPE,
CARD_FARE_NON_AC CBG_DISTANCE_FARE.CARD_FARE_NON_AC%TYPE,
EZLINK_FARE_AC CBG_DISTANCE_FARE.EZLINK_FARE_AC%TYPE,
EZLINK_FARE_NON_AC CBG_DISTANCE_FARE.EZLINK_FARE_NON_AC%TYPE,
AVG_RUNTIME CBG_DISTANCE_FARE.AVG_RUNTIME%TYPE,
ALTERNATIVE_NO CBG_DIRECT_ALT.ALTERNATIVE_NO%TYPE,
MAX_FREQ_AM CBG_SVC.MAX_FREQ_AM%TYPE,
MIN_FREQ_AM CBG_SVC.MIN_FREQ_AM%TYPE,
ADVANTAGE_CODE CBG_DIRECT_ALT.ADVANTAGE_CODE%TYPE,
DIST_FARE_CODE_1 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
DIST_FARE_CODE_2 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
DIST_FARE_CODE_3 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
FROM_STOP_CODE CBG_DISTANCE_FARE.FROM_STOP_CODE%TYPE,
TO_STOP_CODE CBG_DISTANCE_FARE.TO_STOP_CODE%TYPE,
MIN_TIME CBG_DIRECT_ALT.MIN_TIME%TYPE,
MIN_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
                                        ACT_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
TRAVEL_TYPE VARCHAR2(4),
TRANSFER_INFO VARCHAR2(1),
END_TRANSFER_INFO VARCHAR2(1));
--TABLE  TYPE DECLARATION
TYPE BUS_INFO_TAB IS TABLE OF DIRECT_ALT_REC INDEX BY BINARY_INTEGER;
-- CURSOR TYPE DECLARATION
TYPE TEMP_REC_STRUCT1 IS RECORD (
RECORD_POSITION BINARY_INTEGER,
DIST_FARE_CODE1 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
DIST_FARE_CODE2 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
DIST_FARE_CODE3 CBG_DISTANCE_FARE.DIST_FARE_CODE%TYPE,
ADVANTAGE_CODE CBG_DIRECT_ALT.ADVANTAGE_CODE%TYPE,
MINIMUM_FARE CBG_DIRECT_ALT.MIN_FARE%TYPE,
MINIMUM_TIME CBG_DIRECT_ALT.MIN_TIME%TYPE,
TRAVEL_TYPE VARCHAR2(4) );
TYPE TEMP_TAB_STRUCT1 IS TABLE OF TEMP_REC_STRUCT1 INDEX BY BINARY_INTEGER;
TEMP_TABLE1 BUS_INFO_TAB;
G_RESULTSET_INDEX BINARY_INTEGER := 0 ;
G_TOT_RECS_IN_TAB1 BINARY_INTEGER := 0 ;
TYPE BUS_INFO_CUR IS REF CURSOR RETURN DIRECT_ALT_REC;
---PROCEDURE INSIDE THE PACKAGE
--- PROCEDURE TO SELECT THE RECORDS
PROCEDURE SEL_DIRECT_ALT(P_FROM_STOP_CODE IN VARCHAR2,
P_TO_STOP_CODE IN VARCHAR2,
RESULTSET IN OUT BUS_INFO_TAB);
I'm using ODP.net and here is my code
string storedprocedure = "PKG_TRAVEL_NEW_SUND.SEL_DIRECT_ALT";
//PKG_TRAVEL_NEW_SUND
//CBG003_XP_SP_TEST1
ArrayList retlist = new ArrayList();
OracleConnection curr_conn = this.GetOpenConnection();
OracleCommand cmd = curr_conn.CreateCommand();
cmd = new OracleCommand(storedprocedure, curr_conn);
cmd.CommandType = CommandType.StoredProcedure;
// input parameter
OracleParameter param1 = new OracleParameter();
OracleParameter param2 = new OracleParameter();
param1.ParameterName = "start_code";
param2.ParameterName = "end_code";
param1.OracleDbType = OracleDbType.Varchar2;
param2.OracleDbType = OracleDbType.Varchar2;
param1.Direction = ParameterDirection.Input;
param2.Direction = ParameterDirection.Input;
param1.Size = 5;
param2.Size = 5;
param1.Value = start_codes;
param2.Value = end_codes;     
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
OracleParameter outputparam3 = new OracleParameter();
outputparam3.Direction = ParameterDirection.InputOutput;
outputparam3.ParameterName = "output";
outputparam3.OracleDbType = OracleDbType.RefCursor;
// output type
cmd.Parameters.Add(outputparam3);
cmd.ExecuteNonQuery();
At this point, when i execute Query, i get the message telling me that i could have the wrong number or type arguments for the procedure.
I've looked thru countless examples saying i should use a RefCursor, but what else could i miss out?

Hi,
This is from Metalink NOTE.219191.1 How to return the values in a PL/SQL table to a ref cursor
Hope it helps,
Greg
This document gives details with an example on how to pass the values
in a PL/SQL table to a ref cursor.
SCOPE & APPLICATION
This document is useful for developers who are familiar with SQL & PL/SQL
How to return the values in a PL/SQL table to a ref cursor
This can be done by using a SQL Object type instead of a PL/SQL table.
Here is an example.
SQL> create or replace type ObjectType as object
2 ( x int,
3 y date,
4 z varchar2(25)
5 );
6 /
Type created.
SQL> create or replace type TabType as table of ObjectType;
2 /
Type created.
SQL> create or replace
2 function demo_function( p_start_row in number,
3 p_end_row in number )
4 return TabType
5 as
6 l_data TabType := TabType();
7 l_cnt number default 0;
8 begin
9 for x in ( select * from emp order by sal desc )
10 loop
11 l_cnt := l_cnt + 1;
12 if ( l_cnt >= p_start_row )
13 then
14 l_data.extend;
15 l_data(l_data.count) :=
16 objectType( x.empno,
17 x.hiredate,
18 x.ename );
19 end if;
20 exit when l_cnt = p_end_row;
21 end loop;
22
23 return l_data;
24 end;
25 /
Function created.
SQL> select *
2 from the ( select cast( demo_function(3,7) as TabType )
3 from dual ) a;
X Y Z
7902 03-DEC-81 FORD
7566 02-APR-81 JONES
7698 01-MAY-81 BLAKE
7782 09-JUN-81 CLARK
7844 08-SEP-81 TURNER
By using a SQL object type, the table can be selected easily.
SQL> create or replace package demo_pkg
2 as
3 type rc is ref cursor;
4
5 procedure p( p_cursor in out rc );
6 end;
7 /
Package created.
SQL> create or replace package body demo_pkg
2 as
3
4 procedure p( P_cursor in out rc )
5 is
6 l_data TabType := TabType();
7 begin
8 for i in 1 .. 3 loop
9 l_data.extend;
10 l_data(i) :=
11 ObjectType( i, sysdate+i, i || ' data');
12 end loop;
13
14 open p_cursor for
15 select *
16 from TABLE ( cast ( l_data as TabType) );
17 end;
18
19 end;
20 /
Package body created.
SQL> set autoprint on
SQL> variable x refcursor
SQL> exec demo_pkg.p(:x)
PL/SQL procedure successfully completed.
X Y Z
1 15-NOV-02 1 data
2 16-NOV-02 2 data
3 17-NOV-02 3 data

Similar Messages

  • How to type cast PL/SQL table to REF cursor?

    any one knows how to CAST PL/SQl table to Ref cursor?
    eg
    procedure some_name(r_out out sys_refcurosr)
    IS
    type t is table of tab%ROWTYPE;
    my_type t;
    begin
    select * bulk collect into my_type from tab;
    r_out := my_type; -- need help here..
    end;
    it's 10g

    ref cursor is pointer to result set. You can not cast to PL/SQL table.
    1 create or replace procedure some_name(r_out out sys_refcursor)
    2 IS
    3 begin
    4 OPEN r_out for select * from emp;
    5* end;
    SQL> /
    Procedure created.
    SQL> var mycursor refcursor;
    SQL> exec some_name(:mycursor);
    PL/SQL procedure successfully completed.
    SQL> set linesize 2000
    SQL> print :mycursor;
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7369 SMITH CLERK 7902 12/17/80 00:00:00 800 20
    7499 ALLEN SALESMAN 7698 02/20/81 00:00:00 1600 300 30
    7521 WARD SALESMAN 7698 02/22/81 00:00:00 1250 500 30
    7566 JONES MANAGER 7839 04/02/81 00:00:00 2975 20
    7654 MARTIN SALESMAN 7698 09/28/81 00:00:00 1250 1400 30
    7698 BLAKE MANAGER 7839 05/01/81 00:00:00 2850 30
    7782 CLARK MANAGER 7839 06/09/81 00:00:00 2450 10
    7788 SCOTT ANALYST 7566 04/19/87 00:00:00 3000 20
    7839 KING PRESIDENT 11/17/81 00:00:00 5000 10
    7844 TURNER SALESMAN 7698 09/08/81 00:00:00 1500 0 30
    7876 ADAMS CLERK 7788 05/23/87 00:00:00 1100 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7900 JAMES CLERK 7698 12/03/81 00:00:00 950 30
    7902 FORD ANALYST 7566 12/03/81 00:00:00 3000 20
    7934 MILLER CLERK 7782 01/23/82 00:00:00 1300 10
    14 rows selected.

  • How to create table from ref cursor

    I have a proc that returns a ref cursor, whats the simplest way to create a table based on the return of the ref cursor?
    declare
    type rc is ref cursor;
    p_data rc;
    begin
    call_my_proc(p_data);
    :result := p_data; -- If I run this in TOAD I can see the data here but I want to create a table based on it rather than outputting it)
    end;
    thanks.
    edit: sorry. typed this wrong first time, should be right now

    961469 wrote:
    I have a proc that returns a ref cursor, whats the simplest way to create a table based on the return of the ref cursor?Not to do it...
    A cursor is not a result set. A cursor is not a result set. Worth repeating several times as this is a common misconception
    A cursor is essentially a program. Executable code that was compiled from a SQL source code program.
    A SELECT cursor is "read" program. Each fetch instruction runs this program (from its current "paused state"), and outputs data.
    An INSERT cursor is a "write" program. You pass data to it (process called binding, via bind variables). You then execute the program. It writes the data it received (can be bulk data via a bulk bind) to table.
    Now your question is: How do I write the output of a cursor program back to the database?
    The answer is that a "write" cursor program is needed. Your code needs to execute (fetch output from) the ref (read/select) cursor. Then bind that data to the "write" cursor and execute it.
    In other words, you have a read cursor and a write cursor, and you need to pass data from one to the other.
    HOWEVER.. This is slow. This does not scale. This is also known as slow-by-slow row by row processing.
    The correct approach is to create a single program. One that reads the data, and then writes the data. No to send data via a detour through your code between the read part and write part.
    The cursor to create is an INSERT..SELECT cursor. This can do fast direct path inserts. This can be executed in parallel - i.e. the database executing several copies of this read-and-write program at the same time.

  • 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;
    }

  • How to get rowtype of a ref cursor?

    Hello again,
    I need your help once more.
    I have a function in a package which returns a SYS_REFCURSOR. Now I am trying to open that cursor from the application (currently sql_developer) to show the data. For starting I have a simple query in the statement: select * from emp;
    Later it will be a complex query which returns results of multiple joined tables.
    I have the following package:
    >
    CREATE OR REPLACE
    PACKAGE P_TEST_ASP AS
    FUNCTION test_asp_1 (dti_id in NUMBER)
    RETURN SYS_REFCURSOR;
    END P_TEST_ASP;
    >
    And here comes the package body:
    >
    CREATE OR REPLACE
    PACKAGE BODY P_TEST_ASP AS
    FUNCTION test_asp_1 (dti_id in NUMBER)
    RETURN SYS_REFCURSOR AS
    resultCursor SYS_REFCURSOR;
    BEGIN
    OPEN resultCursor FOR select * from emp;
    RETURN resultCursor;
    END test_asp_1;
    END P_TEST_ASP;
    >
    Now my Problem is that I do not know how to get the cursor's rowtype to assign it to the collection:
    I Managed to access the cursor when I set the rowtype of my collection res to emp%rowtype.
    >
    set serveroutput on
    DECLARE
    type        testtype is TABLE OF emp%rowtype;
    myCursor SYS_REFCURSOR;
    res testtype;
    BEGIN
    -- Get ref cursor from function
    myCursor := p_test_asp.test_asp_1(9);
    FETCH myCursor BULK COLLECT into res;
    dbms_output.put_line('Value from cursor:' );
    CLOSE myCursor;
    END;
    >
    But that will not work with the final statement.
    I would like to set the rowtype to myCursor%rowtype -> But I don't know how to do it:
    >
    set serveroutput on
    DECLARE
    type        testtype is TABLE OF myCursor%rowtype;
    myCursor SYS_REFCURSOR;
    res testtype;
    BEGIN
    -- Get ref cursor from function
    myCursor := p_test_asp.test_asp_1(9);
    FETCH myCursor BULK COLLECT into res;
    dbms_output.put_line('Value from cursor:' );
    CLOSE myCursor;
    END;
    >
    this statement throws the following errors:
    Fehlerbericht:
    ORA-06550: line 2, column 36:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 2, column 3:
    PL/SQL: Item ignored
    ORA-06550: line 11, column 36:
    PLS-00597: expression 'RES' in the INTO list is of wrong type
    ORA-06550: line 11, column 3:
    PL/SQL: SQL Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    Edited by: Andreas S. on 13.12.2011 04:56

    Why do you want to use a collection? I dont see any need for that.
    Lets say your client is SQL Plus. SQL Plus provides a API called PRINT that prints the cursor. You can use that.
    SQL> var rc refcursor
    SQL>
    SQL> exec open :rc for select level from dual connect by level <= 10;
    PL/SQL procedure successfully completed.
    SQL> print rc
         LEVEL
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL>Like wise whatever is your client use the correct API that offers to handle cursors.

  • How to get values from a ref cursor in a procedure

    I have a procedure that returns a cursor type of values, but I cannot get the values.
    I got error when on how to define the output cursor. Could someone please look at the code and tell me how to correct it?
    Thanks in advance.
    ******************************8
    --This is the package
    CREATE OR REPLACE PACKAGE Test_SECURITY2 as
    type T_RoleTest is ref cursor;
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest);
    end;
    CREATE OR REPLACE PACKAGE BODY Test_SECURITY2 as
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest) as
    begin
         open p_cur for
         select PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
    end;
    end;
    --This is the testing code. I got error here
    SQL> set serveroutput on;
    SQL> execute dbms_output.enable;
    PL/SQL procedure successfully completed.
    SQL> declare
    2 type T_RoleTest is ref cursor;
    3 V_UserRole is ref cursor; --how to define the output cursor
    4 v_userId number := 42;
    5 V_Role_Id number;
    6 v_Role_name varchar2(20);
    7 begin
    8 Test_SECURITY2.P_GetUserRole(v_userId, V_UserRole);
    9
    10 open V_UserRole;
    11 loop
    12 fetch V_UserRole into V_Role_Id, v_Role_name;
    13
    14 EXIT WHEN V_UserRole%NOTFOUND;
    15 dbms_output.put_line('RoleID'||v_Role_ID);
    16 dbms_output.put_line('Rolename'||v_Role_name);
    17
    18 end loop;
    19
    20 end;
    21 /
    V_UserRole is ref cursor;
    ERROR at line 3:
    ORA-06550: line 3, column 13:
    PLS-00103: Encountered the symbol "IS" when expecting one of the following:
    constant exception <an identifier>

    declare
      type T_RoleTest is ref cursor;
      v_UserRole T_RoleTest;or just:
    declare
      v_UserRole  Test_Security2.T_RoleTest;And, if you are on 9i or later, you can just use the built-in sys_refcursor type.

  • Using plsql table and ref cursor in oracle forms 10g

    Hi all,
    Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.
    And in that procedure i have created a pl/sql table and a ref cursor in data base level.
    CREATE OR REPLACE PACKAGE SCOTT.BONUS_PKG IS TYPE bonus_rec
    IS RECORD(
    empno     bonus_EMP.empno%TYPE,
    ename     bonus_EMP.ename%TYPE,
    job     bonus_EMP.job%TYPE,
    sal     bonus_EMP.sal%TYPE,
    comm     bonus_EMP.comm%TYPE);
    TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
    TYPE bontab IS TABLE OF bonus_rec INDEX BY BINARY_INTEGER;
    PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor);
    PROCEDURE bonus_query(bonus_data IN OUT bontab);
    END bonus_pkg;
    CREATE OR REPLACE PACKAGE BODY SCOTT.BONUS_PKG IS
    PROCEDURE bonus_query(bonus_data IN OUT bontab) IS
    ii NUMBER;
    CURSOR bonselect IS
    SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
    BEGIN
    OPEN bonselect;
    ii := 1;
    LOOP
    FETCH bonselect INTO
    bonus_data( ii ).empno,
    bonus_data( ii ).ename,
    bonus_data( ii ).job,
    bonus_data( ii ).sal,
    bonus_data( ii ).comm;
    EXIT WHEN bonselect%NOTFOUND;
    ii := ii + 1;
    END LOOP;
    END bonus_query;
    PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor) IS
    BEGIN
    OPEN bonus_data FOR SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
    END bonus_refcur;
    END bonus_pkg;
    i want to populate the data in forms manually not using forms data block wizard and programmatically.
    please reply...

    Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.Typically, you would use a procedure based block when you have a collection of data from multiple tables presented in a Form and your user needs to be able to update the information displayed.
    From your code example, it looks like you are using Oracle Support document "Basing a Block on a Stored Procedure - Sample Code [ID 66887.1]". If this is the case, keep following the document - it walks you through all of the steps. There is no need to Manually configure things that the Data Block Wizard will perform for you!
    i want to populate the data in forms manually not using forms data block wizard and programmatically. Why? Let the Data Block Wizard take care of configuring your block based on a procedure for you. There is no need to manually loop through the data! I've actually done what you are attempting and it was more work than was needed. Let Forms do the work for you. :)
    If you absolutely must do things manually, I recommend you use the PROCEDURE bonus_query(bonus_data IN OUT bontab) instead of the bonus_refcur(bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB and then call the bonus_query procedure. Then it is a simple case of looping through the table of records returned by the bonus_query procedure. For example:
    DECLARE
       t_bonus    bonus_pkb.bontab;
    BEGIN
       bonus_pkg.bonus_query(t_bonus);
       FOR i in 1 .. t_bonus.count LOOP
          :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
          :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
          :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
          :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
          :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
       END LOOP;
    END;This code sample demonstrates the basics, but as it is sample code - you will have to adapt it to your situation.
    Also, I strongly recommend you look at the article InoL listed. This is a very comprehensive discussion on REF CURSORs. If you are set on using a procedure based data source - it is more efficient to pass the table of records back to your form than it is to pass a ref cursor. Using a ref cursor, you might as well just using a standard named cursor and loop through your named cursor. The effect is the same (one row returned at a time creating lots of network traffic). Using the table of records is more efficient because the entire data set is returned so network traffic is reduced.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to convert the varray to ref cursor

    Hi,
    Is there any way to convert varray to ref cursor....
    i dont want to use any table or record as an ref cursor..
    i just want to create a procedure which returns a ref cursor..
    below is the sample procedure for it..
    create or replace procedure FETCH_DATA1
    tab_name in varchar2,
    p_recordset1 OUT fetch_data_pak.ref_cursor
    AS
    type v_array1 is varray(1000) of t_transaction%rowtype;
    v_array2 v_array1;
    cursor s1 is select * from t_transaction where lastupdate_date > '08-Aug-09';
    begin
    open s1;
    fetch s1 bulk collect into v_array2 limit 100;
    close s1;
    select * from table(cast (v_array2 as p_recordset1));
    end FETCH_DATA1;
    I need to convert the varray to ref cursor.....

    Why put it into a varray at all?
    You can just open the ref cursor for that select you are desiring.
    And if you need to limit it to returning just the first 100 (as your code seems to imply), wrap it and filter on rownum.
    Something similar to this:
    create or replace procedure FETCH_DATA1
      tab_name in varchar2,
      p_recordset1 OUT fetch_data_pak.ref_cursor
    AS
    begin
      open p_recordset1 for
      select /*+ first_rows(100) */ * from (
        select * from t_transaction
        where lastupdate_date > to_date('08-08-2009','DD-MM-YYYY')
        --order by something
      where rownum <= 100;
    end FETCH_DATA1;And note, that you really should have an order by when you wish to limit yourself to "first 100 rows" - otherwise it will be "random 100 rows".
    That goes for your cursor solution as well...
    Edited by: Kim Berg Hansen on Nov 28, 2011 10:25 AM
    Added explicit date conversion - it is bad practice not to explicitly convert dates ;-)

  • Stored procedure: how to return multline table

    Environment: SQL Server 2008 R2, Windows
    Tools: MSMS 2008 R2
    Code:
    CREATE PROCEDURE [dbo].[Cleanup]
    (@id CHAR(12)
    ,@Date DATETIME
    ,@ID int OUT
    ,@Ln_ID CHAR(10) OUT
    ,@qcdate DATETIME OUT
    ,@P4 VARCHAR(8000)OUT
    ,@P9 VARCHAR(8000) OUT
    ,@P11 VARCHAR(8000) OUT
    ) WITH ENCRYPTION
    AS
    BEGIN
    Update Table_mocha
    SET P4=Replace(PE4,RTRIM(Cast(Q_ID as varchar(10))), '')
    where id=@id and order_dt=@Date
    Update Table_mocha
    SET P4 = NullIf(P4,'')
    where id=@id and order_dt=@Date
    Update Table_mocha
    SET P4=LTRIM(RTRIM(P4))
    where id=@id and order_dt=@Date
    SELECT @id=id, ln_id=@ln_id,@p4=p4, @p9=P9,@p11=P11
    where id=@id and order_dt=@Date
    Problem: having three updates would cause the database to lock. How would I pass input paramaters for those three updates in SP. How would I update multiple tables, how to avoid database lock, how to return multi-statment table - value (display
    table contains multiple records)

    I prefer to use different stored procedures to do different things.
    CREATE PROCEDURE [dbo].usp_updatedata
    (@id CHAR(12)
    ,@Date DATETIME
    AS
    BEGIN
    Update Table_mocha
    SET P4=LTRIM(RTRIM(Nullif(Replace(PE4,RTRIM(Cast(Q_ID as varchar(10))), ''),'')))
    where id=@id and order_dt=@Date
    End
    CREATE PROCEDURE [dbo].usp_getData
    (@id CHAR(12)
    ,@Date DATETIME
    AS
    BEGIN
    SET NOCOUNT ON;
    SELECT id, ln_id,p4, P9,P11
    where id=@id and order_dt=@Date
    End

  • How to use BULK COLLECT in ref cursor?

    hi,
    can we use bulk collect in ref cursor ? if yes then please give small example ..
    thanks

    Try this:
    create or replace type person_ot as object (name varchar2(10)) not final;
    create or replace type student_ot under person_ot (s_num number) not final;
    create type person_tt as table of person_ot;
    create table persons of person_ot;
    declare
    lv_person_list person_tt;
    lv_sql varchar2(1000);
    ref_cur sys_refcursor;
    begin
    lv_sql:= 'select new student_ot(''fred'', 100) from dual
    union all
    select new student_ot(''sally'', 200) from dual';
    open ref_cur for lv_sql;
    fetch ref_cur bulk collect into lv_person_list;
    close ref_cur;
    for i in lv_person_list.first..lv_person_list.last loop
    dbms_output.put_line(lv_person_list(i).name );
    end loop;
    forall i in lv_person_list.first..lv_person_list.last
    insert into persons values lv_person_list(i);
    end;
    /

  • Question in invoking a bpel process from adf (how to return a table)

    hi all,
    i have developed a bpel process that checks customer name and if the customer name is valid , it will go to query a table of product and send this data to the client (jsf)
    In my bpel process ,there are two services
    1. Getcustomer service--> this service is developed by java web services that checks if the customername ='john' and it will return true and then query the product deta
    2. Product serverice--> this service is developed using entity ejb class first and then created sesssion bean , exposing this seesion bean as a ejb web serive that can query a product table in the database.
    In the syschronous process
    1. receive input (customer name)
    2. assigncustomer
    3. invoke_customer-->if =john----> Getcustomer service
    4. switch---->if true--->
    5. invoke_product ---> product service that can return a table of product detail
    6. assignproductdetail
    7. replyoutput to the client ( i could see the result of the detail of product on the bpel control , it seemed fine)
    i could deploy this bpel process sucessfully without errors and i copied the wsdl of this bpel process
    8. i created an adf application and put this wsdl link into the web service control that i created so that i could see the data control
    However,
    Under the data control tab......
    product------>(data control)
    process(string)...operation
    parameters
    ----input
    <----String (result)
    the question is did i create the wrong bpel process because the result that return is String why when the bpel process is mapped into data control it looked like this.
    why i can not see any collection of product or any parameter of product could anyone give me some advices???
    Therefore when i developed jsf page i fill the input value customer name -- and it returned nothing......please help i would highly appreicated.
    datacontrol.xml file
    <?xml version="1.0" encoding="UTF-8" ?>
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
    version="10.1.3.39.84" id="untitled1PageDef"
    Package="oracle.view.pageDefs">
    <parameters/>
    <executables>
    <variableIterator id="variables">
    <variable Type="java.lang.String" Name="process_input"
    IsQueriable="false"/>
    <variable Type="java.lang.String" Name="process_Return"
    IsQueriable="false" IsUpdateable="0"
    DefaultValue="${bindings.process.result}"/>
    </variableIterator>
    </executables>
    <bindings>
    <methodAction id="process" MethodName="process" RequiresUpdateModel="true"
    Action="999" IsViewObjectMethod="false"
    DataControl="product_customer" InstanceName="product_customer"
    ReturnName="product_customer.methodResults.product_customer_process_result">
    <NamedData NDName="input" NDType="java.lang.String"
    NDValue="${bindings.process_input}"/>
    </methodAction>
    <attributeValues id="input" IterBinding="variables">
    <AttrNames>
    <Item Value="process_input"/>
    </AttrNames>
    </attributeValues>
    <attributeValues id="process1" IterBinding="variables">
    <AttrNames>
    <Item Value="process_Return"/>
    </AttrNames>
    </attributeValues>
    </bindings>
    </pageDefinition>
    <?xml version="1.0" encoding="UTF-8" ?>
    <JavaBean xmlns="http://xmlns.oracle.com/adfm/beanmodel" version="10.1.3.39.84"
    id="product_customer" BeanClass="product_customer"
    isJavaBased="false">
    <MethodAccessor IsCollection="false" Type="java.lang.String" id="process"
    ReturnNodeName="Return">
    <ParameterInfo id="input" Type="java.lang.String" isStructured="false"/>
    </MethodAccessor>
    </JavaBean>

    hi, i just can not post the long information...test
    ProductSession.wsdl
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://oracle/" name="ProductSessionWebServiceService" targetNamespace="http://oracle/">
    <types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://oracle/" elementFormDefault="qualified">
    <complexType name="Product">
    <sequence>
    <element name="brand" type="string" nillable="true"/>
    <element name="price" type="float" nillable="true"/>
    <element name="description" type="string" nillable="true"/>
    <element name="category" type="string" nillable="true"/>
    <element name="name" type="string" nillable="true"/>
    <element name="prodid" type="long" nillable="true"/>
    </sequence>
    </complexType>
    <element name="mergeEntity" type="tns:mergeEntity"/>
    <complexType name="mergeEntity">
    <sequence>
    <element name="Object_1" type="anyType" nillable="true"/>
    </sequence>
    </complexType>
    <element name="mergeEntityResponse" type="tns:mergeEntityResponse"/>
    <complexType name="mergeEntityResponse">
    <sequence>
    <element name="return" type="anyType" nillable="true"/>
    </sequence>
    </complexType>
    <element name="persistEntity" type="tns:persistEntity"/>
    <complexType name="persistEntity">
    <sequence>
    <element name="Object_1" type="anyType" nillable="true"/>
    </sequence>
    </complexType>
    <element name="persistEntityResponse" type="tns:persistEntityResponse"/>
    <complexType name="persistEntityResponse">
    <sequence>
    <element name="return" type="anyType" nillable="true"/>
    </sequence>
    </complexType>
    <element name="queryProductFindAll" type="tns:queryProductFindAll"/>
    <complexType name="queryProductFindAll">
    <sequence/>
    </complexType>
    <element name="queryProductFindAllResponse" type="tns:queryProductFindAllResponse"/>
    <complexType name="queryProductFindAllResponse">
    <sequence>
    <element name="return" type="tns:ListOfProduct" nillable="true"/>
    </sequence>
    </complexType>
    <complexType name="ListOfProduct">
    <sequence>
    <element name="item" type="tns:Product" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    <element name="removeProduct" type="tns:removeProduct"/>
    <complexType name="removeProduct">
    <sequence>
    <element name="Product_1" type="tns:Product" nillable="true"/>
    </sequence>
    </complexType>
    <element name="removeProductResponse" type="tns:removeProductResponse"/>
    <complexType name="removeProductResponse">
    <sequence/>
    </complexType>
    </schema>
    </types>
    <message name="ProductSessionWebService_mergeEntity">
    <part name="parameters" element="tns:mergeEntity"/>
    </message>
    <message name="ProductSessionWebService_mergeEntityResponse">
    <part name="parameters" element="tns:mergeEntityResponse"/>
    </message>
    <message name="ProductSessionWebService_persistEntity">
    <part name="parameters" element="tns:persistEntity"/>
    </message>
    <message name="ProductSessionWebService_persistEntityResponse">
    <part name="parameters" element="tns:persistEntityResponse"/>
    </message>
    <message name="ProductSessionWebService_queryProductFindAll">
    <part name="parameters" element="tns:queryProductFindAll"/>
    </message>
    <message name="ProductSessionWebService_queryProductFindAllResponse">
    <part name="parameters" element="tns:queryProductFindAllResponse"/>
    </message>
    <message name="ProductSessionWebService_removeProduct">
    <part name="parameters" element="tns:removeProduct"/>
    </message>
    <message name="ProductSessionWebService_removeProductResponse">
    <part name="parameters" element="tns:removeProductResponse"/>
    </message>
    <portType name="ProductSessionWebService">
    <operation name="mergeEntity">
    <input message="tns:ProductSessionWebService_mergeEntity"/>
    <output message="tns:ProductSessionWebService_mergeEntityResponse"/>
    </operation>
    <operation name="persistEntity">
    <input message="tns:ProductSessionWebService_persistEntity"/>
    <output message="tns:ProductSessionWebService_persistEntityResponse"/>
    </operation>
    <operation name="queryProductFindAll">
    <input message="tns:ProductSessionWebService_queryProductFindAll"/>
    <output message="tns:ProductSessionWebService_queryProductFindAllResponse"/>
    </operation>
    <operation name="removeProduct">
    <input message="tns:ProductSessionWebService_removeProduct"/>
    <output message="tns:ProductSessionWebService_removeProductResponse"/>
    </operation>
    </portType>
    <binding name="ProductSessionWebServiceSoapHttp" type="tns:ProductSessionWebService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="mergeEntity">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    <operation name="persistEntity">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    <operation name="queryProductFindAll">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    <operation name="removeProduct">
    <soap:operation soapAction=""/>
    <input>
    <soap:body use="literal"/>
    </input>
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    </binding>
    <service name="ProductSessionWebServiceService">
    <port name="ProductSession" binding="tns:ProductSessionWebServiceSoapHttp">
    <soap:address location="http://home-f045512354:8888/testproduct/ProductSession"/>
    </port>
    </service>
    </definitions>

  • How to return a table from function

    Hi,
    I want to return a table from the function. But i'm unable to do it.
    can any one give me a peice of code.
    Thanks in advance.
    Regards,
    Alok

    Are you referring to a pipelined table function?
    Here is an example of such a function returning a "hailstone" sequence.. a number range that always end in 4,2,1. (see the [url http://en.wikipedia.org/wiki/Collatz_conjecture]Collatz Conjecture for more details on the maths used).
    SQL> create or replace type TNumbers is table of number;
    2 /
    Type created.
    SQL>
    SQL> create or replace function hailstone( nValue number ) return TNumbers pipelined is
    2 n number;
    3 begin
    4 n := nValue;
    5 loop
    6 PIPE ROW( n );
    7 exit when n = 1;
    8
    9 if MOD(n,2) != 0 then
    10 n := (n * 3) + 1;
    11 else
    12 n := n / 2;
    13
    14 end if;
    15 end loop;
    16 end;
    17 /
    Function created.
    SQL> show errors
    No errors.
    SQL>
    SQL>
    SQL> select * from TABLE( hailstone(10) );
    COLUMN_VALUE
    10
    5
    16
    8
    4
    2
    1
    7 rows selected.
    SQL> select * from TABLE( hailstone(1923413) );
    ..etc.

  • How to insert a table with ref statement?

    the script:
    CREATE OR REPLACE TYPE B_T AS OBJECT (
    type varchar(6),
    value number(2));
    create table Bo of B_T;
    insert into Bo values('a',0);
    insert into Bo values('b',1);
    create or replace type try_T AS OBJECT(
    iii number(10),
    aaa ref B_T);
    create table try of try_T
    (scope for (aaa) is Bo);
    how to insert into the "try" table?
    the statement:
    insert into try values(4,B_T('a'))
    or :
    insert into try values(4, ref(t) from bo t where bo.type='a');
    both are erro.
    help me please.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • How to join two tables in a cursor

    i have a cursor that selects data from one table,
    i want it to select data from one other table also.. how i can do that.. is there any alternate way to do that if yes then suggest .. waiting for ur reply....

    employee_number" and other has column name as "comp_employee_number" .. Well that would be quite simple ....
    SELECT e1.foo, e2.bar 
    FROM   employees e1, staff_members e2
    WHERE e1.employee_number = e2.comp_employee_number;.... unless what you're really expecting is for the datbase to somehow figure out by itself that although those columns have different names they actually represent the same data and magically derive the join for you.
    Perhaps, you really need to explain in more detail precisely what your problem is.
    Cheers, APC

  • Web Service and CAF Application Services - How to return a table

    Hello,
    I'd like to build a CAF Application Service and expose it as a Web Service. This service should return an array or table which I'd like to display in a Visual Composer model.
    I understand that there're limitations at CAF regarding supported data types.
    Does anyone know how to get a workaround?
    Any information is very appreciated.
    Kind regards
    Stefan

    Hi,
    You can return a list.
    The standard way to do this is you have to create a complex data type for response.
    Configure the cardinality of this data type to 1..n so as to accomodate a list.
    In your implementation add your list to this response message and return the list.
    This waly you can return collections.
    Hope it helps.
    Regards,
    Srinivasan Subbiah

Maybe you are looking for