Call a procedure that returns a refcursor, use it in another proc's sql?

I have a procedure that returns a refcursor; how can I include that refcursor in a sql statement that's in another procedure, or view etc?
This is the kind of foolery I've tried so far (myproc1 returns a ref cursor):
create or replace procedure myproc2
rc ref cursor
AS
rc1 ref cursor;
begin
EXECUTE myproc1(rc1);
open rc for
select rc1.* from rc1;
end myproc2;

lecaro wrote:
To reiterate, I was interested in consuming the refcursor output of one proc in another proc. I wanted to take what I regarded as the records returned by the first sproc and manipulate them using SQL in the second sproc.
Since I can't use that approach, what are some hopefully fairly straightforward solutions that might work?Something like:
create or replace
  procedure p1(
               p_stmt varchar2,
               p_refcursor OUT sys_refcursor
    is
    begin
        open p_refcursor for p_stmt;
end;
create or replace
  procedure p2(
               p_stmt varchar2
    is
        v_refcursor sys_refcursor;
        v_var varchar2(30);
    begin
        p1(p_stmt,v_refcursor);
        loop
          fetch v_refcursor into v_var;
          exit when v_refcursor%notfound;
          dbms_output.put_line(v_var);
        end loop;
end;
set serveroutput on
exec p2('select ename from emp where deptno = 20');
SQL> set serveroutput on
SQL> exec p2('select ename from emp where deptno = 20');
SMITH
JONES
SCOTT
ADAMS
FORD
PL/SQL procedure successfully completed.
SQL> SY.

Similar Messages

  • Call a Stored Procedure that returns a REFCURSOR using ODI Procedure

    Hi,
    I have a scenario wherein the stored procedure (TEST_PROC1) that returns a REFCURSOR. The second procedure(TEST_PROC2) will use the REFCURSOR as inpuut and insert it to a table.
    Now, I need to execute the test procedures (TEST_PROC1 and TEST_PROC2) using the ODI Procedure but I always get error. However, I was able to execute the test procedures using sqlplus. Here is the command I used for sqlplus:
                   var rc refcursor
                   exec TEST_PROC1(:rc);
                   exec TEST_PROC2(:rc);
    PL/SQL Stored Procedure:
    -- TEST_PROC1 --
    create or replace
    PROCEDURE TEST_PROC1 (p_cursor IN OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT *
    FROM test_table1;
    END;
    -- TEST_PROC2 --
    create or replace
    procedure TEST_PROC2( rc in out sys_refcursor ) is
    FETCH_LIMIT constant integer := 100;
    type TFetchBuffer is table of test_table2%RowType;
    buffer TFetchBuffer;
    begin
    loop
    fetch rc bulk collect into buffer limit FETCH_LIMIT;
    forall i in 1..buffer.Count
    insert into test_table2(
    c1, c2
    ) values(
    buffer(i).c1, buffer(i).c2
    exit when rc%NotFound;
    end loop;
    end;
    Is there a way to call a PL/SQL Stored Procedure that returns a REFCURSOR using ODI Procedure?
    Thanks,
    Cathy

    Thanks for the reply actdi.
    The procedure TEST_PROC1 is just a sample procedure. The requirement is that I need to call a stored procedure that returns a cursor using ODI and fetch the data and insert into a table, which in this case is test_table2.
    I was able to execute a simple SQL procedure (without cursor) using ODI procedure. But when i try to execute the SQL procedure with cursor in ODI, I encountered error.
    Do you have any idea how to do this?

  • Function calling stored procedure that returns a cursor into a LOV

    Hello,
    Is it possible in HTML DB to implement a process that has a function that calls a stored procedure that returns a cursor, used to then populate a select list?
    Or can I do a function call to a stored procedure in the 'List of values definition' box for the item itself that returns a cursor to populate the item's select list?

    Hi Vikas,
    Actually, I just found another posting that shows how to do what I'm looking for:
    Re: Filling a LOV with a cursor
    Check it out. I posted another question in response to that discussion...maybe you could answer that? Thanks!
    Laura

  • Calling a procedure that returns a cursor inside a procedure

    Hi,
    I have two stored procedures. They both return a cursor as output variables. On the other hand I have another stored procedure that calls these procedures and return their results again an output variable. I know that this seems quite odd to be wanting to do something like this but how can I do that?

    You can make the hack generic. Make it execute any SQL as that schema that creates the ref cursor. E.g.
    // as schema BILLY, open a huge security hole and grant access to USER1
    SQL> create or replace procedure GetTableData( tableName varchar2, refCur out sys_refcursor ) authid definer is
      2          dynamicSQL      varchar2(32767);
      3  begin
      4          dynamicSQL := 'select * from '||tableName;
      5          open refCur for dynamicSQL;
      6  end;
      7  /
    Procedure created.
    SQL>
    SQL>
    SQL> grant execute on GetTableData to USER1;
    Grant succeeded.As USER1, you can now execute SQL (and even PL/SQL) as BILLY:
    SQL> create or replace type TStrings is table of varchar2(4000);
      2  /
    Type created.
    SQL> grant execute on TStrings to BILLY;
    Grant succeeded.
    SQL> --// execute this as the caller (which will be BILLY.GetTableData)
    SQL> create or replace procedure ExecSQL( hackSQL varchar2 ) authid current_user is
      2          pragma autonomous_transaction;
      3  begin
      4          execute immediate hackSQL;
      5          commit;
      6  end;
      7  /
    Procedure created.
    SQL> --// wrap the above into something that BILLY.GetData can execute as a ref cursor
    SQL> --// and return a meaningful message as to how successful the hack was
    SQL> create or replace function PipeLineHack( hackSQL varchar2 ) return TStrings authid current_user pipelined is
      2  begin
      3          ExecSQL(  hackSQL );
      4          pipe row( 'SQL hack successful' );
      5  exception when OTHERS then
      6          pipe row( 'SQL hack faled with '||SQLERRM(SQLCODE) );
      7  end;
      8  /
    Function created.
    SQL>
    SQL> grant execute on PipeLineHack to BILLY;
    Grant succeeded.
    SQL>
    SQL> var c refcursor
    SQL> --// expected used of the GetTableData() interface
    SQL> --// we select from table BILLY.EMP
    SQL> exec BILLY.GetTableData( 'EMP', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800          0         20
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 1981/02/22 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 1981/04/02 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 1981/09/28 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 1981/06/09 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 1981/09/08 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 1981/12/03 00:00:00        950                    30
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 1982/01/23 00:00:00       1300                    10
    14 rows selected.
    SQL>
    SQL> --// getting that interface to run unexpected code - we
    SQL> --// rename BILLY.EMP table to something else
    SQL> exec BILLY.GetTableData( 'TABLE(USER1.PipeLineHack( ''alter table emp rename to emp_has_been_hacked''))', :c );
    PL/SQL procedure successfully completed.
    SQL> print c
    COLUMN_VALUE
    SQL hack successful
    SQL>

  • DB  Adapter Calling DB Procedure that returns a Record Type

    I am trying to call a PL/SQL procedure that returns a Record Type and a VARCHAR2 and I'm getting this error:
    <Faulthttp://schemas.xmlsoap.org/soap/envelope/>
    <faultcode>env:Server</faultcode>
    <faultstring>java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'MY_PROC.GET_ID' ORA-06550: line 1, column 7: PL/SQL: Statement ignored </faultstring> </Fault>
    Is there something different I need to do to handle the Record Type OUT parameter?
    Thanks.

    The adapter configuration wizard should take care of the Record Type for you. It should invoke JPublisher to create an equivalent Object type and a package containing a wrapper that will be called by the adapter runtime. The package also contains conversion functions for converting between your Record Type and the generated Object type. Maybe it would help if you posted the signature of your stored procedure (not the body).

  • [perl] How call function/procedure that returns SYS_REFCURSOR type?

    I've got some simple procedure which returns record(s):
    CREATE OR REPLACE PROCEDURE "GET_SYS_DATE"
    RESULTSET IN OUT SYS_REFCURSOR
    IS
    BEGIN
         OPEN RESULTSET FOR
              SELECT SYSDATE FROM DUAL;
    END;
    In perl i invoke it with somthing like this:
    my $ret;
    my $s= "BEGIN GET_SYS_DATE(:1); END;";
    my $sth = $dbh->prepare($s);
    $sth->bind_param_inout(1, \$ret, 0 { TYPE => XXX}); # tried to use many DBD::SQL_* types (SQL_ROW, SQL_REF, etc.)
    $sth->execute(); #... but without luck
    I always get:
    DBD::ODBC::st execute failed: [Oracle][ODBC][Ora]ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GET_SYS_DATE'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Of course if i use other datatype in SP (e.g. VARCHAR2) and bind it as SQL_VARCHAR it works well... Moreover, if i use DBD::Oracle and bind it as ORA_RSET type it also works.
    Is it possible that ODBC doesn't know SYS_REFCURSOR type? Then, is there any way to call SP and retrieve cursor from perl without using DBD::Oracle?
    Or, if it is possible, then how to retrieve that cursor and data stored within it? Any help?

    Hi,
    I have not one eensy teensy bit of knowledge about PERL, other than how to spell it.
    I do however, know about ref cursors, and ODBC, so maybe this will help.
    ODBC has nothing for REF CURSOR built in. ODBC is made to the lowest common denoninator of databases, and a refcur is an Oracle thing. So, what that means is that you can't BIND anythign to the ref cursor, as there is no appropriate ODBC type to bind.
    Does that mean you can't call a refcur via ODBC? No, it doesnt.
    What happens is that Oracle's ODBC driver kinda "magically" goes out behind the scenes and describes the procedure or pacakge to determine if any of the parameters are ref cursors, and if so automatically sets up the bind for them.
    Here's a complete working example using VB and ADO rather than PERL, but maybe you can port it over and get it working. Note that the proc takes two params, but we only bind one (for the IN number)
    Hope it helps,
    Greg
    'create or replace package testrefcur as
    '  type mycur is ref cursor;
    ' procedure getemps(dno in number, ecur out mycur);
    ' end;
    'create or replace package body testrefcur as
    'procedure getemps(dno in number, ecur out mycur) is
    '  begin
    '     open ecur for select * from emp where deptno = dno;
    '  end;
    'end;
    Private Sub Command1_Click()
    Dim con As New ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim rst As New ADODB.Recordset
    strcnn = "dsn=orcl;uid=scott;pwd=tiger"
    con.Open strcnn
    cmd.CommandText = "{call testrefcur.getemps(?)}"
    Set cmd.ActiveConnection = con
    Set param1 = cmd.CreateParameter("param1", adNumeric, adParamInput, 4)
    param1.Value = 10
    param1.Precision = 4
    cmd.Parameters.Append param1
    Set rst = cmd.Execute  
    While Not rst.EOF
    strrslt = strrslt & rst.Fields("ename").Value & " "
    rst.MoveNext
    Wend
    MsgBox strrslt
    End Sub

  • How to call a routine that returns a pointer using jni

    hi this is ravi kiran,
    i have a situation where i need to call a c-routine from my java program that returns a pointer.
    how can i get the content of the pointer that the routine is returning.
    plz help me
    thanx in advance

    Return it as a java long.
    When you need to use it again then pass it in as a long and cast it to a pointer.
    If you need to free it then you should consider writing a finalize() method (one of the few times it is appropriate) and a destroy() method as well.

  • Calling stored procedure and returning multiple resultsets

    Hello,
    Is it possible to create a procedure that return multiple result sets?
    e.g.
    procedure GetDataFromTables() is
    begin
    select * from table_one;
    select * from table_two;
    end GetDataFromTables;
    And I want to call this procedure that returns multiple resultsets (one for table_one and another for table_two)
    I have referred to the OCCI sample occiproc.cpp, but I am not sure how to handle multiple resultsets.
    Your help is highly appreciated.

    Thank You,
    Got the REF cursor in storedproc.cpp.
    But as it is documented, getCursor() gets the REF CURSOR value of an OUT parameter as a ResultSet.
    So, is it true that if I have to write a procedure that selects * from 50 tables (50 SQL statements) , I have to set 50 OUT parameters to get the result sets.?
    Is there any better way of doing this?
    e.g. in DB2, we can open multiple cursors in the procedure body and then get the result set one after another.
    CREATE PROCEDURE get_staging_data ()
    RESULT SETS 1 <no. of result sets>
    LANGUAGE SQL
    BEGIN ATOMIC
    DECLARE L_SQL varchar(5000);
    DECLARE c CURSOR WITH RETURN TO CLIENT FOR L_STMT;
    SET L_SQL = '';
    SET L_SQL = 'SELECT * FROM ';
    SET L_SQL = L_SQL || IN_Tab_Name ;
    SET L_SQL = L_SQL || ' WHERE VERIFY_FLAG=''S'' FOR READ ONLY OPTIMIZE FOR 2000 ROWS' ;
    PREPARE L_STMT FROM L_SQL;
    OPEN c; < can open multiple cursors in the prodedure body>
    END

  • Using XI - RFC table and an Oracle stored procedure that returns a cursor.

    I need to create an interface using XI between an RFC table and an Oracle stored procedure that returns a cursor.  We are on oarcle 9.2 and  SP12.
    My stored procedure looks something like this:
    CREATE OR REPLACE
    PROCEDURE testproc_xi2 (p_recordset1 OUT SYS_REFCURSOR,
                                             in_quoteid IN varchar2 )
    AS
    BEGIN
      OPEN p_recordset1 FOR
       SELECT  q.quote_id,
                     q.modified_by,
                     q.quote_status,
                     q.total_cost
                FROM quote q
               WHERE q.quote_id = in_quoteid
                 AND q.total_cost > 0 ; 
    END testproc_xi2 ;
    My RFC has table and  one import parameter .
    I wanted to know how to create the data type for the ref cursor? and also for the table type in the RFC?
    CAN XI handle multi rows coming from a Stored procedure? Are there any other alternative methods if this is not supported?Any pointers to this would be helpful.
    I have called a Oracle SP from an RFC before, but that interface had one input parameter going to the stored procedure from the RFC and about 6 o/p parameters coming from the Stored procedure. This works fine.
    Thanks for the help.
    Mala

    Mala,
    i dont think there is anything called an rfc table...RFC stands for remote function call. That in essence would imply you need a rfc to jdbc connection.
    yes XI can handle multiple rows cooming from the the stored procedure if you have them mapped appropriately.
    Now as to how to create the data type within xi , you need to know what fields are going to be returned and whether they are nested and then just create them as you would for an xml
    for ex
    <Details>
      <FirstName>
    <LastName>
    </Details>
    that in xi would be smthing like
    Details  type of data occurence
    FirstName type of data occurence
    LastName type of data occurence.
    Hope that helps.
    If it does dont forget the points..:-)

  • How Do I Call PL/SQL Stored Procedure That Returns String Array??

    I Have Problem Calling An Oracle(8i) Stored Procedure That Returns Array Type (Multi Rows)
    (As Good As String Array Type..)
    In This Fourm, I Can't Find Out Example Source.
    (Question is Exist.. But No Answer..)
    I Want An Example,, Because I'm A Beginner...
    (I Wonder...)
    If It Is Impossible, Please Told Me.. "Impossible"
    Then, I'll Give Up to Resolve This Way.....
    Please Help Me !!!
    Thanks in advance,

    // Try the following, I appologize that I have not compiled and run this ... but it is headed in the right direction
    import java.sql.*;
    class RunStoredProc
    public static void main(String args[])
    throws SQLException
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    catch(Exception ex)
    ex.printStackTrace();
    java.util.Properties props = new java.util.Properties();
    props.put("user", "********"); // you need to replace stars with db userid
    props.put("password", "********"); // you need to replace stars with userid db password
              // below replace machine.domain.com and DBNAME, and port address if different than 1521
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@machine.domain.com:1521:DBNAME", props);
    // replace "Your Stored Procedure" with your stored procedure
    CallableStatement stmt = conn.prepareCall("Your Stored Procedure");
    ResultSet rset = stmt.execute();
    while(rset.next())
    System.out.println(rset.getString(1));

  • How to call a sp that returns multi_columns from another sp

    Hi,
    Can anybody help me to solve this problem? I called a sp which
    returns ename, sal using a weak ref cursor from another sp. Is
    it possible to do this? or I did something wrong? The error
    messages are:
    ERROR at line 1:
    ORA-00904: invalid column name
    ORA-06512: at "SCOTT.TESTPKG", line 14
    ORA-06512: at line 1
    below is my code:
    create or replace package testpkg AS           //12/19/01
    TYPE sumCur IS REF CURSOR;
    TYPE estType IS REF CURSOR;
         function totalNo (
              dno IN NUMBER)
              RETURN estType;
         procedure test(
              sum_cv IN OUT NOCOPY sumCur);
    END;
    CREATE OR REPLACE PACKAGE BODY testpkg AS
         function totalNo (
              dno IN NUMBER)
              RETURN estType IS est_cv estType;
              BEGIN
              OPEN est_cv FOR SELECT ename, sal FROM emp
    where deptno = dno and job = 'MANAGER';
              RETURN est_cv;
         END totalno;          
         procedure test(
              sum_cv IN OUT NOCOPY sumCur) AS
              sql_statement VARCHAR2(100);
         BEGIN
              sql_statement :='SELECT dname, totalNo(deptno)
    from dept ';
              OPEN sum_cv FOR sql_statement ;
         END test;     
    END;
    Thanks

    The error that you are getting is because totalNo(deptno) needs
    to be testpkg.totalNo(deptno), but that is not the only error.
    Maybe you can use something like this:
    SQL> CREATE OR REPLACE PACKAGE testpkg
      2  AS
      3    TYPE sumcur       IS         REF CURSOR;
      4    FUNCTION totalno
      5      (dno         IN            NUMBER)
      6      RETURN                     VARCHAR2;
      7    PROCEDURE test
      8      (sum_cv      IN OUT        sumcur);
      9  END testpkg;
    10  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY testpkg
      2  AS
      3    FUNCTION totalno
      4      (dno         IN            NUMBER)
      5      RETURN                     VARCHAR2
      6    IS
      7      est_cv                     VARCHAR2 (30);
      8    BEGIN
      9      SELECT ename || ' ' || TO_CHAR (sal)
    10      INTO   est_cv
    11      FROM   emp
    12      WHERE  deptno = dno
    13      AND    job = 'MANAGER';
    14      RETURN est_cv;
    15    END totalno;
    16    PROCEDURE test
    17      (sum_cv      IN OUT        sumcur)
    18    AS
    19      sql_statement              VARCHAR2 (100);
    20    BEGIN
    21      sql_statement :=
    22         ' SELECT dname, testpkg.totalno (deptno)'
    23      || ' FROM dept';
    24      OPEN sum_cv FOR sql_statement;
    25    END test;
    26  END testpkg;
    27  /
    Package body created.
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC testpkg.test (:g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    DNAME
    TESTPKG.TOTALNO(DEPTNO)
    ACCOUNTING
    CLARK 2450
    RESEARCH
    JONES 2975
    SALES
    BLAKE 2850
    DNAME
    TESTPKG.TOTALNO(DEPTNO)
    OPERATIONS

  • Help! Need oracle help with constructing stored procedure that return resultsets

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

    Suns tutorial path for returning resultsets from stored procedures indicates that the following should work...
    CallableStatement cs = con.prepareCall("{call SHOW_SUPPLIERS}");
    ResultSet rs = cs.executeQuery();
    Thats if you build your stored procedure something like this ...
    String createProcedure = "create procedure SHOW_SUPPLIERS " + "as " + "select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "order by SUP_NAME";
    We are using oracle 8.1.6. However I've been told that with oracle procedures when you return a result set from a called procedure you return a p_cursor variable. Somthing like this
    (p_cursor in out SHOW_SUPPLIERS.SHOCurTyp)
    is
    begin
    open p_cursor for
    select * from suppliers
    In which case the above mentioned sun code doesn't work.
    We want to use jdbc to call a stored procedure that returns a resultset that does not require us to import any proprietary oracle objects...
    Is there another way to write these stored procedures, rather than using this cursor construct? Are we missing something in the way we invoke them?

  • Sort/filter datablock based on procedure that return table type

    Hi All,
    I’ve got datablock based on procedure that return table type. In the form I have to provide ‘filter and sort records’ functionality. Previously, using tables/views based datablocks, I’ve done that by using:
    -- filter
    SET_BLOCK_PROPERTY (L_BLOCK_NAME, DEFAULT_WHERE, L_WHERE_CLAUSE);
    -- sort
    SET_BLOCK_PROPERTY(L_BLOCK_NAME ,ORDER_BY, L_ORDER_BY_CLAUSE);
    -- and then
    EXECUTE_QUERY;
    It doesn’t work with procedure that return table type. How I can do that?
    Bartek

    I agree with Andreas, from the sample you have given us, I don't see any reason why you could not merge these queries into a single UNION/UNION ALL query. Also, I would add your summation query to your main query to eliminate this extra step. The result would look something like:
    SELECT DISTINCT
         pih.id
         ,d.document_id
         ,pih.doc_serial_no
         ,pih.purch_invoice_date
         ,oh.company_name
         ,(SELECT NVL(SUM(amount),0)
              FROM "YOUR TABLE HERE" yth
              WHERE yth."YOUR COLUMN HERE" = pih.id) AS sum_amount
      FROM "YOUR TABLES HERE"
    WHERE "YOUR JOIN CONDITIONS HERE"
    UNION ALL
    SELECT DISTINCT
         sih.id
         ,d.document_ind
         ,sih.doc_serial_no
         ,sih.sales_invoice_date
         ,sih.company_name
         ,(SELECT NVL(SUM(amount),0)
              FROM "YOUR TABLE HERE" yth
              WHERE yth."YOUR COLUMN HERE" = sih.id) AS sum_amount
      FROM "YOUR TABLES HERE"
    WHERE "YOUR JOIN CONDITIONS HERE"
    [/code]
    Hope this helps.
    Craig...
    +If a response is helpful or correct, please mark it accordingly+
    Edited by: CraigB on Feb 23, 2010 1:39 PM
    It appears the CODE tags are not working as well as the URL tags.  :(                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • Stored procedure that returns multiple tables

    Hello everyone,
    I was wondering if there's a way to write a stored procedure that returns multiple result set as in sql server. for example, in sql server, you can write 2 select statements and when loading them in c#, u can get two data tables.
    I am not sure having a single ref cursor for each select is the only solution. I might need to return a variable number of tables per procedure call (based on a certain criteria).
    Any ideas?
    thanks for your time

    Sure. Ref cursor is the only easier answer for your problem.
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:01.43
    satyaki>
    satyaki>create or replace procedure ref_gen_arg(choice in int,b in out sys_refcursor)
      2  is  
      3    str   varchar2(500);
      4  begin   
      5    if choice = 1 then      
      6      str := 'select * from emp';   
      7    elsif choice = 2 then      
      8      str := 'select * from dept';   
      9    end if;       
    10   
    11    open b for str;
    12  exception  
    13    when others then     
    14      dbms_output.put_line(sqlerrm);
    15  end;
    16  /
    Procedure created.
    Elapsed: 00:00:04.38
    satyaki>
    satyaki>
    satyaki>declare   
      2    rec_x emp%rowtype;   
      3    rec_y dept%rowtype;       
      4    w sys_refcursor;
      5  begin  
      6    dbms_output.enable(1000000);  
      7    ref_gen_arg(1,w);  
      8    loop    
      9      fetch w into rec_x;     
    10      exit when w%notfound;             
    11        dbms_output.put_line('Employee No: '||rec_x.empno||' - '||                          
    12                             'Name: '||rec_x.ename||' - '||                          
    13                             'Job: '||rec_x.job||' - '||                          
    14                             'Manager: '||rec_x.mgr||' - '||                          
    15                             'Joining Date: '||rec_x.hiredate||' - '||                          
    16                             'Salary: '||rec_x.sal||' - '||                          
    17                             'Commission: '||rec_x.comm||' - '||                          
    18                             'Department No: '||rec_x.deptno);  
    19    end loop;  
    20    close w;    
    21   
    22    ref_gen_arg(2,w);  
    23    loop    
    24      fetch w into rec_y;
    25      exit when w%notfound;            
    26         dbms_output.put_line('Department No: '||rec_y.deptno||' - '||                           
    27                              'Name: '||rec_y.dname||' - '||                           
    28                              'Location: '||rec_y.loc);  
    29    end loop;  
    30    close w;
    31  exception  
    32    when others then    
    33      dbms_output.put_line(sqlerrm);
    34  end;
    35  /
    Employee No: 9999 - Name: SATYAKI - Job: SLS - Manager: 7698 - Joining Date: 02-NOV-08 - Salary: 55000 - Commission: 3455 - Department No: 10
    Employee No: 7777 - Name: SOURAV - Job: SLS - Manager:  - Joining Date: 14-SEP-08 - Salary: 45000 - Commission: 3400 - Department No: 10
    Employee No: 7521 - Name: WARD - Job: SALESMAN - Manager: 7698 - Joining Date: 22-FEB-81 - Salary: 1250 - Commission: 500 - Department No: 30
    Employee No: 7566 - Name: JONES - Job: MANAGER - Manager: 7839 - Joining Date: 02-APR-81 - Salary: 2975 - Commission:  - Department No: 20
    Employee No: 7654 - Name: MARTIN - Job: SALESMAN - Manager: 7698 - Joining Date: 28-SEP-81 - Salary: 1250 - Commission: 1400 - Department No: 30
    Employee No: 7698 - Name: BLAKE - Job: MANAGER - Manager: 7839 - Joining Date: 01-MAY-81 - Salary: 2850 - Commission:  - Department No: 30
    Employee No: 7782 - Name: CLARK - Job: MANAGER - Manager: 7839 - Joining Date: 09-JUN-81 - Salary: 4450 - Commission:  - Department No: 10
    Employee No: 7788 - Name: SCOTT - Job: ANALYST - Manager: 7566 - Joining Date: 19-APR-87 - Salary: 3000 - Commission:  - Department No: 20
    Employee No: 7839 - Name: KING - Job: PRESIDENT - Manager:  - Joining Date: 17-NOV-81 - Salary: 7000 - Commission:  - Department No: 10
    Employee No: 7844 - Name: TURNER - Job: SALESMAN - Manager: 7698 - Joining Date: 08-SEP-81 - Salary: 1500 - Commission: 0 - Department No: 30
    Employee No: 7876 - Name: ADAMS - Job: CLERK - Manager: 7788 - Joining Date: 23-MAY-87 - Salary: 1100 - Commission:  - Department No: 20
    Employee No: 7900 - Name: JAMES - Job: CLERK - Manager: 7698 - Joining Date: 03-DEC-81 - Salary: 950 - Commission:  - Department No: 30
    Employee No: 7902 - Name: FORD - Job: ANALYST - Manager: 7566 - Joining Date: 03-DEC-81 - Salary: 3000 - Commission:  - Department No: 20
    Department No: 10 - Name: ACCOUNTING - Location: NEW YORK
    Department No: 20 - Name: RESEARCH - Location: DALLAS
    Department No: 30 - Name: SALES - Location: CHICAGO
    Department No: 40 - Name: LOGISTICS - Location: CHICAGO
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.73
    satyaki>Regards.
    Satyaki De.

Maybe you are looking for

  • How to read/write a binary file from/to a table with BLOB column

    I have create a table with a column of data type BLOB. I can read/write an IMAGE file from/to the column of the table using: READ_IMAGE_FILE WRITE_IMAGE_FILE How can I do the same for other binary files, e.g. aaaa.zip?

  • Prototypes won't load variables?

    I am using FMS2 to work as a buffer inbetween my PHP Code and my Flash Client. The thing is, my client worked flawlessly when using PHP/MySQL and Flash alone, but when integrating FMS, I encountered a few problems. It seems like when using a prototyp

  • Full table scans : sql or server?

    Thanks for taking my question! We have 3 oracle servers (10.2.0.3). Each server has the same tables, data, and indexes but each can start acting different for no apparent reason. Sql that has runs for months goes bad on our production and test server

  • Desperately In Need Of Case For (ZEN MicroPho

    I've done hours of research but can't come up with any Microphoto Cases, I realize the normal Zen Micros cut off the top of the ZMP's screen. I don't want that, at this point I'll take anything from Silicon to Aluminum cases. Anybody have any ideas?

  • TS3683 iTunes nightmare!!!

    When backing up my iPhone and iPad to my iTunes it won't download a large number of albums bought from iTunes.  The error message says that the originals can't be found, however the are still available in the purchased section of iTunes.