Ref cursor returns login ids

I have this ref cursor that returns login ids from a procedure.
While I can define the ref cursor as sys_refcursor; I want to use strongly typed ref cursor ( for improved readabilty of code).
But I guess I can not define the cursor that returns %type.
e.g. Type return_login_id IS REF CURSOR return tab1.login_id%type;
On compilation the package threw an error saying the return type should be record.
I need to define a record with one column and use that as return type ?
any other way around ?
TIA
S

Btw, why you need to use REF Cursor?
You can use just a cursor:
SQL> declare
  2  cursor c1 is select empid from emp;
  3  TYPE my_id IS TABLE OF emp.empid%type;
  4  myid my_id := my_id();
  5  BEGIN
  6  OPEN c1;
  7  FETCH c1 BULK COLLECT INTO myid;
  8  CLOSE c1;
  9  END;
10  /
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • Creating a function having a ref cursor returned

    I get an error message for the following code below. I am trying to create a function that allows the users to pass in a certain parameter which is used to invoke a specific query for the paramented passed in. Once the query is invoked, it should return a ref cursor. Please help. I am still using pl/Sql developer.
    create or replace package TEST2 is
    type rec_DropDownList_Item is RECORD(
    TEXT_TYPE VARCHAR2(200),
    xsVALUE VARCHAR2(200));
    TYPE cur_DropDownList IS REF CURSOR RETURN rec_DropDownList_Item;
    FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2) RETURN cur_DropDownList;
    end TEST2;
    create or replace package body TEST2 is
    FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2)
    RETURN cur_DropDownList IS
    my_ref_cursor cur_DropDownList;
    BEGIN
    OPEN my_ref_cursor FOR
    SELECT vehicletype, vehicledescription
    FROM cars where vehicletype = need_type;
    return my_ref_cursor;
    END Getprocedure_yearreportdisplay;
    end TEST2;

    user13046875 wrote:
    a simple example might help because I am having a difficult understanding the reply. Thank you.
    create or replace package TEST2 is
       type rec_DropDownList_Item is RECORD(
       TEXT_TYPE VARCHAR2(200),
       xsVALUE VARCHAR2(200));
       TYPE cur_DropDownList IS REF CURSOR RETURN rec_DropDownList_Item;
       FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2) RETURN cur_DropDownList;
    end TEST2;
    create or replace package body TEST2 is
    FUNCTION Getprocedure_yearreportdisplay (need_type in VARCHAR2)
    RETURN cur_DropDownList IS
    my_ref_cursor cur_DropDownList;
    BEGIN
       OPEN my_ref_cursor FOR
       SELECT 'column1', 'column2'
       FROM dual;
       return my_ref_cursor;
    END Getprocedure_yearreportdisplay;
    end TEST2;
    TUBBY_TUBBZ?variable x refcursor;
    TUBBY_TUBBZ?
    TUBBY_TUBBZ?exec :x := TEST2.Getprocedure_yearreportdisplay('dummy');
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?print :x
    'COLUMN 'COLUMN
    column1 column2
    1 row selected.
    Elapsed: 00:00:00.03
    TUBBY_TUBBZ?Is an example of running in SQLPLUS (you may want to get your own copy, it's free and available on OTN).

  • How to read my cursor that is ref cursor returning user defined type

    Hi
    I have types defined as follows:
    TYPE MY_RECORD IS RECORD (
    COL1 TABLE1.COL1%TYPE,
    COL2 TABLE1.COL2%TYPE
    TYPE MY_CURSOR IS REF CURSOR
    RETURN MY_RECORD;This is used as return type in a stored procedure.
    I have a pl/sql block where I make a call to the SP that returns this cursor.
    How can I read individual values being returned from SP?

    SQL> create or replace package pkg
    as
       type my_record is record (col1 emp.empno%type, col2 emp.ename%type);
       type my_cursor is ref cursor
          return my_record;
       procedure p (cur out my_cursor);
    end pkg;
    Package created.
    SQL> create or replace package body pkg
    as
       procedure p (cur out my_cursor)
       as
       begin
          open cur for
             select   empno, ename
               from   emp
              where   rownum <= 2;
       end p;
    end pkg;
    Package body created.
    SQL> declare
       cur     pkg.my_cursor;
       e_rec   pkg.my_record;
    begin
       pkg.p (cur);
       loop
          fetch cur into   e_rec;
          exit when cur%notfound;
          dbms_output.put ('Empno: ' || e_rec.col1);
          dbms_output.put_line ('; Ename: ' || e_rec.col2);
       end loop;
       close cur;
    end;
    Empno: 7369; Ename: SMITH
    Empno: 7499; Ename: ALLEN
    PL/SQL procedure successfully completed.

  • Ref cursor return type

    i am using a ref cursor as out parameter in a stored procedure.
    When I call the stored procedure and want to retrieve the rows returned by the ref cursor,
    is there a way to fetch the records using something like %ROWTYPE if I donot know the type of rows returned by the cursor.
    eg.
    procedure my_test_ref_cursor ( a OUT SYS_REFCURSOR) IS
    BEGIN
    OPEN a FOR SELECT EMP_ID, EMP_NAME FROM EMP;
    END;
    procedure call_my_test_ref_cursor is
    b sys_refcursor;
    begin
    my_test_ref_cursor(b);
    fetch b into XXXXXXX - if this program doesnot know the type of ref cursor 'b' is pointing to is there a way to use
    something like %ROWTYPE here ?
    end;

    While you can use the logic to return a weakly typed reference cursor, there should be a compelling why. A strongly typed reference cursor may be a better solution. You define a strongly typed reference cursor inside a package, and you anchor it to a ROWTYPE. Weakly typed reference cursors are typically useful when you are working with a subset of a table because you can't anchor to part of a table. However, you can define a view that uses the portion of the table and anchor a strongly typed reference cursor to the view.
    A strongly typed PL/SQL reference cursor is defined like this in a package specification:
    TYPE strongly_typed_cursor IS REF CURSOR RETURN some_table%ROWTYPE;
    So, if you rewrote it like this ...
    PROCEDURE my_test_ref_cursor (a OUT SOME_PACKAGE.STRONGLY_TYPED_CURSOR) IS
    BEGIN
    OPEN a FOR SELECT emp_id, emp_name FROM emp;
    END;
    Now, you can access it like this ...
    PROCEDURE call_my_test_ref_cursor IS
    another_var SOME_PACKAGE.STRONGLY_TYPED_CURSOR;
    target SOME_TABLE%ROWTYPE;
    BEGIN
    my_test_ref_cursor(another_var);
    LOOP
    FETCH another_var INTO target;
    EXIT WHEN another_var%NOTFOUND;
    dbms_output.put_line('See it '||target.emp_name||'.');
    END LOOP;
    END;
    The DBMS_SQL method you're looking for is Method 4. My recollection is that there isn't a good example in the docs but I could be wrong ... The OCI works no differently, nor does the JDBC interface. Hope this helps.

  • Pro*C program to use a REF CURSOR returned by a DB Function

    Hi,
    Please help me with this.
    I have a pro*c program that should call a
    database function which returns a ref cursor.
    This is the sample code i have :-
    EXEC SQL BEGIN DECLARE SECTION;
    SQL_CURSOR emptycabin_cursor;
    int cabinid;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL ALLOCATE :emptycabin_cursor;
    EXEC SQL EXECUTE BEGIN
    :emptycabin_cursor:=posremptycabin(:voy,:segid);
    END;END-EXEC;
    /* more_records = 1*/
    while (more_records)
    EXEC SQL FETCH :emptycabin_cursor INTO :cabinid;
    if (SQLCODE==NOTFOUND)
    {more_records=FALSE;break;}
    EXEC SQL close :emptycabin_cursor;
    When I execute I keep getting fetch out of sequence error.
    Can someone let me know whats wrong with this code?
    When I execute the function from sqlplus
    variable ref_cur refcursor ;
    exec :ref_cur:=posremptycabin(232,'CC');
    print :ref_cur;
    I get the data properly displayed.So nothing wrong with the function.
    Thanks for your help

    I know nothing about Pro*C, but Tom Kyte's Pro*C example for ref cursors fetches the cursor with a loop that looks like:
    for( ;; )
            EXEC SQL WHENEVER NOTFOUND DO break;
            EXEC SQL FETCH :my_cursor INTO :ename, empno;
            printf( "'%.*s', %d\n", ename.len, ename.arr, empno );
        EXEC SQL CLOSE :my_cursor;http://asktom.oracle.com/~tkyte/ResultSets/index.html
    Hope this helps.

  • REF CURSOR RETURNED FROM STORED PROCEDURE OPENED WITH CURRENT_USER PRIVILEGES

    Hi.
    I was wondering if anyone knows when this bug will be fixed. The bug# is 899567 off of metalink.
    I am running into this problem as well, and we do not want to use OCI/SQLNet as the fix. We have an application with secure data concerns and only want to give access to stored procedures to an application user.
    Thanks,
    Brad

    I'm using version 8.1.6.0.0 on a W2K server.
    PS: a strange behaveour
    if i try to insert a row using the following anonymous pl/sql block
    begin
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    end;
    i get the following error msg
    ERROR at line 1:
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-302: component 'OBJ_T' must be declared
    but if i use only the sql command from the sql plus prompt
    insert into objects select 2, 'B', ref(c) from meta.classes c where id =1;
    the row is inserted.
    OBJ_T is the object type(id number, label varchar2, class ref class_t),
    OBJECTS is a table of obj_t,
    CLASS_T is an object type(id number, label varchar2)
    CLASSES is a table of CLASS_T.
    null

  • Error Returning REF CURSOR

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

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

  • Returning a Ref cursor as an OUT Parameter

    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptType, productCursor OUT deptType) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end;

    A Correction to the above code snippet
    Hi Guys
    I have defined 2 Types and 2 Ref cursors as shown below.I have written a procedure having 2 IN and 2 OUT parameters which are of type Ref cursors and return records to the calling client. My question is how can i test for the output of the two cursors here in pl/sql?.. also i should not close the sursors.. right?..its the job of the calling client as per my knowledge....Please suggest
    TYPE type_dept_Rec IS RECORD(deptNo varchar2);
    TYPE type_prod_Rec IS RECORD(prodType varchar2);
    TYPE deptCursor IS REF CURSOR RETURN type_dept_Rec;
    TYPE prodCursor IS REF CURSOR RETURN type_prod_Rec;
    PROCEDURE TEST (pinCode IN varchar2, prodType IN number, deptCursor OUT deptCursor, productCursor OUT prodCursor) IS
    BEGIN
    OPEN deptCursor FOR SELECT
    deptNo
    from
    DEPT
    where
    pinCode = pinCode;
    OPEN productCursor FOR SELECT
    prodCode
    from
    PROD
    where
    prodType = prodType;
    end

  • How to handle the ref cursor which is returning "no rows"

    I have written a function which is returning the REF CURSOR. But in one situation the REF CURSOR returns "no rows selected". To handle this situation an exception is raised "when no data found". But i dont know in this situation how should NULL cursor be returned through this function. Since I want to call this function in another procedure so something should be returned through this function by means of ref cursor. But since i am not able to handle this "no rows selected" situation i am not able move further.
    Thanks in advance........

    I agree.
    You would simply process the returned ref cursor irrespective of any rows actually returned in the cursor or not. You would be able to do at least one FETCH from the cursor (even if it does not actually contain any rows) and then determine the %NOTFOUND status to do the rest of the processing.
    SQL> variable cur refcursor
    SQL> exec open :cur for select * from scott.emp where rownum = 1 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980        800                    20
    1 row selected.
    SQL>
    SQL> exec open :cur for select * from scott.emp where 1 = 2 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
    no rows selected
    SQL>
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2      rec scott.emp%ROWTYPE;
      3      bol BOOLEAN;
      4      cur sys_refcursor;
      5  BEGIN
      6      OPEN cur FOR
      7          SELECT * FROM scott.emp WHERE 1 = 2; /* assume this is your function call returning a ref cursor */
      8      bol := FALSE;
      9      LOOP
    10          FETCH cur
    11              INTO rec;
    12          EXIT WHEN cur%NOTFOUND;
    13          --
    14          -- process the data here
    15          --
    16          bol := TRUE;
    17      END LOOP;
    18      CLOSE cur;
    19      IF (bol)
    20      THEN
    21          dbms_output.put_line('At least one row was found');
    22      ELSE
    23          dbms_output.put_line('No rows were selected');
    24      END IF;
    25  END;
    26  /
    No rows were selected
    PL/SQL procedure successfully completed.
    SQL>

  • How to return a table to ref cursor?

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

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

  • Number of total rows returned by a ref cursor without using FETCH

    Hi. How can we get the total number of rows returned by a ref cursor without doing the FETCH? I mean, if you use %ROWCOUNT, it only returns the current row number being returned in every fetch. This is not what I want. My purpose is to determine if my query using ref cursor returns greater than zero total rows without using fetch. Thanks.

    As John pointed out in the thread you linked to, the only way to know how many rows a query will return is to actually fetch all the rows. Oracle doesn't know how many rows a query is going to return until it actually fetches the last row.
    Plus, assuming the default transaction isolation level, if you run the same query multiple times in succession, there is no guarantee that the results will be the same.
    If you just want to know whether a query will return a nonzero number of rows, why not just write the code to assume that it returns at least 1 row and handle the zero row result as an exception.
    Justin

  • Return csv string as strongly typed ref cursor

    I have a column in a table that is csv delimited and I want to return it (and others) as a strongly typed ref cursor.
    eg
    create table test_tab (mydata varchar2(100))
    insert into test_tab(mydata) values ('"a1","b1","c1","d1"')
    insert into test_tab(mydata) values ('"a2","b2","c2","d2"')
    so test_tab has 1 column and 2 rows:
    "a1","b1","c1","d1"
    "a2","b2","c2","d2"
    So a,b,c,d represent columns in my strongly typed ref cursor
    If I then try something like:
    declare
    type my_rec is record(
    a varchar2(50),
    b varchar2(50),
    c varchar2(50),
    d varchar2(50)
    type my_rec_refc IS REF CURSOR RETURN my_rec;
    my_test_refc my_rec_refc;
    begin
    open my_test_refc for select mydata,mydata,mydata,mydata from test_tab;
    end;
    then it obviously works as my ref cursor is expecting 4 columns. However, what I want to do is break each individual element out of the mydata column. I've played around a bit with dynamic sql but only getting so far and apparently that can't be used with a ref cursor anyway. I need to return a strongly typed cursor as another program requires this.
    One option is to manually parse each row and insert into temp table that is basically definition of record (so record type no longer needed) and this becomes type of ref cursor. I can then simply select from the table. I'm not keen on this as it's just another object to worry about.
    Another option is to do some ugly instr/substr to extract each element in the sql statement (or write a function to do it but need to consider performance of this). The more generic the better as I need to reuse against multiple strongly typed ref cursors (kind of a contradiction in that by virtue of using strongly typed cursors I know exactly what I want returned!).
    Another option is for someone to shed some light on this as it must be possible to do in a simple way along the same lines I have started?
    thanks in advance

    That documentation seems to stay pretty vague. What constitutes the "right set of columns". Obviously my observed result matches what you are saying about not being able to enforce the datatypes in the fields of the strong typed cursor. But then I don't see the point of the strong typed cursor otherwise. Other sites i have read seem to focus on the %rowtype return rather than mapping it to a record. But the general consensus (at least to my understanding) is that if the cursor is strongly typed then the sql statement that used to open it must have the same set of columns and the datatypes must at least be able to implicitly convert.
    I will try the %rowtype strong ref cursor against a table and see if there is a different result. I am mainly interested in this because I would like to beable to ensure the datatype returned on the .net side through ODP
    I want to be able to know the datatype of a field coming back through a ref cursor at compile time not runtime. So it the answer to cast every field of the select statement?

  • Ref Cursor closed returning to Form

    Hi,
    I came across this old thread which seems to be an exact match for my problem.
    sys ref cursor is closed
    And whereas the solutions do work as stated there is an issue with it that i wonder if anyone here has since got around.
    Take those examples and make the sql dynamic. on return to the form the ref cursor is instantaneouly closed for you making the thing unusable.
    i.e.
    OPEN cur FOR SELECT 'x' from dual
    works just fine but
    OPEN cur FOR 'SELECT ''X'' from dual'
    resutls in an closed cursor the moment the ref cursor parameter returns to the form. I need the dynamic form because my cursor is truly built dynamically.
    Any ideas anyone?

    Hi,
    try this :
    1. declare in the package specification
    TYPE rec_view IS RECORD(
      COL1        VARCHAR2(250),
      COL2        VARCHAR2(250),
      COL3        VARCHAR2(250),
      COL4        VARCHAR2(250),
      COL5        VARCHAR2(250)
      TYPE t_ref_curs IS REF CURSOR RETURN rec_view;
      TYPE t_rec_c IS REF CURSOR;
    2. define the dynamic sql - procedure
    PROCEDURE   prc_getdata (p_refcur IN OUT t_ref_curs, p_result OUT VARCHAR2,
                             p_filter IN varchar2 DEFAULT NULL, p_orderby In VARCHAR2 DEFAULT NULL)  IS
      BEGIN
            -- dyn cursor ! --
            EXECUTE IMMEDIATE
                    'BEGIN
                          OPEN :a FOR ' ||
                              ' select empno, ename, job, mgr, hiredate, sal  from emp'||' '||
                                p_filter  ||' '||
                                p_orderby ||'; '||
                     'END;'
               USING p_refcur;
       END prc_getdata;
    3. define in the Form a PL/SQL based block on this procedure.
    Hope it helps.
    Best regards
    Friedhold

  • Dynamic sql and ref cursors URGENT!!

    Hi,
    I'm using a long to build a dynamic sql statement. This is limited by about 32k. This is too short for my statement.
    The query results in a ref cursor.
    Does anyone have an idea to create larger statement or to couple ref cursors, so I can execute the statement a couple of times and as an result I still have one ref cursor.
    Example:
    /* Determine if project is main project, then select all subprojects */
    for i in isMainProject loop
    if i.belongstoprojectno is null then
    for i in ProjectSubNumbers loop
    if ProjectSubNumbers%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    else
    for i in ProjectNumber loop
    if ProjectNumber%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    end if;
    end loop;
    /* Open ref cursor */
    open sql_output for SqlStatement;
    Thanks in advance,
    Jeroen Muis
    KCI Datasystems BV
    mailto:[email protected]

    Example for 'dynamic' ref cursor - dynamic WHERE
    (note that Reports need 'static' ref cursor type
    for building Report Layout):
    1. Stored package
    CREATE OR REPLACE PACKAGE report_dynamic IS
    TYPE type_ref_cur_sta IS REF CURSOR RETURN dept%ROWTYPE; -- for Report Layout only
    TYPE type_ref_cur_dyn IS REF CURSOR;
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn;
    END;
    CREATE OR REPLACE PACKAGE BODY report_dynamic IS
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn IS
    ref_cur_dyn type_ref_cur_dyn;
    BEGIN
    OPEN ref_cur_dyn FOR
    'SELECT * FROM dept WHERE ' | | NVL (p_where, '1 = 1');
    RETURN ref_cur_dyn;
    END;
    END;
    2. Query PL/SQL in Reports
    function QR_1RefCurQuery return report_dynamic.type_ref_cur_sta is
    begin
    return report_dynamic.func_dyn (:p_where);
    end;
    Regards
    Zlatko Sirotic
    null

  • How to give ref cursor in VB procedure call

    This is my Oracle Sp
    CREATE OR REPLACE PROCEDURE CRD_DMAN.infy_usp_trades_by_broker_bkr
    ** Procedure name: CRD_DMAN.USP_TRADES_BY_BROKER
    ** Author's name: Infosys
    ** Date written: 04/11/07
    ** Description: Compliance Trade by Borker
    ** Maintenance history:
    ** Date Chg req# Name Remarks
    ** 04/11/07 Infosys Created
    p_ordercursor IN OUT infy_pkg_compliance_transact.cur_compliancetrade,
    p_startdate IN VARCHAR,
    p_enddate IN VARCHAR,
    p_fundcode IN cs_fund_config.parent_acct_cd%TYPE,
    p_clientcode IN ts_order_alloc.acct_cd%TYPE,
    p_brokercode IN ts_order_alloc.exec_broker%TYPE,
    p_reportname IN report_log.report_name%TYPE,
    p_callingapplication IN report_log.calling_application%TYPE,
    p_callinguser IN report_log.calling_user%TYPE
    IS
    --Declaring Local Variables
    v_owner VARCHAR2 (30);
    v_startdate VARCHAR2 (10);
    v_enddate VARCHAR2 (10);
    v_rowcount NUMBER:=0;
    v_logrec base_util_pkg.crd_log_record;
    exp_error EXCEPTION;
    v_fundcodevalue NUMBER;
    BEGIN
    BEGIN
    /*checking if the start date and end date are null and
    assigning the sysdate accordingly*/
    IF (TRIM(p_startdate) IS NULL )
    THEN
    v_startdate := TO_CHAR (SYSDATE, 'mm/dd/yy');
    ELSE
    v_startdate := p_startdate;
    END IF;
    IF (TRIM(p_enddate) IS NULL )
    THEN
    v_enddate := TO_CHAR (SYSDATE, 'mm/dd/yy');
    ELSE
    v_enddate := p_enddate;
    END IF;
    /*checking if fund code is null and assigning value accordingly*/
    IF TRIM (p_fundcode) IS NULL
    THEN
    v_fundcodevalue := 0;
    ELSE
    v_fundcodevalue := 1;
    END IF;
    /*checking if the reportname or calling user or calling
    application name*/
    IF (p_reportname IS NULL OR p_callinguser IS NULL
    OR p_callingapplication IS NULL)
    THEN
    RAISE exp_error;
    END IF;
    END;
    --opening and fetching the data into cursor
    v_logrec.start_time := SYSDATE;
    BEGIN
    OPEN p_ordercursor
    FOR
    SELECT
    oa.exec_broker EXEC_BROKER_CODE,
    b.bkr_name          EXEC_BROKER_NAME,
    oa.acct_cd CLIENT_CODE,
    f.acct_name               CLIENT_NAME,
    CASE WHEN (Exists (SELECT 1
                                       FROM cs_fund_broker fb
    WHERE rel_typ_cd IN('P','M')
    AND oa.exec_broker=fb.BKR_CD
                                       AND oa.acct_cd =fb.acct_cd))
                   THEN 'Y'
    ELSE 'N' END          DIRECTED_BROKER,
    COUNT ( distinct o.order_id) COUNT_TICKNUM,
    MAX (o.trade_date) TRADE_DATE,
    SUM (oa.exec_amt)               BASE_COST,
    SUM (oa.commision_amt)          TOTAL_COMMISSION,
         (SELECT ab.bkr_typ_cd FROM au_broker ab
         WHERE ab.au_change_date =(SELECT TO_TIMESTAMP(MAX(ab.au_change_date))
         FROM au_broker ab WHERE b.bkr_typ_cd != ab.bkr_typ_cd AND b.bkr_cd = ab.bkr_cd))
                                  BROKER_HISTORY
    FROM
    ts_order o
    JOIN ts_order_alloc oa ON (o.order_id = oa.order_id)
    JOIN cs_broker b ON(oa.exec_broker = b.bkr_cd)
    JOIN cs_fund f ON(oa.acct_cd = f.acct_cd)
    WHERE
    o.status = 'ACCT'
    AND oa.exec_broker = CASE WHEN TRIM (p_brokercode) IS NULL
              THEN oa.exec_broker
              ELSE TRIM(p_brokercode) END
    AND oa.acct_cd = CASE WHEN TRIM(p_clientcode) IS NULL
    THEN oa.acct_cd
    ELSE TRIM(p_clientcode) END
         AND ((0 = v_fundcodevalue) OR EXISTS (SELECT 1 FROM crd.cs_fund_config cf
              WHERE cf.parent_acct_cd =TRIM (p_fundcode)
         AND oa.acct_cd = cf.child_acct_cd))
         AND o.trade_date BETWEEN TO_DATE (v_startdate, 'mm/dd/yy')
    AND TO_DATE (v_enddate, 'mm/dd/yy')
    GROUP BY oa.exec_broker, b.bkr_name ,oa.acct_cd ,f.acct_name,oa.directed_broker,b.bkr_typ_cd,b.bkr_cd;
    END;
    BEGIN
    SELECT
    owner
    INTO
    v_owner
    FROM
    all_objects
    WHERE
    object_name = 'INFY_USP_TRADES_BY_BROKER_BKR';
    v_logrec.end_time := SYSDATE;
    v_logrec.user_code := v_owner;
    v_logrec.input_param_values := 'INFY_USP_TRADES_BY_BROKER_BKR,'
    || v_startdate
    || ','
    || v_enddate
    || ','
    || p_fundcode
    || ','
    || p_clientcode
    || ','
    || p_brokercode;
    v_logrec.report_name := p_reportname;
    v_logrec.object_name := 'INFY_USP_TRADES_BY_BROKER_BKR';
    v_logrec.rows_returned := v_rowcount;
    v_logrec.calling_application := p_callingapplication;
    v_logrec.calling_user := p_callinguser;
    END;
    BEGIN
    --calling the procedure to insert values into the report_log table
    COMMIT;
    SET TRANSACTION READ WRITE;
    base_util_pkg.crd_base_util_proc (v_logrec);
    SET TRANSACTION READ ONLY;
    END;
    EXCEPTION
    WHEN exp_error
    THEN
    DBMS_OUTPUT.put_line ('ERROR');
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('ERROR OCCURED' || SQLCODE);
    DBMS_OUTPUT.put_line (SQLERRM);
    END infy_usp_trades_by_broker_bkr;
    END OF CRD_DMAN.USP_TRADES_BY_BROKER
    This is my Pakage from where i am using ref cursor
    CREATE OR REPLACE PACKAGE CRD_DMAN.infy_pkg_compliance_transact
    AS
    ** Package name : CRD.INFY_PKG_COMPLIANCE_TRANSACTIONS
    ** Author's name : Infosys
    ** Date written : 06/11/07
    ** Project/System : CRD
    ** Description : Compliance Trades By Borker Package
    ** Maintenance history:
    ** Date Chg req# Name Remarks
    ** 06/11/07 CRD Infosys Created
    --Defining The ComplianceTrade Record DataType
    TYPE rec_compliancetrade IS RECORD (
    exec_broker_code crd.ts_order_alloc.exec_broker%TYPE,
    exec_broker_name crd.cs_broker.bkr_name%TYPE,
    client_code crd.ts_order_alloc.acct_cd%TYPE,
    client_name crd.cs_fund.acct_name%TYPE,
    directed_broker crd.ts_order_alloc.directed_broker%TYPE,
    count_ticknum crd.ts_order.order_id%TYPE,
    trade_date crd.ts_order.trade_date%TYPE,
    base_cost crd.ts_order_alloc.cur_base_mkt_val%TYPE,
    total_commission crd.ts_order_alloc.commision_amt%TYPE,
    broker_history     crd.au_broker.bkr_typ_cd%TYPE
    --Declaring a variable of rec_auditdata data type
    TYPE cur_compliancetrade IS REF CURSOR
    RETURN rec_compliancetrade;
    END infy_pkg_compliance_transact;
    END OF CRD.INFY_PKG_COMPLIANCE_TRANSACTIONS
    How to call this SP from VB code with ref cursor parameter?

    I'm fairly sure that's not possible, since there's nothing in the ODBC spec to allow for ref cursors. The driver has built in support to check for ref cursors that are returned via a stored procedure call, but there's nothing built into the driver to pass one IN. Since a ref cursor can't be constructed on the client side, you'd have to have some sort of structure that allowed you to reference the ref cursor directly in order to be able to pass one back to the database.
    Since you're using VB.NET anyway, the better solution is probably just to use ODP.NET instead, which DOES allow you to reference a ref cursor directly, and there are samples that install with ODP.NET that show you how to do that.
    Greg

Maybe you are looking for

  • Can't get CS6 pkg to install through Casper Remote

    I'm sure this has been talked about in here, but I read through several message boards and it looks like I'm not getting the answer to it, but people are mentioning it in various areas.  Forgive me if this is a repeat question. Can anyone get CS6 to

  • X230 Type 2325-AHG - How to downgrade from Windows 8 to Windows 7

    Hi all,  I have 4 laptops, lenovo x230 Type 2325-AHG, with windows 8 pro preinstalled. I would like to downgrade to windows 7. There is a iso with windows 7 and the drivers and software lenovo preloaded? alternatively, how can I proceed? There is a f

  • E65 and stereo bluetooth

    I really like the look of this phone as it is a step up from my 6233 which has been a great phone. The big disappointment with the 6233 was the lack of stereo bluetooth support. As the E65 support BT 1.2 I assume it supports bluetooth stereo and that

  • Server Core 2008 R2 SP1 - AD DS Best Practice Analyzer Scans Don't Produce Any Output

    Hi, This is a re-post moving this discussion to the recommended forum "Server Core" from here: http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/cc33d429-88e0-4450-a73c-361e395fd217. I am having problems producing any output for an

  • Perhaps I'll have to take it back...was: Frustrated with lack of Creative Supp

    Going nuts trying to get the X-Fi Fatality FSP card to work with my system. I've posted my woes and troubleshooting in this forum. I've called the Creative Support line and got a generic "try another PCI slot" suggestion. Also tried the email support