Return a cursor in function - Oracle 7.3.4

Hello

I need to implement a function (or stored procedure) in a 7.3.4 database that returns a cursor.

I did it for 11g and the code is something like this:

create or replace
function  foo( bar out SYS_REFCURSOR
  ) return number is 
  begin

    OPEN bar FOR select arg1, arg2 ,arg3  from table;

   return 1;
  end;

How can I him re-implement the Oracle 7? (I wonder if it is still possible...)

Can I return the result set of the query "select arg1, arg2, arg3 table" in another way?

Thank you

Believe it or not, the code you posted will work in 7.3.4 with a change. SYS_REFCURSOR, if I'm not wrong, was introduced later. This means creating a package with Ref Cursor type declaration:

CREATE OR REPLACE

PACKAGE cv_types

AS
SYS_REFCURSOR TYPE IS REF CURSOR;

END;

/

create or replace

function foo (bar on cv_types. SYS_REFCURSOR

) is back

Start

OPEN - bar TO select arg1, arg2, arg3 table;

Return 1;

end;

/

SY.


Tags: Database

Similar Questions

  • Can a function returns a cursor?

    Hello
    can a function returns a cursor, or it may just return simple data types? If she can return a cursor which version is it possible?
    Thank you!

    Hi Mark,

    Some examples of the REF Cursor code.

    CREATE OR REPLACE FUNCTION emp_by_job (p_job VARCHAR2,p_deptno NUMBER,pv_table VARCHAR2)
    RETURN SYS_REFCURSOR
    IS
        emp_refcur      SYS_REFCURSOR;
    BEGIN
        OPEN emp_refcur FOR
        'SELECT empno, ename FROM '||pv_table||'  WHERE job = '||''''||p_job||''''||' and deptno= ' ||p_deptno; --Dynamic String where table name column values are parameters
        RETURN emp_refcur;
    END;
    
    DECLARE
      emp_refcur_local      SYS_REFCURSOR;
      empno NUMBER(4);
      ename VARCHAR2(30);
    BEGIN
      --Calling the function using parameters
      emp_refcur_local:=emp_by_job('MANAGER',10,'EMP');
      LOOP
      FETCH emp_refcur_local into empno,ename;
        EXIT WHEN  emp_refcur_local%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE('Employee no: '||empno||'/ Employee name: '||ename);
      END LOOP;
    END;
    
  • Request report - use the function that returns the cursor

    My requirement is to create a report, which the source will be a function that returns a cursor (the type of cursor is ref cursor).
    How this can be done?

    for example. function my_func (pol_no in number) return cur_type < ref cursor >

    Edited by: viveks on October 27, 2009 10:09

    Better to look at a function that returns a query, or use a hose to treat your cursor returned, because the APEX at the moment can NOT handle the sliders in reports...

    Thank you

    Tony Miller
    Webster, TX

  • test a SP that returns a CURSOR

    I am using Oracle 11 and trying to use SQL Developer. However, I can't seem to get the DEBUGGING to work to test the call a SP that returns a cursor.

    I wrote a small test program to test, but they do not compile and I'm not sure why not. Can help you?

    the first code fragment is a package that I have that has a defined CURTYPE. It is used throughout my request, when you declare a cursor:
    create or replace
    PACKAGE          "SP_STATE" 
    Is
        type     curtype is ref cursor;
    ...
    now, here's the first part of the SP I want to test. Note that I've defined PriceCur as using the CURTYPE package.
    create or replace
    PROCEDURE          "USP_GETL_ACCOUNT_PRICES" (
      AcctNo          in     marketer_account.mka_last_full_css_acct_no%type,
      MktrNo          in     marketer_account.mka_mktr_no%type,
      Status                     in              varchar2 default null,     
      PriceCur          out            sp_state.curtype
      )
    as
    begin
    Open Pricecur For 
    Select 
    ...
    Now, here's my m.o.:
    Declare 
       Price_Cur  Sp_State.Curtype;
       price_rec  price_cur%rowtype;
    Begin
       Usp_Getl_Account_Prices('302189139000026', 11813,'A', price_cur);
       Open Price_Cur;
       Loop
          Fetch Price_Cur Into Price_Rec;
          Exit When Price_Cur%Notfound;
          dbms_output.put_line(price_cur%rowcount || ') ' || price_rec.apr_account_price_id);
       End Loop;
       close price_cur;
    end;
    They do not compile. What I'm doing here is call SP - pass 3 incoming parameters and retrieve a cursor.
    so I want to loop through the cursor and list some fields on...

    Where I'm going wrong? Any help would be greatly appreciated.

    Sean

    userLynx wrote:
    I get this error:

    Error report:
    ORA-06504: PL/SQL: return variables of the game results or the query types do not match
    ORA-06512: at line 7
    + 06504. 00000 - "PL/SQL: return of the variable result set or query types do not match." + "
    * Cause: Numbers or types of columns in a query does not match declared.
    return type of a variable result is defined or declared two result types
    Set of variables do not match.
    * Action: Change the program or the declaration statement. Check what query variable +.
    actually we want during execution.

    He doesn't like the var defined as varchar2. I can change that to a % rowType heart?

    When I proposed to modify the code according to your needs, I assume that you would like to change the instruction WRT Fetch your columns retrieved in the Refcursor; And so I suggest no changes in it.

    As riedelme says, a record would help for better maintainability. :)

    You do not experience other errors, you met earlier, right?

    Kind regards
    P

    Published by: Jen K on July 12, 2012 12:04 AM

  • Calling a procedure that returns a cursor in a procedure

    Hello
    I have two stored procedures. They both return a cursor as output variables. However, I have another stored procedure that calls these procedures and return their results once again an output variable. I know that sounds strange to want to do something like this, but how can I do this?

    Mikhail says:

    My first procedure returns a cursor. But the cursor is opened on one condition. Like, if PARAM1 = 1 THEN OPEN cursor_1 to SELECT... OTHERWISE, OPEN CURSOR_1 TO SELECT... And the second slider has the same structure. The thing is in the two procedures if I declare that a single CURSOR_1 IN OUT parameter that the procedure will not work. So in both entities, I have two variables IN OUT SYS_REFCURSOR: c1 and c2. Then, in the third procedure I first call the first procedure, then the second. How can I write my third procedure in order to obtain the result two procedures United?

    Why the appellant (3rd procedure) need to have 2 ref Cursor? How will the appellant to "unite" the sliders?

    The actual data, a power of work must be done inside sliders. Not in PL/SQL or other languages. The SQL language is a very powerful and flexible language.

    So if the SQL 2 data sets (or more) must be "United", then you should not use the 3rd procedure and PL/SQL code to do. Should use you 2 sliders.

    You should watch this by using SQL only. The 2 sets of data can be merged, joined, union'ed. You can determine the intersection. You can determine the difference (with a negative sign). It can be rotated. It can be aggregated. It can be cube' ed. Etc.

    This SQL will then be used as a single slider and a unique reference cursor handle will be used to consume the output of the cursor.

    The basic rule to develop Oracle applications is simple. Optimize SQL. Minimize the PL/SQL.

    Use the SQL language to the data of the crisis. No PL/SQL.

  • How to execute a stored procedure that returns a cursor?

    How to execute a stored procedure that returns a cursor?

    Follow the code:

    CREATE OR REPLACE PROCEDURE stp_cashin_grupo
    (p_func in VARCHAR
    p_cod_grup in full
    p_des_grup in VARCHAR
    p_logi in VARCHAR
    p_curs_rset ON infoc.pck_cashin_grupo.curs_rset
    )
    IS
    BEGIN

    If p_func = "1" then
    OPEN FOR P_curs_rset
    Select
    cod_grup
    des_grup
    dat_manu_grup
    des_logi_manu
    of infoc.tbl_cashin_grupo
    order of des_grup;
    end if;
    END stp_cashin_grupo;


    and packaging:

    CREATE or REPLACE PACKAGE pck_cashin_grupo
    AS
    TYPE curs_rset IS REF CURSOR;
    END pck_cashin_grupo;

    My question is how to execute in sql plus?
    Stp_cashin_grupo EXEC ('1', 0, ", '465990', my doubt is how to move the cursor as return)


    Thank you

    It is described in the manual

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14357/CH5.htm#sthref1122

  • Error when the stored procedure returns a cursor in c pro


    Hello

    I tried to make things work, explained to the
    [2537153 m]

    He runs a stored procedure from pro c which returns a cursor.
    But when I compllie to c pro I get following error. My name of the procedure's TEST.
    If I change the output to an int value parameter. It compiles okay.



    PLS-S-00306, wrong number or types of arguments in the call to 'TEST '.
    Error on line 34, column 5 in file E:\C\Test\tt.pc
    TEST(:test_cursor);
    +.... 1 +.
    PLS-S-00000, ignored statement
    A semantic error on line 33, column 1, folder E:\C\Test\tt.pc:
    BEGIN
    + 1 +
    PCC-S-02346, PL/SQL found semantic errors

    Can make a point about what could be the error?
    I work from oracle 8i client. that connects to oracle 9.0.1.
    Operating system is win 2000 sp4

    Oh yes - differs from the code snippet I posted your with the declaration of the host cursor variable. A difference in the case. Is how important it?

    ( it's been almost 10 years since I've coded last in Pro * C, so be careful with these questions! ) ;-) )

  • return ref cursor

    I want to return ref cursor based on explicit cursors


    create or replace procedure get_extract (in_val in varchar2, return_cursor to sys_refcursor)
    is
    cursor c1 is select * from jumbo.
    cursor c2 is select * from mumbo.

    rec_j jumbo % rowtype;
    rec_m mumbo % rowtype;

    Start

    If in_val = am' then

    Open c1;

    loop
    Fetch c1 in rec_m;
    When exit c1% notfound;
    end loop;

    Open return_cursor SELECT * from rec_m;
    Close c1;

    elsif in_val = 'J' then

    Open c2;

    loop
    extract the c2 in rec_j;
    When the exit c2% notfound;

    end loop;
    Open return_cursor SELECT * from rec_j;
    Close c2;

    on the other

    Open return_cursor select double null.

    end if;

    end;
    /

    When I compile the procedure above, I get the error

    LINE/COL ERROR
    -------- ---------------------------------------------------
    20/24 PL/SQL: statement ignored
    20/38 PL/SQL: ORA-00942: table or view does not exist
    32/24 PL/SQL: statement ignored
    32/38 PL/SQL: ORA-00942: table or view does not exist

    so its occurring in the open return_cursor for... statement, what is the problem with above?

    user650888 wrote:
    I wrote the above and it worked but instead of having a select into the body of the procedure, I love it in an explicit cursor

    You can't do that. The sliders don't work that way. On the closest you could get would be something like:

    SQL> select * from t;
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> select * from t1;
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    
    SQL> create or replace procedure get_extract(in_val in varchar2,
      2                               return_cursor out sys_refcursor) is
      3     l_cur_m varchar2(100) := 'select * from t';
      4     l_cur_j varchar2(100) := 'select * from t1';
      5  begin
      6     if in_val = 'M' then
      7        open return_cursor for l_cur_m;
      8     elsif in_val = 'J' then
      9        open return_cursor for l_cur_j;
     10     else
     11        open return_cursor for select null from dual;
     12  end if;
     13  end;
     14  /
    
    Procedure created.
    
    SQL> var cur refcursor;
    SQL> exec get_extract('M', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> exec get_extract('J', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    

    John

  • I need to return multiple values in function

    create or replace function f (p) in varchar2) return varchar2
    is
    a number (10);
    Start

    for loop 1 in 1.10
    Select instr('yyyyyyyyynnnnnyynny','y',1,i) in the doubles.
    end loop;
    return a;
    end;

    my function return a value, but I need to return multiple values
    Thanks in advance

    I don't know if that's what you want (you should give expected results also)

    SQL> create or replace type mytabletype as table of number;
      2  /
    
    Type created.
    
    SQL> create or replace function f (p in varchar2) return myTableType pipelined is
      2    a number(10);
      3  begin
      4    for i in 1..10 loop
      5      select instr('yyyyyyyyynnnnnyynny','y',1,i) into a from dual;
      6      pipe row (a);
      7    end loop;
      8  end;
      9  /
    
    Function created.
    
    SQL> select * from table(f('1'));
    
    COLUMN_VALUE
    ------------
               1
               2
               3
               4
               5
               6
               7
               8
               9
              15
    
    10 rows selected.
    
    SQL>
    

    Published by: Leo Mannhart on March 22, 2011 11:01

    could even be compressed into

    create or replace function f (p in varchar2) return myTableType pipelined is
    begin
      for i in 1..10 loop
        pipe row (instr('yyyyyyyyynnnnnyynny','y',1,i));
      end loop;
    end;
    
  • Return by using the function number

    How can I return number using the function.

    Here is my procedure but do not in the name of variable or setting up as a variable...

    create or replace function Calculate_number)
    Number 1 in number,
    Number2 number)
    Return number is
    Start
    declare
    number of result;

    Select number1 + number2 as a result of double;


    Return (result);
    end;

    Hello

    You have not need double a lot in PL/SQL.

    CREATE OR REPLACE FUNCTION Calculate_number
    (
         number1 IN NUMBER,
         number2 IN NUMBER
    )
    RETURN NUMBER
    DETERMINISTIC
    IS
           result number;
    BEGIN
         result := number1 + number2;
    
         RETURN Result;
    END      Calculate_number;
    

    Strored procedures, local variables are declared between statements IS and BEGIN. DECLARE in a stored procedure starts a nested block to BEGIN, with its own local variables, which is rarely necessary. (Nested BEGIN blocks are not so rare, but they almost never have local variables need a nested block. Most people here all variables of the function complete together before the first START.)

    If the function always returns the same value when it is called with the same arguments, then Deniz it as DETERMINISTIC; It might make it faster to use.

    There are many good reasons to use a variable as results, but if you don't happen to have one, then you can do this:

    CREATE OR REPLACE FUNCTION Calculate_number
    (
         number1 IN NUMBER,
         number2 IN NUMBER
    )
    RETURN NUMBER
    DETERMINISTIC
    IS
    BEGIN
         RETURN  number1 + number2;
    END      Calculate_number;
    

    Published by: Frank Kulash, October 22, 2010 12:37
    Fault corrected typo (thanks, HM); Added after the remarks.

    Published by: Frank Kulash, October 22, 2010 13:28

  • You must return the value of the Oracle function in VB Code

    Hi all

    I have the oracle APPTIDFUN (WHO RETURN NUMBER) function, I need to call in the VB Code. (Here's the code)

    --------------------------------
    If Msg2 = 6 Then
    Dim RS As New ADODB. Recordset
    Dim SQL As String
    RS. Open "appointments", CN, adOpenDynamic, adLockPessimistic
    RS. Find ' patient_id = ' "& str1 &" "'". "
    If RS. When the EOF
    RS. Find ' Appt_start_Date = ' "& str3 &" "'". "
    If RS. When the EOF
    RS. AddNew
    RS ("patient_id") = str1
    RS ("Appt_type") = str2
    RS ("Appt_start_Date") = str3
    RS ("Appt_end_date") = str4
    RS ("Num_days") = str5
    RS ("Total_Amount") = str6
    RS ("Inv_Number") = str7
    RS ("Approval_status") = str8
    RS ("NUM_WATCHER") = str9
    RS. Update

    ------------------------------------------------------------
    I want to call the function from oracle here that in the above code

    RS ("Appt_id") = < value of function >


    Please do the needful.

    Abdul,

    You need to change the line

    RS("Appt_Id") = RS1
    

    TO

    RS("Appt_Id") = RS1(0)
    

    Kind regards

    Manu.

    If my answer or the answer to another person has been useful or appropriate, please mark accordingly

  • INVALID CURSOR - block anonymous component the cursor in function

    I get an error when you try to call my cursor.
    CREATE OR REPLACE PACKAGE tax_update
    AS
     TYPE gencur IS ref cursor;
     FUNCTION tax_sf
     (
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
     )
     RETURN NUMBER;
    END;
    / 
    CREATE OR REPLACE PACKAGE BODY tax_update
    AS
     FUNCTION tax_sf
     (
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
     )
     RETURN NUMBER
      IS
      lv_taxrate NUMBER;
     BEGIN
      OPEN p_thecursor FOR 
       SELECT taxrate 
       FROM bb_tax
       WHERE state = p_state;
      RETURN lv_taxrate;
     END;
    END;
    / 
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
     BEGIN
     LOOP
      FETCH tax_cur INTO rec_tax;
       EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
     END LOOP;
    END;
    DECLARE
    *
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 6
    Mission is to create a package that will contain the rate of taxation by the State in a packed slider. The package contains a function that can receive a State of 2 character abbreviated as an argument and finds a match in the cursor and return the tax rates for tha tstate. An anonymous block will test the function with the State of North Carolina.
    If anyone can help?

    user13842802 wrote:
    Have tried a few ways to call but always error on TAX_SF.

    SET SERVEROUTPUT ON
    DECLARE
        tax_cur tax_update.gencur;
        rec_tax bb_tax%rowtype;
    BEGIN
        tax_cur := tax_update.tax_sf('NC');
        LOOP
          FETCH tax_cur INTO rec_tax;
          EXIT WHEN tax_cur%NOTFOUND;
          DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
        END LOOP;
    END;
    /
    

    SY.

  • How to return a multiple registration with Oracle Native Web Service?

    Hi all

    I would like to know the native web service oracle can return multiple records of customer or not?

    I have successfully developed the native oracle web service to return only one record, but the next challenge is to develop the web service to return a multiple record (such as database on each department employees)

    Thank you and best regards,
    Zenoni

    I have successfully developed the native oracle web service to return only one record, but the next challenge is to develop the web service to return a multiple record (such as database on each department employees)

    You may return a list (multiple values/records) in XML (using CLOB or XMLType), CSV or JSON format or whatever.

    function get_employees (p_department_id in number) return clob
    as
    begin
      return 'your_xml_string_here';
    end get_employees;
    

    It would be up to the customer (the caller of the web service) to extract the values of any format you decide, of course.

    -Morten

    http://ORA-00001.blogspot.com

  • Reg: Ref cursor in function

    Hi friends,
    LSPQ HELP ME.
    I CREATED A FUNCTION AS EXAMPLE BELOW.

    TYPE REFCURTYPE IS REFCURSOR; -DECLARE REF CURSOR.

    CREATE FUNCTION FUNC1(EMPID,DESIG) RETURN REFCURTYPE
    AS
    OPEN FOR REFCURTYPE
    SELECT A GROUP OF GROUPMASTER;
    RETURN REFCURTYPE;
    END;

    WHEN I RUN THE QUERY AS
    SELECT FUNC1('1001','SM') FROM DUAL;

    IN THIS CASE, I WANT TO SEE THE REPORTS THAT IS COMES TO WORK IN REFCURTYPE... WHAT WOULD I DO?;

    Rajnish Chauhan says:
    BUT EXPENSIVE...

    I CALL THIS QUERY IN THE PROCEDURE... SELECT FUNCTION('101','SM') FROM DUAL;

    There is no need to SELECT. Just call function and fetch:

    SQL> CREATE OR REPLACE
      2    PROCEDURE P1
      3    IS
      4        v_cur SYS_REFCURSOR;
      5        v_ename VARCHAR2(20);
      6    BEGIN
      7        v_cur := f1;
      8        LOOP
      9          FETCH v_cur INTO v_ename;
     10          EXIT WHEN v_cur%NOTFOUND;
     11          DBMS_OUTPUT.PUT_LINE(v_ename);
     12        END LOOP;
     13  END;
     14  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL> exec p1;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • return of the declared function of type

    Hi gurus

    I have a question, how can I find type in the function that is declared inside, but don't create do not package and own type.

    For ex.:

    Create or replace function test_func

    return t_tab in pipeline as

    type r_tab is (record

    col1 test_tab.col1%type,

    col2 test_tab.col2%type);

    type t_tab is table of the r_tab;

    v_tab t_tab;

    Start

    -some operations

    end test_func;

    Concerning

    Hello

    Necronus wrote:

    Hi gurus

    I have a question, how can I find type in the function that is declared inside, but don't create do not package and own type.

    For ex.:

    Create or replace function test_func

    return t_tab in pipeline as

    type r_tab is (record

    col1 test_tab.col1%type,

    col2 test_tab.col2%type);

    type t_tab is table of the r_tab;

    v_tab t_tab;

    Start

    -some operations

    end test_func;

    Concerning

    You can not.  If you want t_tab to be available outside test_func, then you must set outside test_func.

Maybe you are looking for

  • Content that is not when the headset is connected

    I have an early 2015 MacBook Air 13 "El Capitan (version 10.11.5) running 1.6 Intel Core i5 to Ghz, 4 GB RAM When I plug the headphones into the 3.5 mm headphone jack, the system recognizes as being connected, but something strange is happening. It w

  • 8,6 of fieldpoint installation problem

    Hey everybody, I installed a laptop to Labview 8.6 real-time with 8.6. For some reason any he doesn't let me install Labview 8.6 real-time on our device compact fieldpoint. I reinstalled, twice. Still, when I go to add/remove programs and you try to

  • RUNDLL error when opening Power Options XP MCE sp3

    I can't open my mobile Power Options - I get an error message so my settings are "stuck" and cannot be changed.  Rundll error is as follows: an exception occurred while trying to run "shell32.dll, control_rundllPowerCf.cpl.  Can anyone help?

  • can't verify your existing purchases

    Hey guys, I have two quick questions/problems... (1) how do you usually check the api blackberry.payment? I tried to use the devmode structure, but I noticed the behavior isn't quite 100% identical to the production. (2) seems to be control problems

  • Adobe CC tool installed new versions (CC 2015) instead of the upgrade of CC 2014

    I have a new CC subscription account. Decided to improve the existing CC 2014. But I got new versions of all CC 2015 (for example, Photoshop 2015 CC).  Why?What to do next? Manually remove the CC 2014? What is the best way to remove CC 2015 without s