Refcursor in package

Hi,
Can i use REFCURSOR in package.
if not why?

Yes..
see the example .
CREATE OR REPLACE PACKAGE CURSPKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
                               IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
                                DEPTCURSOR OUT T_CURSOR);
END CURSPKG;
CREATE OR REPLACE PACKAGE BODY CURSPKG AS
    PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER,
                               IO_CURSOR IN OUT T_CURSOR)
    IS
        V_CURSOR T_CURSOR;
    BEGIN
        IF N_EMPNO <> 0
        THEN
             OPEN V_CURSOR FOR
             SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
                  FROM EMP, DEPT
                  WHERE EMP.DEPTNO = DEPT.DEPTNO
                  AND EMP.EMPNO = N_EMPNO;
        ELSE
             OPEN V_CURSOR FOR
             SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME
                  FROM EMP, DEPT
                  WHERE EMP.DEPTNO = DEPT.DEPTNO;
        END IF;
        IO_CURSOR := V_CURSOR;
    END OPEN_ONE_CURSOR;
    PROCEDURE OPEN_TWO_CURSORS (EMPCURSOR OUT T_CURSOR,
                                DEPTCURSOR OUT T_CURSOR)
    IS
        V_CURSOR1 T_CURSOR;
        V_CURSOR2 T_CURSOR;
    BEGIN
        OPEN V_CURSOR1 FOR SELECT * FROM EMP;
        OPEN V_CURSOR2 FOR SELECT * FROM DEPT;
        EMPCURSOR  := V_CURSOR1;
        DEPTCURSOR := V_CURSOR2;
    END OPEN_TWO_CURSORS;
END CURSPKG;Venkadesh

Similar Messages

  • Please Help in ORACLE SPOOL File

    Hello All,
    I made oracle Spool file.Generally i m calling a FUNCTION which return a REFCURSOR.
    ----Package Spec------------------------
    CREATE OR REPLACE PACKAGE Axspointrpt IS
    TYPE return_cur IS REF CURSOR ;
    -- # Updates to the SOI and associated CARMA user ids
    FUNCTION F_UPDATION_USERID_RPT RETURN return_cur ;
    END Axspointrpt;
    ----Package Body------------------------
    CREATE OR REPLACE PACKAGE BODY Axspointrpt IS
    FUNCTION F_UPDATION_USERID_RPT
    RETURN return_cur IS
    VCur return_cur;
    BEGIN
    OPEN VCur FOR
    SELECT
    ID_SCTY,ID_SYMBOL,NM_SHORT,S.DT_MNT_LST,S.ID_MNT_LST,LTRIM(RTRIM(CARMA_FINAL.F_Getusername(S.ID_MNT_LST))) USERNAME,DECODE(IN_DELETED,'Y','YES','N','NO') ACTION
    FROM SOI_MASTER S,APP_USER A
    WHERE S.ID_MNT_LST=A.ID_MNT_LST;
    RETURN VCur;
    EXCEPTION
    WHEN OTHERS THEN
    IF (VCur%isOpen) THEN
    CLOSE VCur;
    END IF;
    END F_UPDATION_USERID_RPT ;
    -----------callRPT.sql ------------------
    SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>SQL*Plus Report</title> -"
    SET ECHO OFF
    SET PAUSE OFF
    SET VERIFY OFF
    SET FEEDBACK OFF
    SET HEADING ON
    SET LINESIZE 150
    set PAGESIZE 85
    SET TRIMSPOOL ON PAGESIZE 50
    SPOOL D:\Avinash\employee.htm
    select Axspointrpt.F_UPDATION_USERID_RPT from DUAL;
    clear breaks
    TTITLE OFF
    SPOOL OFF
    SET MARKUP HTML OFF
    SET ECHO ON
    When i run this SQL file then i am getting the procedure name as well as CURSOR STATEMENT along with the table data.I want get Hide the procedure namd,and cursor statement.Please help in this.
    Regards,
    [email protected]

    Hi Avinash,
    Try this:
    create or replace package dump_refcursor_test is
    type return_cur is ref cursor;
    function get_data return return_cur;
    end dump_refcursor_test;
    create or replace package body dump_refcursor_test is
    function get_data return return_cur
    is
    l_cur return_cur;
    begin
    open l_cur for select 'qwerty' from dual;
    return l_cur;
    end get_data;
    end dump_refcursor_test;
    Create a file called spool.sql put it in c:\. Put his in the file:
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 80
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET HEADING OFF
    SET MARKUP HTML OFF SPOOL OFF
    set sqlprompt "".
    var res refcursor;
    exec :res:= dump_refcursor_test.get_data;
    spool c:\spool_output
    print res
    spool off
    Now go to sql*plus and type this:
    @c:\spool.sql
    This will give you a file with only the data, here "qwerty"
    Regards Pete

  • How  to use  refcursor in a package

    i want to use refcursor in a package
    but when i am trying to declare a refcursor variable ,
    I get no error but the refcursor does not return anything .
    why is this happenning ?
    I also read that we cannot define cursor variables in a paclage .
    Then how to go about it ?
    regards
    shubhajit

    Since Oracle 7.3 REF CURSORS have been available which allow recordsets to be returned from stored procedures, functions and packages. The example below uses a ref cursor to return a subset of the records in the EMP table.
    First, a package definition is needed to hold the ref cursor type:
    CREATE OR REPLACE PACKAGE Types AS
    TYPE cursor_type IS REF CURSOR;
    END Types;
    Note. In Oracle9i the SYS_REFCURSOR type has been added making this first step unnecessary. If you are using Oracle9i or later simply ignore this first package and replace any references to Types.cursor_type with SYS_REFCURSOR.
    Next a procedure is defined to use the ref cursor:
    CREATE OR REPLACE
    PROCEDURE GetEmpRS (p_deptno IN emp.deptno%TYPE,
    p_recordset OUT Types.cursor_type) AS
    BEGIN
    OPEN p_recordset FOR
    SELECT ename,
    empno,
    deptno
    FROM emp
    WHERE deptno = p_deptno
    ORDER BY ename;
    END GetEmpRS;
    The resulting cursor can be referenced from PL/SQL as follows:
    SET SERVEROUTPUT ON SIZE 1000000
    DECLARE
    v_cursor Types.cursor_type;
    v_ename emp.ename%TYPE;
    v_empno emp.empno%TYPE;
    v_deptno emp.deptno%TYPE;
    BEGIN
    GetEmpRS (p_deptno => 30,
    p_recordset => v_cursor);
    LOOP
    FETCH v_cursor
    INTO v_ename, v_empno, v_deptno;
    EXIT WHEN v_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_ename || ' | ' || v_empno || ' | ' || v_deptno);
    END LOOP;
    CLOSE v_cursor;
    END;
    In addition the cursor can be used as an ADO Recordset:
    Dim conn, cmd, rs
    Set conn = Server.CreateObject("adodb.connection")
    conn.Open "DSN=TSH1;UID=scott;PWD=tiger"
    Set cmd = Server.CreateObject ("ADODB.Command")
    Set cmd.ActiveConnection = conn
    cmd.CommandText = "GetEmpRS"
    cmd.CommandType = 4 'adCmdStoredProc
    Dim param1
    Set param1 = cmd.CreateParameter ("deptno", adInteger, adParamInput)
    cmd.Parameters.Append param1
    param1.Value = 30
    Set rs = cmd.Execute
    Do Until rs.BOF Or rs.EOF
    -- Do something
    rs.MoveNext
    Loop
    rs.Close
    conn.Close
    Set rs = nothing
    Set param1 = nothing
    Set cmd = nothing
    Set conn = nothing
    The cursor can also be referenced as a Java ResultSet:
    import java.sql.*;
    import oracle.jdbc.*;
    public class TestResultSet {
    public TestResultSet() {
    try {
    DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:oci:@w2k1", "scott", "tiger");
    CallableStatement stmt = conn.prepareCall("BEGIN GetEmpRS(?, ?); END;");
    stmt.setInt(1, 30); // DEPTNO
    stmt.registerOutParameter(2, OracleTypes.CURSOR); //REF CURSOR
    stmt.execute();
    ResultSet rs = ((OracleCallableStatement)stmt).getCursor(2);
    while (rs.next()) {
    System.out.println(rs.getString("ename") + ":" + rs.getString("empno") + ":" + rs.getString("deptno"));
    rs.close();
    rs = null;
    stmt.close();
    stmt = null;
    conn.close();
    conn = null;
    catch (SQLException e) {
    System.out.println(e.getLocalizedMessage());
    public static void main (String[] args) {
    new TestResultSet();
    Hope this helps. Regards
    Srini

  • How to pass refcursor as input parameter to a procedure in a package

    Hi there
    Please can anybody explain me with an small example for
    passing a procedure output(output should be a refcursor) and pass that refcursor values into a procedure in a package as input parameter and this value i want to use as join condition in my procedure ie. ename=refcursor.ename like this).That my exact question is how to pass refcursor values as in parameter
    Pls suggest me with some example statements
    thanks in advance
    prasanth a.s.

    I am giving you a generic example.
    SQL> variable v_out REFCURSOR
    SQL> r
      1  DECLARE
      2  PROCEDURE TEST1(p_out OUT SYS_REFCURSOR) IS
      3  BEGIN
      4  OPEN p_out FOR SELECT EMPNO,ENAME FROM SCOTT.EMP;
      5  END;
      6  PROCEDURE TEST2(p_in IN SYS_REFCURSOR) IS
      7  v_empno NUMBER(10);
      8  v_ename VARCHAR2(30);
      9  BEGIN
    10  LOOP
    11  FETCH p_in INTO v_empno,v_ename;
    12  EXIT WHEN p_in%NOTFOUND;
    13  DBMS_OUTPUT.PUT_LINE(v_ename);
    14  END LOOP;
    15  NULL;
    16  END;
    17  BEGIN
    18     TEST1(:v_out);
    19     TEST2(:v_out);
    20* END;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.

  • Having issues with bind variable refcursor

    Hi,
    I have a procedure which returns just the list of employees from the emp table.
    while executing this package, it gives me an error
    Ex:
    sql> variable cur refcursor;
    sql> exec emp.getemplist(:cur);
    error:
    not all variables bound
    Please let me know what is wrong here.
    Thanks
    Manju

    manjukn wrote:
    package is a simple one..
    Exact Oracle version? Works fine on 10.2.0.4.0:
    SQL> create or replace package body emp_pkg is
      2  PROCEDURE getemplist (result_cursor OUT sys_refcursor)
      3  IS
      4  begin
      5  open result_cursor for select * from emp where deptno=10;
      6  end getemplist;
      7  end emp_pkg;
      8  /
    Package body created.
    SQL> variable cur refcursor;
    SQL> exec emp_pkg.getemplist(:cur);
    PL/SQL procedure successfully completed.
    SQL> print cur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    SQL> SY.

  • How to read the data from a refcursor

    Hi all,
    Here my program . I'm calling pr_test into another program there i need to read the values from refcursor of pr_test program . I dont want use all the values in my second program I need to pass empno and job only.
    pls help me out how to read this?
    package pg_test
    is
    type curvartype is ref cursor;
    procedure pr_test(p_empno in number, o_curvar_out curvartype);
    end;
    package pg_test is
    procedure pr_test( o_curvar_out curvartype)
    is
    begin
    open o_curvar_out for
    select * from emp;
    end loop;
    end;
    end;Thanks,
    Venkat.

    I dont want use all the values in my second program I need to pass empno and job only.Since your cursor gets all the columns (using the * is not a good way to code the cursor), that is what your other program will get when it calls pr_test procedure. You will have to FETCH all the columns in that other procedure and discard the ones you do not need.
    Alternatively, change the code of cursor to select only the columns you would actually need.

  • Calling Oracle Package Function from Visual Basic

    Hi,
    Oracle Client 8.04
    Oracle ODBC Driver 8.00.04
    VB 6.0
    Windows 2000
    I'm stumped here. I want to have a Oracle stored procedure run a
    query and return a result set which I can assign to a recordset
    object in VB. Based on things I've read here and on MS's site,
    here's what I've done:
    In the Oracle Schema Manager under the Packages folder I created
    the following package:
    PACKAGE test
    IS
    TYPE test_cur IS REF CURSOR;
    FUNCTION mycur RETURN test_cur;
    END test;
    and under the Package Body folder created:
    PACKAGE BODY test
    IS
    FUNCTION mycur RETURN test_cur
    IS
    c_return test_cur;
    BEGIN
    OPEN c_return FOR
    SELECT * FROM table_A;
    RETURN c_return;
    CLOSE c_return;
    END mycur;
    END test;
    They both compile without errors and in Oracle SQL Worksheet I
    can enter the following:
    variable x refcursor;
    execute :x :=test.mycur;
    print x;
    and the query results are displayed as expected.
    The problem is trying to get the result back into a VB recordset
    object.
    In VB 6.0 I have done this:
    Dim RS As ADODB.Recordset
    Dim Conn As ADODB.Connection
    Dim sConnection As String
    Dim sSQL As String
    sSQL = "{call test.mycur}"
    sConnection = "Provider=MSDASQL;UID=" & sUserID & ";PWD=" &
    sPassword & ";Driver={Microsoft ODBC for Oracle}; Server=" &
    sInstance & ";"
    Conn.Open sConnection
    RS.CursorLocation = adUseClient
    RS.Open sSQL, Conn, adOpenForwardOnly, adLockOptimistic,
    adCmdStoredProc ' or adCmdText
    but get:
    ?err.Number -2147217900
    ?err.Source Microsoft OLE DB Provider for ODBC Drivers
    ?err.Description [Microsoft][ODBC driver for Oracle]Syntax error
    or access violation
    The problem is not with the connection or permissions, since the
    query works fine when I just use the select statement in the
    package function as the string, instead of calling the function
    in the package (eg sSQL = "Select * from table_A") and can
    process the resulting recordset in VB.
    I've also tried variations using:
    Set RS = Conn.Execute("{call test.mycur}")
    or using a Command object something like:
    Dim com As ADODB.Command
    Set com = New ADODB.Command
    With Conn
    .ConnectionString = sConnection
    .CursorLocation = adUseClient
    .Open
    End With
    With com
    .ActiveConnection = Conn
    .CommandText = sSQL
    .CommandType = adCmdText
    End With
    Set RS.Source = com
    RS.Open
    But still get the same errors. Any help is appreciated. Also, in
    my package body, is it necessary to explicitly close the cursor,
    or does the function just exit when it executes the return and
    not ever hit the close statement?
    Thanks,
    Ed Holloman

    Hi
    i don't know if you got your answer, but i work with VB and
    Oracle.
    the procedure in the DB should have the cursor like you writen
    in your mail.
    to call a procedure in Oracle and get the data back
    into a recordset you shuld use a Command object like this:
    Dim conn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim rs As ADODB.Recordset
    Set conn = CreateObject("adodb.connection")
    Set cmd = CreateObject("adodb.command")
    Set rs = CreateObject("adodb.recordset")
    With conn
    .ConnectionString = ""
    .CursorLocation = adUseClient
    .Open
    End With
    'THE IMPORTENT SECTION IS THIS WHERE YOU SET THE COMMAND TO THE
    STORE PROCEDURE TYPE
    With cmd
    .ActiveConnection = conn
    .CommandText = "proc.fun"
    .CommandType = adCmdStoredProc
    End With
    'Then you set the rs to the command
    Set rs = cmd.Execute
    Set conn = Nothing
    Set rs = Nothing
    Set cmd = Nothing

  • Issue with IN parameter of Oracle Procedure returning two RefCursors...

    Hi all,
    I'm having a nightmare with an Oracle procedure that takes one input parameter and returns two RefCursors as outputs. I recently got help in this forum getting a procedure to work that took no inputs but returned two refcursors and that's still working fine. So, for my current issue I have a procedure defined as follows:
    PROCEDURE getQueueInfo(domainKey char, importQueues OUT ODPNet.refcur, exportQueues OUT ODPNet.refcur) IS
      BEGIN
        OPEN importQueues FOR SELECT
        source_key, source_applid,
        import_status(source_key) as status,
        time_added, time_processed
        FROM wm_import_source_header
        WHERE source_id = domainKey
        ORDER BY source_key DESC;
        OPEN exportQueues FOR SELECT
        h.source_key, d.source_applid,
        export_status(h.source_key) as status,
        d.source_wire_code, d.destination_wire_code, h.time_added,
        h.time_transmitted
        FROM wm_export_source_header h, wm_export_source_data d
        WHERE h.source_key = d.source_key
          and d.source_id = domainKey
        ORDER BY h.source_key DESC;
      END getQueueInfo;This is defined within a package called ODPNet as with my previous procedure and all works fine (I can execute within Oracle SQL Developer and it returns the expected results). Within my .NET application my code is as follows:
                try
                    using (OracleConnection conn = new OracleConnection(connString))
                    using (OracleCommand comm = new OracleCommand())
                        comm.CommandText = "ODPNet.getQueueInfo";
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Connection = conn;
                        OracleParameter domainKey = new OracleParameter();
                        OracleParameter importQueues = new OracleParameter();
                        OracleParameter exportQueues = new OracleParameter();
                        domainKey.OracleDbType = OracleDbType.Char;
                        importQueues.OracleDbType = OracleDbType.RefCursor;
                        exportQueues.OracleDbType = OracleDbType.RefCursor;
                        domainKey.Value = "UKBD72";
                        domainKey.Direction = ParameterDirection.Input;
                        importQueues.Direction = ParameterDirection.Output;
                        exportQueues.Direction = ParameterDirection.Output;
                        comm.Parameters.Add(domainKey);
                        comm.Parameters.Add(importQueues);
                        comm.Parameters.Add(exportQueues);
                        conn.Open();
                        comm.ExecuteNonQuery();
                        OracleDataReader dr1 = ((OracleRefCursor)importQueues.Value).GetDataReader();
                        OracleDataReader dr2 = ((OracleRefCursor)exportQueues.Value).GetDataReader();
                        if (dr1.HasRows)
                            while (dr1.Read())
                                result6 += dr1["source_applid"].ToString() + "<br>";
                        else
                            result6 += "No Rows";
                        if (dr2.HasRows)
                            while (dr2.Read())
                                result7 += dr2["source_applid"].ToString() + "<br>";
                        else
                            result7 += "No Rows";
                catch (Exception ex)
                    result6 = ex.ToString();
                }The value I want to submit as the IN parameter of the procedure is "UKBD72". but I'm really not sure how to apply this and then return my two refcursors into separate datareaders (except for the input parameter stuff the code above is exactly what I did with the other procedure that returned two ref cursors and still works fine). When I run this code I get no errors, I just get told that each DataReader has no rows returned, which shouldn't be right.
    Any help with this would be hugely appreciated.
    Cheers,
    Seb

    Sorry folks, after staring at this over and over, eventually going to sleep and coming back to it with some fresh eyes I realised I was just being a complete idiot - I was feeding the procedure different data in the .NET app than I was when testing in Oracle SQL Developer. Low and behold once I gave it the right data it worked!
    Silly me...

  • PLS-00304: cannot compile body of package without its specification

    Hi all,
    While compiling the below pasted package , I got the following error msg.
    PL/SQL: Compilation unit analysis terminated
    PLS-00304: cannot compile body of 'EDR_RPT_CLASS_BY_TAWT_PACKAGE'
    without its specification
    PLS-00905: object HDOT.EDR_RPT_CLASS_BY_TAWT_PACKAGE is invalidBut I believe that have declared package and ppackage body specification correctly. Please could anyone help me to find out the error
    CREATE OR REPLACE PACKAGE edr_rpt_class_by_tawt_package AS
    PROCEDURE edr_rpt_gen_class_by_tawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    PROCEDURE edr_rpt_gen_class_by_fawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    PROCEDURE edr_rpt_gen_class_by_sawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    PROCEDURE edr_rpt_gen_class_by_triawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    PROCEDURE edr_rpt_gen_class_by_qawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    FUNCTION  class_count
      in_lane_id                  edr_rpt_by_ranges_output.lane_id%TYPE,
      in_direction_id             edr_rpt_by_ranges_output.direction_id%TYPE,
      in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_interval_end_date_time   edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_axle_wt_min              edr_cls_by_tawt_report_data.group_weight%TYPE,
      iin_axle_wt_max             edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_class_min                edr_cls_by_tawt_report_data.vehicle_class%TYPE,
      in_class_max                edr_cls_by_tawt_report_data.vehicle_class%TYPE
    RETURN VARCHAR2;
    END edr_rpt_class_by_tawt_package;
    CREATE OR REPLACE PACKAGE BODY edr_rpt_class_by_tawt_package AS
       c_front_axle_only         CONSTANT axle_class.group_type%TYPE := -1;
       c_axle_single_group_type  CONSTANT axle_class.group_type%TYPE := 1;
       c_axle_tandem_group_type  CONSTANT axle_class.group_type%TYPE := 2;
       c_axle_tridem_group_type  CONSTANT axle_class.group_type%TYPE := 3;
       c_axle_quadrem_group_type CONSTANT axle_class.group_type%TYPE := 4;
       c_kips_conversion_unit_id CONSTANT units.unit_id%TYPE         := 8;
       v_report_axle_group_type  axle_class.group_type%TYPE := 0;
    FUNCTION  class_count
      in_lane_id                  edr_rpt_by_ranges_output.lane_id%TYPE,
      in_direction_id             edr_rpt_by_ranges_output.direction_id%TYPE,
      in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_interval_end_date_time   edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_axle_wt_min              edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_axle_wt_max              edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_class_min                edr_cls_by_tawt_report_data.vehicle_class%TYPE,
      in_class_max                edr_cls_by_tawt_report_data.vehicle_class%TYPE
    RETURN NUMBER
    IS
      my_count_result NUMBER(18);
    BEGIN
       SELECT NVL(SUM(vehicle_count), 0 )
       INTO my_count_result
       FROM
            SELECT site_lane_id
            FROM   edr_rpt_tmp_report_lanes
            WHERE  edr_rpt_tmp_report_lanes.output_lane_id        = in_lane_id
              AND  edr_rpt_tmp_report_lanes.output_direction_id   = in_direction_id
           ) report_lanes
       JOIN edr_cls_by_tawt_report_data
         ON edr_cls_by_tawt_report_data.site_lane_id          = report_lanes.site_lane_id
       WHERE edr_cls_by_tawt_report_data.bin_start_date_time >= in_interval_start_date_time
         AND edr_cls_by_tawt_report_data.bin_start_date_time <  in_interval_end_date_time
         AND edr_cls_by_tawt_report_data.group_weight >= in_axle_wt_min
         AND edr_cls_by_tawt_report_data.group_weight  < in_axle_wt_max 
         AND edr_cls_by_tawt_report_data.vehicle_class >= in_class_min
         AND edr_cls_by_tawt_report_data.vehicle_class <= in_class_max
       RETURN my_count_result;
    END;
    FUNCTION get_row_class_counts_text
    RETURN VARCHAR2
    IS
       my_row_counts_text  VARCHAR2(10000);
       my_row_counts_entry  VARCHAR2(10000);
       CURSOR row_counts_text IS
         SELECT 'edr_rpt_class_by_tawt_package.class_count('
                           ||'lane_id, '
                           ||'direction_id, '
                           ||'interval_start_date_time, '
                           ||'interval_end_date_time, '
                           ||'range_low, '
                           ||'range_high, '
                           || class_id || ', '
                           || class_id || ') "'|| class_id || '"'
         FROM edr_rpt_tmp_report_classes
         ORDER BY class_id;
    BEGIN
      my_row_counts_text   := '';
      my_row_counts_entry  := '';
      -- generate the speed ranges function calls
      OPEN row_counts_text;
      LOOP
        FETCH row_counts_text INTO my_row_counts_entry;
        EXIT WHEN row_counts_text%NOTFOUND;
        my_row_counts_text := my_row_counts_text || ', ' || my_row_counts_entry;
      END LOOP;
      CLOSE row_counts_text;
      RETURN my_row_counts_text;
    END;
    FUNCTION get_row_totals_text
    RETURN VARCHAR2
    IS
       my_row_count_total_text  VARCHAR2(10000);
    BEGIN
      my_row_count_total_text := '';
      -- generate the 'total' column function call
      SELECT 'edr_rpt_class_by_tawt_package.class_count('
                           ||'lane_id, '
                           ||'direction_id, '
                           ||'interval_start_date_time, '
                           ||'interval_end_date_time, '
                           ||'range_low, '
                           ||'range_high, '
                           || MIN(class_id) || ', '
                           || MAX(class_id) || ') " "'
      INTO my_row_count_total_text
      FROM edr_rpt_tmp_report_classes;
      RETURN ', ' || my_row_count_total_text;
    END;
    PROCEDURE apply_default_awt_ranges(in_report_parameter_id   IN   NUMBER)
    IS
      my_awt_ranges_count NUMBER(4);
    BEGIN
    SELECT nvl(count(1),0)
    INTO my_awt_ranges_count
    FROM report_range_parameters
    WHERE REPORT_PARAMETER_ID = in_report_parameter_id
       AND REPORT_PARAMETER_GROUP = 'AXLE_GROUP'
       AND REPORT_PARAMETER_NAME = 'AXLE_NAME';
    IF  ( my_awt_ranges_count = 0 )
    THEN
      INSERT INTO report_range_parameters (REPORT_PARAMETER_ID, REPORT_PARAMETER_GROUP, REPORT_PARAMETER_NAME, REPORT_PARAMETER_MIN_VALUE, REPORT_PARAMETER_MAX_VALUE)
        VALUES (in_report_parameter_id, 'AXLE_GROUP', 'AXLE_NAME', '0', '2');
        VALUES (in_report_parameter_id, 'AXLE_GROUP', 'AXLE_NAME', '30', '32');
    END IF;
    END;
    PROCEDURE edr_class_by_tawt_use_per_veh
       in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
       in_good_status_mask      IN      NUMBER
    IS
    max_axle_group_value NUMBER(12);
    BEGIN
      DELETE FROM edr_cls_by_tawt_report_data;
      COMMIT;
      INSERT INTO edr_cls_by_tawt_report_data
                      site_id,
                      site_lane_id,
                      site_direction_id,
                      site_direction_name,
                      bin_start_date_time,
                      group_weight,
                      bin_id,
                      bin_value
      SELECT site_id,
             site_lane_id,
             site_direction_id,
             site_direction_name,
             date_time,
             group_weight,
             vehicle_class,
             COUNT(vehicle_class)
      FROM
               SELECT edr_cls_by_tawt_per_veh_data.*
                 FROM edr_cls_by_tawt_per_veh_data          
         GROUP BY date_time,
               site_lane_id,
               group_weight,
               vehicle_class,
               site_id,
               site_direction_id,
               site_direction_name;
    END edr_class_by_tawt_use_per_veh;
    PROCEDURE edr_class_by_tawt_data_type
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      in_good_status_mask      IN      NUMBER,
      in_data_type             IN      VARCHAR2,
      out_data_type_used          OUT  VARCHAR2
    IS
      my_bin_entry_count   NUMBER(12,0);
      my_veh_entry_count   NUMBER(12,0);
    BEGIN
      IF(UPPER(in_data_type) = 'BINNED') THEN
        --  Axle information can only be read from Per Vehicle data records
        --   - using bins-only is not a supported option
        RAISE_APPLICATION_ERROR(-20101,'Binned data cannot be used for this report.');
      ELSIF    (UPPER(in_data_type) = 'PERVEHICLE')
            OR (UPPER(in_data_type) = 'COMBINED')
      THEN
        out_data_type_used := 'Per Vehicle (All Vehicles)';
        edr_class_by_tawt_use_per_veh( in_report_parameter_id, in_good_status_mask );
      ELSE
         RAISE_APPLICATION_ERROR(-20101,'The data type specified is not recognized.');
      END IF;
    END edr_class_by_tawt_data_type;
    PROCEDURE edr_class_by_tawt_get_veh_data
      in_report_parameter_id   IN   NUMBER,
      in_site_id               IN   NUMBER,
      in_start_date_time       IN   TIMESTAMP,
      in_end_date_time         IN   TIMESTAMP,
      in_report_level_min      IN   NUMBER,
      in_report_level_max      IN   NUMBER
    IS
    BEGIN
      DELETE FROM edr_cls_by_tawt_per_veh_data;
      INSERT INTO edr_cls_by_tawt_per_veh_data
              site_id,
              site_lane_id,
              site_direction_id,
              site_direction_name,
              record_id,
              date_time,
              group_weight,
              vehicle_class,
              group_number,
              vehicle_status,
              vehicle_error_count,
              axle_violations_count,
              group_type         
      SELECT axle_info.site_id,
             axle_info.site_lane_id,
             axle_info.site_direction_id,
             axle_info.site_direction_name,
             axle_info.record_id,
             axle_info.datetime,
             axle_info.group_weight,
             axle_info.v_class,
             axle_info.group_number,
             NVL((SELECT SUM(status_code)
                    FROM traffic_status
                   WHERE traffic_status.record_id = axle_info.record_id), 0) vehicle_status,
             NVL((SELECT COUNT(error_code)
                    FROM traffic_error
                   WHERE traffic_error.record_id = axle_info.record_id), 0) vehicle_error_count,
             NVL((SELECT COUNT(1)
                    FROM axle_weight_violation
                   WHERE axle_weight_violation.record_id = axle_info.record_id), 0) axle_violations_count,
             axle_info.group_type           
        FROM (SELECT site_to_data_source_lane_v.site_id,
                     site_to_data_source_lane_v.site_lane_id,
                     site_to_data_source_lane_v.site_direction_id,
                     site_to_data_source_lane_v.site_direction_name,
                     traffic_record.record_id,
                     traffic_record.datetime,
                     NVL(traffic_class.v_class, 0)   v_class,
                     NVL(axle_class.group_type, 0)   group_type,
                     NVL(axle_class.group_number, 0) group_number,               
                     NVL(TRUNC(sum(convert_units(axle.weight_unit_id,
                                             c_kips_conversion_unit_id,
                                             axle.axle_weight
                           0
                         ) group_weight
               FROM  traffic_record
               JOIN  site_to_data_source_lane_v
                 ON  traffic_record.data_source_id = site_to_data_source_lane_v.data_source_id
                AND  traffic_record.lane = site_to_data_source_lane_v.data_source_lane_id                   
           GROUP BY site_to_data_source_lane_v.site_id,
                     site_to_data_source_lane_v.site_lane_id,
                     site_to_data_source_lane_v.site_direction_id,
                     site_to_data_source_lane_v.site_direction_name,
                     traffic_record.record_id,
                     traffic_record.datetime,
                     traffic_class.v_class,                
                     axle_class.group_type,
                     axle_class.group_number
            ) axle_info
    END edr_class_by_tawt_get_veh_data;
    PROCEDURE gen_class_by_axle_type
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      apply_default_awt_ranges(in_report_parameter_id);
      my_date_format_mask   := edr_rpt_generic_package.edr_rpt_get_date_format_mask(in_report_parameter_id);
      my_start_date_time    := edr_rpt_generic_package.edr_rpt_get_start_date_time(in_report_parameter_id, my_date_format_mask);
      my_end_date_time      := edr_rpt_generic_package.edr_rpt_get_end_date_time(in_report_parameter_id, my_date_format_mask);
      my_lane_grouping      := edr_rpt_generic_package.edr_rpt_get_lane_grouping(in_report_parameter_id);
      my_site_id            := edr_rpt_generic_package.edr_rpt_get_site_id(in_report_parameter_id);
      my_selected_data_type := edr_rpt_generic_package.edr_rpt_get_data_type(in_report_parameter_id);
      -- ensure selected classes and lanes temp tables have been populated
      edr_rpt_generic_package.edr_rpt_gen_tmp_lanes(in_report_parameter_id);
      edr_rpt_generic_package.edr_rpt_gen_tmp_classes(in_report_parameter_id);
      edr_rpt_generic_package.edr_rpt_gen_tmp_speed_ranges(in_report_parameter_id);
      my_good_weight_statuses_mask   := edr_rpt_generic_package.get_good_weight_status_mask(in_report_parameter_id);
      edr_rpt_generic_package.edr_rpt_gen_inclusion_table
        in_report_parameter_id,
        my_date_format_mask,
        my_start_date_time,
        my_end_date_time
      edr_rpt_generic_package.edr_rpt_gen_grouping_table
        in_report_parameter_id,
        my_date_format_mask,
        my_start_date_time,
        my_end_date_time
      edr_class_by_tawt_get_veh_data
        in_report_parameter_id,
        my_site_id,
        my_start_date_time,
        my_end_date_time,
        0,                          --Hardcoded until reclassification is supported.
        0                           --Hardcoded until reclassification is supported.
      edr_class_by_tawt_data_type
        in_report_parameter_id,
        my_good_weight_statuses_mask,
        my_selected_data_type,
        my_used_data_type
      edr_rpt_generic_package.gen_rpt_by_ranges_output_table
        in_report_parameter_id,
        'AXLE_GROUP',
        'AXLE_NAME'
      COMMIT;
      my_report_data_statement :=
          ' SELECT rank "Rank", '
        ||       ' row_type "Row Type", '
        ||       ' interval_start_date_time "Date", '
        ||       ' interval_start_date_time, '
        ||       ' range_label "Chart X-Axis", '
        ||       ' lane_id "Group Id" , '
        ||       ' ''None'' "Group Name", '
        ||       ' range_label "Speed (mph)" '
        ||         get_row_class_counts_text
        ||         get_row_totals_text
        ||       ' FROM edr_rpt_by_ranges_output '
        ||       ' ORDER BY lane_id, '
        ||                ' direction_id, '
        ||                ' interval_start_date_time, '
        ||                ' range_high, '
        ||                ' rank, '
        ||                ' range_low'
      dbms_output.put_line('SQL start------------------------');
      dbms_output.put_line(my_report_data_statement);
      dbms_output.put_line('SQL end--------------------------');
      my_chart_data_statement :=
           ' SELECT range_low "X Axis", '
        ||        ' lane_id "Group" '
        ||         get_row_class_counts_text
        || ' FROM '
        || ' ( '
        || ' SELECT lane_id, '
        ||        ' direction_id, '
        ||        ' range_low, '
        ||        ' range_high, '
        ||        ' min(interval_start_date_time) interval_start_date_time, '
        ||        ' max(interval_end_date_time) interval_end_date_time '
        || ' FROM edr_rpt_by_ranges_output '
        || ' WHERE rank = 1 '
        || ' GROUP BY lane_id, direction_id, range_low,  range_high '
        || ' ) '
        || ' order by "Group", range_low '
      dbms_output.put_line('SQL start------------------------');
      dbms_output.put_line(my_chart_data_statement);
      dbms_output.put_line('SQL end--------------------------');
      SELECT my_used_data_type
        INTO my_data_type_used
        FROM SYS.DUAL;
      SELECT NVL(COUNT(DISTINCT record_id), 0)
        INTO my_per_vehicle_total
        FROM edr_cls_by_tawt_per_veh_data;
      SELECT NVL(COUNT(DISTINCT record_id), 0)
        INTO my_status_vehicle_total
        FROM edr_cls_by_tawt_per_veh_data
       WHERE vehicle_status > 0
         AND vehicle_error_count = 0;
      SELECT NVL(COUNT(DISTINCT record_id), 0)
        INTO my_error_vehicle_total
        FROM edr_cls_by_tawt_per_veh_data
       WHERE vehicle_error_count > 0;
      SELECT NVL(COUNT(DISTINCT record_id), 0)
        INTO my_status_clear_total
        FROM edr_cls_by_tawt_per_veh_data
       WHERE vehicle_status = 0
         AND vehicle_error_count = 0;
      SELECT NVL(COUNT(1), 0)
        INTO my_binned_vehicle_total
        FROM edr_cls_by_tawt_per_veh_data;
      SELECT NVL(COUNT(1), 0)
        INTO my_good_weight_total
        FROM edr_cls_by_tawt_per_veh_data
       WHERE vehicle_error_count = 0
         AND BITAND(vehicle_status, my_good_weight_statuses_mask) = 0;
      -- insert vehicle totals into the temporary table
      DELETE FROM edr_rpt_tmp_veh_totals_table;
      INSERT INTO edr_rpt_tmp_veh_totals_table
      SELECT my_data_type_used,
             my_per_vehicle_total,
             my_binned_vehicle_total,
             my_error_vehicle_total,
             my_status_vehicle_total,
             my_good_weight_total,
             my_status_clear_total
        FROM SYS.DUAL;
      -- execute the query into the output refcursor
      OPEN report_data FOR
        my_report_data_statement;
      OPEN chart_data FOR
        my_chart_data_statement;
      OPEN footer_data FOR
        SELECT data_type_used,
               per_vehicle_total,
               binned_vehicle_total,
               error_vehicle_total,
               status_vehicle_total,
               good_weight_total,
               status_clear_total
          FROM edr_rpt_tmp_veh_totals_table;
    END gen_class_by_axle_type;
    PROCEDURE edr_rpt_gen_class_by_sawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      v_report_axle_group_type := c_axle_single_group_type;
      gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data);
    END;
    PROCEDURE edr_rpt_gen_class_by_fawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      v_report_axle_group_type := c_front_axle_only ;
      gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data);
    END;
    PROCEDURE edr_rpt_gen_class_by_tawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      v_report_axle_group_type := c_axle_tandem_group_type;
      gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data);
    END;
    PROCEDURE edr_rpt_gen_class_by_triawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      v_report_axle_group_type := c_axle_tridem_group_type;
      gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data);
    END;
    PROCEDURE edr_rpt_gen_class_by_qawt (
      in_report_parameter_id   IN      report_tasks.report_task_id%TYPE,
      report_data              OUT     SYS_REFCURSOR,
      chart_data               OUT     SYS_REFCURSOR,
      footer_data              OUT     SYS_REFCURSOR
    AS
    BEGIN
      v_report_axle_group_type :=  c_axle_quadrem_group_type;
      gen_class_by_axle_type(in_report_parameter_id, report_data, chart_data, footer_data);
    END;
    END edr_rpt_class_by_tawt_package;
    LIST
    SHOW ERROR

    Hi,
    PLS-00304: cannot compile body of 'EDR_RPT_CLASS_BY_TAWT_PACKAGE'
    without its specificationThis error usually indicates an issue with used datatypes in a package spec. that differs from a package body.
    Check your spec:
    FUNCTION  class_count
      in_lane_id                  edr_rpt_by_ranges_output.lane_id%TYPE,
      in_direction_id             edr_rpt_by_ranges_output.direction_id%TYPE,
      in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_interval_end_date_time   edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_axle_wt_min              edr_cls_by_tawt_report_data.group_weight%TYPE,
      iin_axle_wt_max             edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_class_min                edr_cls_by_tawt_report_data.vehicle_class%TYPE,
      in_class_max                edr_cls_by_tawt_report_data.vehicle_class%TYPE
    RETURN VARCHAR2; However in your package body:
    FUNCTION  class_count
      in_lane_id                  edr_rpt_by_ranges_output.lane_id%TYPE,
      in_direction_id             edr_rpt_by_ranges_output.direction_id%TYPE,
      in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_interval_end_date_time   edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
      in_axle_wt_min              edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_axle_wt_max              edr_cls_by_tawt_report_data.group_weight%TYPE,
      in_class_min                edr_cls_by_tawt_report_data.vehicle_class%TYPE,
      in_class_max                edr_cls_by_tawt_report_data.vehicle_class%TYPE
    RETURN NUMBERReturn number in spec. vs. return varchar2 in body..
    That won't compile, either return a number or a varchar2 in both. (spec and body).

  • How to divide resultset of a query in different ref cursors in a package

    Hi Oracle Gurus,
    I need to create a package which counts the no of rows returned by a select query on multiple tables and according to the returned rowcount inputs the resultset in a ref cursor. Procedure will be called by a .NET program and output param refcursor will be assigned to a data reader which will redirect all the data to an Excel file.
    All the above is done. Issue is due to Excel's limit of 64000 rows, if data returned by query is greater than 64K it wont be fit in 1 Excel sheet. So, in order to overcome this limit I need to do some looping in Oracle package which keeps on storing the query results (rows<64K) in different ref cursors so that these refcursors as OUT params can be redirected to separate Excel sheets in C# program.
    NOTE : Earlier on I created 2 procedures in the package to fetch rows<64K and another one to fetch rows between 64K and rowcount of the query. My program was calling 2 different procedures to redirect data into 2 diff Excel sheets.
    But this fails when query resultset is even greater than 128000 or more and demands 3-4 or even more Excel sheets to be created.
    Please help.
    Any idea how to do looping in Oracle to accomplish this?

    > So, in order to overcome this limit I need to do some looping in Oracle package which keeps on
    storing the query results (rows<64K) in different ref cursors so that these refcursors as OUT params
    can be redirected to separate Excel sheets in C# program.
    Huh?
    That is saying that "I need to change this road and build it straight through that lake as the road has a curve here".
    It surely is a LOT easier to leave the road as is and simply turn the darn steering wheel in the car?
    Have the .Net data reader keep a row count of rows read from the ref cursor - and when it reached a pre-set max, have the reader do a "control break"[1] and change to a new worksheet as the destination for writing the rows to.
    [1] Google the term if you do not understand this basic concept that was among the very basic program control structures taught back in the 80's.. while I foam at the mouth how today's "wonder kids" turned programmers, that grew up with computers, do not even comprehend the most basic programming logic designs...

  • JDBC gives error if accessing Package Synonym

    Calling a stored procedure in a package using JDBC...
    Where we are using a synonym for our package (given all permissions are OK - I've even tried SYSDBA) rather than calling procedures directly in the package, we get the error 'table or view does not exist'.
    This error only occurs for procedures in the package which return ref cursor type (i.e. a recordset), otherwise the procedure seems to execute fine.
    The same procedures can happily be used via ODBC and OLEDB using the synonym, so I suspect it is JDBC at fault.
    We do need to use a synonym (I like to keep nice clean tidy schemas!) so if anyone knows how to get around it or whether the bug will be fixed shortly please let us know.
    Regards
    Jason.
    null

    Hi,
    Returning refcursors from Java stored proc feature is planned for JDBC 8.2.
    Hope this helps,
    -Kishore

  • REFCURSOR in getCursor CallableStatement

    Hi ,
    I am calling a stored package procedure which returns REFCursor (i am using oracle 8.1.6 as backend) throughjdbc
    am importing the Oracle JDBC drivers which support bind variables of type REFCURSOR.(classes from the oracle.jdbc.driver package
    8.1.7 driver)
    Used the getCursor method of the CallableStatement to convert a REFCURSOR value returned by a PL/SQL block
    into a ResultSet.
    Casting the corresponding CallableStatement to oracle.jdbc.driver.OracleCallableStatement to use the getCursor method.
    The problem is this works absolutely fine if i connect as the owner of the package procedure. but if i create a public syonym for the same package and grant execute
    on package to other user.
    And now if i connect as this other user through jdbc and run the same program it gives me SQLException
    ora-00942 table or view does not exit.
    (and the same thing works fine from sql*plus when the package is tested from thsi other) just to inform you that no grants / rights issues over here.
    I am just unable to understand how do i proceed in this case, as no way i can have the package procedure being created in the same user, also doesn't sound
    implementable in live environment.
    Can any body confirm, if this is a bug in the dirver am using, and if so where do i find this
    Please help me.
    I hope i have given required info to get an answer.
    Thanks. Geeta
    null

    I had the same problem. It only worked
    for me if I granted both execute
    permission on the Package as well as
    select permission on the table accessed
    by the package (which doesn't make sense)
    null

  • Execute store procedure( in Id, in out RefCursor), and data fetched in ref cursor should be sent out as excel sheet.

    I am trying to make a ssis package that get the data calling the store proc with two param one is ID and other is Sys_refcursor. Say Store Proc as ListName(Id int, myCur sys_refcursor), which gets the datas with the conditions inside it.
    REATE OR REPLACE PROCEDURE schemaName.LISTNAME (P_ID  IN INT, LST_NAME_REFCUR   IN OUT SYS_REFCURSOR)
    IS
    P_NAMESOURCE_ID INT;
    BEGIN
        SELECT SOURCE_ID INTO P_NAMESOURCE_ID FROM SEARCHING_TABLE ST WHERE ST.ID = P_ID;           
                   IF (P_NAMESOURCE_ID=1)
                   THEN
                      OPEN LST_SOURCE_REFCUR FOR 
                            SELECT ST.ID,
                                   ST.TRANSACTION_DATE AS TRAN_DATE,
              IF (P_NAMESOURCE_ID=1)
                   THEN 
                      OPEN LST_SOURCE_REFCUR FOR             ....     
    then i need to get the data from that refcursor and fetch those data to excel sheet to a virtual directory.
    Any help would be appreciated. I am new to SSIS. and i need to do this assignment this friday. 

    Hi 11srk,
    To fetch data from Oracle store procedure, you can use a Script Component as source to call the Oracle stored procedure by using System.Data.OracleClient OracleDataReader, and get the rows and add them to the pipeline buffer. For more information, please
    see:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d0b3a1b-8792-469c-b0d1-f2fbb9e9ff20/dump-oracle-ref-cursor-into-ms-sql-staging-table-using-ssis
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/fcdaa97e-8415-4c3e-8ffd-1ad45b590d57/executing-an-oracle-stored-procedure-from-ssis?forum=sqlintegrationservices
    http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(VS.90).aspx  
    Regards,
    Mike Yin
    TechNet Community Support

  • Why do RefCursors return result sets in reverse order?

    Oracle XE version 10.2.0.1 (both windows and Linux perform the same).
    I'm porting code from DB2 to Oracle - our environment is mostly stored procedures returning REFCURSORS to a java layer. Many of the stored procedures return more than one REFCURSOR (please no posts on the value of packages vs procs, I understand the benefit but cannot switch at this time to packages). It took me a while to figure this out, but it appears that the cursors are returned in reverse order of their OUT param position(s). My fear is that this isn't always the case, but that the cursors could be open in some random order, in which case any conditional processing I have would need to account for that. Anyone experience this? Or can any Oracle guru explain why the cursors are open in reverse order? At this point in time, I do need to process them positionally rather than naming them -
    Here's a test case:
    CREATE TABLE TESTCUR(
    col1 NUMBER,
    col2 VARCHAR2(50)
    INSERT INTO TESTCUR VALUES (1, 'value for cursor 1');
    INSERT INTO TESTCUR VALUES (2, 'value for cursor 2');
    INSERT INTO TESTCUR VALUES (3, 'value for cursor 3');
    CREATE OR REPLACE PROCEDURE TESTREFCURSORMULTI (
      testcasenumber IN NUMBER,
      cv_1 OUT SYS_REFCURSOR,
      cv_2 OUT SYS_REFCURSOR,
      cv_3 OUT SYS_REFCURSOR
    AS
    BEGIN
         IF testcasenumber = 1 THEN
         OPEN cv_1 FOR
              SELECT col2
              FROM TESTCUR
              WHERE col1 = 1;
         OPEN cv_2 FOR
              SELECT * FROM DUAL WHERE 1=0;
         OPEN cv_3 FOR
              SELECT * FROM DUAL WHERE 1=0;
         ELSE
              IF testcasenumber = 2 THEN
              OPEN cv_1 FOR
                   SELECT col2
                   FROM TESTCUR
                   WHERE col1 = 2;
              OPEN cv_2 FOR
                   SELECT * FROM DUAL WHERE 1=0;
              OPEN cv_3 FOR
                   SELECT * FROM DUAL WHERE 1=0;
              ELSE
                   OPEN cv_1 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 1;
                   OPEN cv_2 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 2;
                   OPEN cv_3 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 3;
              END IF;
         END IF;
    END;
    set autoprint on
    var rc1 refcursor
    var rc2 refcursor
    var rc3 refcursor
    begin
    TESTREFCURSORMULTI(
    testcasenumber => 3,
    cv_1 => :rc1,
    cv_2 => :rc2,
    cv_3 => :rc3)
    end;
    /     Here are the results when opening all three:
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    COL2
    value for cursor 3
    COL2
    value for cursor 2
    COL2
    value for cursor 1Results when opening 1:
    SQL> set autoprint on
    SQL> var rc1 refcursor
    SQL> var rc2 refcursor
    SQL> var rc3 refcursor
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 1,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    no rows selected
    no rows selected
    COL2
    value for cursor 1

    It nothing more but the way how AUTOPRINT works:
    SQL>  set autoprint on
    SQL> var rc1 refcursor
    SQL> var rc2 refcursor
    SQL> var rc3 refcursor
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    COL2
    value for cursor 3
    COL2
    value for cursor 2
    COL2
    value for cursor 1
    SQL> set autoprint off
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> print rc1
    COL2
    value for cursor 1
    SQL> print rc2
    COL2
    value for cursor 2
    SQL> print rc3
    COL2
    value for cursor 3
    SQL> As you can see, right cursor returned right result, just autoprint in case of multiple variables prints results starting last open cursor:
    SQL> set autoprint on
    SQL> begin
      2  open :rc1 for 'select 1 from dual';
      3  open :rc2 for 'select 2 from dual';
      4  open :rc3 for 'select 3 from dual';
      5  end;
      6  /
    PL/SQL procedure successfully completed.
             3
             3
             2
             2
             1
             1
    SQL> begin
      2  open :rc3 for 'select 3 from dual';
      3  open :rc2 for 'select 2 from dual';
      4  open :rc1 for 'select 1 from dual';
      5  end;
      6  /
    PL/SQL procedure successfully completed.
             1
             1
             2
             2
             3
             3
    SQL> SY.

  • Use of REFCURSOR between procedures

    Hi
    I have a packaged procedure get_data and another write_data, is the use of a REFCURSOR the best way to pass/reference the data between each?
    Code snippets:
    create or replace
    PACKAGE BODY              pkg_test as
    TYPE rc_test IS REF CURSOR;
    PROCEDURE get_data(out_retcur OUT SYS_REFCURSOR)
    IS
    BEGIN
      OPEN out_retcur
      FOR SELECT col1
                ,col2
             FROM test_table;
    END get_data;
    PROCEDURE write_data
    IS
    rc rc_test;
    rec test_table%ROWTYPE;
    BEGIN
      get_data(rc);
      LOOP
      <<process_data>>
        FETCH rc INTO rec;
        EXIT WHEN rc%NOTFOUND;
        UTL_FILE.put_line ...
      END LOOP process_data;
      CLOSE rc;
    END write_data;
    END pkg_test;Cheers
    Si

    ScoobySi wrote:
    Can you please explain a bit, how does a view help if I want to separate the get and write into two different procedures?Your get appears to consist solely of a select statement, if so a view is better than a stored procedure.
    Your write assumes one row at a time processing, which is the slowest way of doing anything, if you are fine with that then it is no problem. If someone wanted to use the get_data view efficiently however they could, if it is a procedure they will be forced to use it as inefficiently as you plan to.
    It depends on whether you want to do this the best way or whether you you want to write two different procedures.

Maybe you are looking for

  • How can I restore FileGlobals in a Client Sequence File that is reloaded?

    Hi, I'm using TS2.0.1f1 and dynamic client files (search "DynamicClientModel" to see an example) in order to load different test sequences depending on what product should be tested. We do something like this, newseq = IEngine.GetSequenceFile(...) Ex

  • ARD 3 Will Not Install "The serial number is not valid"

    Hello, and thanks for reading. I am a new network admin in a silicon valley school district. I come from a Windows background and I am picking up the Mac pretty well. I was asked by the support team to install Apple Remote Desktop 3 on my MacBook Pro

  • Not getting Result please Help

    Hi All query_string VARCHAR2(2000); query_string are EMPNO,ENAME for rec1 in (SELECT query_string FROM p_table_name ) loop utl_file.put_line(v_file, rec1.result1); END LOOP; not getting Result please Help Regards

  • Duplicating multiple sets of seperately linked layers results in all layers being linked together

    This has been an issue for a while now, I found an old thread from 2011 about the same problem and the mod reported it to the devs, but as far as I know no solution has ever been offered. (maybe in cs6? we are still using cs5) For one or two layers i

  • Passing arguments to JVM from eclipse

    When running a program from eclipse, I get an error like java.lang.UnsatisfiedLinkError: no driJNI in java.library.path I tried the -Djava.library.path={whatever} in the VM arguments. However, I still get the error of unsatisfied link. When try setti