Reg. Converting a package in a Ref cursor level slider

Hi guru,.

I need to convert a package-level slider which contains the clause 'FOR UPDATE OF' in a Ref cursor when the query will be dynamically built with the necessary table name and other settings.

Using this slider many Update statement were made with the 'WHERE CURRENT OF' included in this clause.

Now, I've changed my Ref cursor cursor, but when I compile the cursor is dynamic based is not identified, because I get the error message.

Can someone tell me how to implement?

I need only go to dynamic bulding of the whole procedure.

Kind regards
Vijayasekaran.N

Maybe you can use around the ROWID. Like this

Say what your actual code.

declare
     cursor c
     is
     select *
       from t
        for update of name;

     lno t.no%type;
     lname t.name%type;
begin
     open c;
     loop
          fetch c into lno, lname;
          exit when c%notfound;

          update t set name = lno||lname
           where current of c;
     end loop;
     close c;
end;
/

With refcursor you can do.

declare
     type rc is ref cursor;
     c rc;
     lno t.no%type;
     lname t.name%type;
     lrowid rowid;
begin
     open c for 'select rowid rid, t.*
               from t
                for update of name';
     loop
          fetch c into lrowid,lno, lname;
          exit when c%notfound;

          update t set name = lno||lname
           where rowid = lrowid;
     end loop;
     close c;
end;
/

Published by: Karthick_Arp on December 26, 2008 02:00

Tags: Database

Similar Questions

  • Packages and poorly Ref Cursor

    SQL Server Developer, I fight with Oracle to say the least. I fought with the poor performance of the extraction of data from the database, but also a multitude of other things. The last number I have is a stored procedure in a package that does not work when run from my .NET code. I have many other packages and stored procedures that are working, but this one is a failure. I don't get any errors, just no data when I should be.

    I would run the toad package and see if it is the stored Proc and packaging, or if there is a problem in my .NET code. My stored procedure accepts a single PARAMETER of type integer, and has two parameters SYS_RefCursor OUT. My SQL uses the parameter (ID field) to select from a table. If I run the select SQL by itself with the hardcoded value ID, it works fine. I can run too where it uses the SQL for open cursors and inserts the data but I can't determine if it worked.

    So, my questions are the following:

    Can I select a Ref_Cursor? I'm trying to do something like that.
    results_cursor SYS_REFCURSOR;
    
    OPEN results_cursor FOR
       SELECT * FROM Person;
    
    SELECT * FROM results_cursor;
    If I could get the 1st issue a response, I can keep up with my next question.

    Thanks in advance.
    Jeff

    Hello

    I don't see an issue of .NET at this point, so you can have the best chance to post in the forum PLSQL, as it seems that if you need help writing a procedure, rather than interacting with a procedure well known in .NET:
    SQL and PL/SQL

    I'm not clear on your question though. Yes, you can read from a slider ref, and you do it by getting him.

    SQL > set serveroutput on

    SQL > declare
    Ref1 2 sys_refcursor;
    3 rec1 emp % rowtype;
    Number 4 NTC;
    5. start
    6. open ref1 for select * from emp;
    7 LOOP
    8 FETCH INTO rec1 ref1;
    9 OUTPUT WHEN ref1% NOTFOUND;
    10 DBMS_OUTPUT. Put_line (' name = ' | rec1.ename);
    11 END OF LOOP;
    12 end;
    13.
    Name = SMITH
    Name = ALLEN
    Name = WARD
    Name = JONES
    Name = MARTIN
    Name = BLAKE
    Name = CLARK
    Name = SCOTT
    Name = KING
    Name = TURNER
    Name = ADAMS
    Name = JAMES
    Name = FORD
    Name = MILLER

    PL/SQL procedure successfully completed.

    SQL >

    Maybe if clarify what you are trying to do or accomplish in "selecting from a ref cursor" it would be useful.

    Greg

  • How to run the packaged procedure with Ref Cursor

    Hello.
    The question may be very simple for you... but I was confused how to run
    I have the following package
    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); 
        
    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; 
    
        
    END CURSPKG;
    /
    But I want to test (run) this procedure...
    But confused how to have Ref Cursor
    Could you help me in this...

    Thank you

    You must declare a variable of type T_CURSOR and pass it to the procedure like this.

    declare
      lOutCursor CURSPKG.T_CURSOR;
    begin
      CURSPKG.OPEN_ONE_CURSOR(, lOutCursor);
    end;
    
  • Converts the ref cursor effect of function table

    I have a function named fn_get_emp(), whose return type is sys_refcursor. When I select fn_get_emp of double; I get the output to the format of the cursor. I want to convert to the table like format so that I can use in my insert statements insert into foo select * from fn_get_emp();

    Please note that the columns in the output of the fn_get_emp() is not fixed.

    Published by: user10566312 on January 30, 2012 22:25

    Here are the steps in the package DBMS_SQL, you need to turn your Ref Cursor a cursor DBMS_SQL.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25788/d_sql.htm#CHDJDGDG

    and then the rest of the documentation of the DBMS_SQL package gives many examples of how to treat this a cursor dbms_sql.

    Here is an example to use the package dbms_sql to process a request and produce some projection of sql and the database is in the query to CSV file...

    As user sys:

    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    /
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /
    

    As myuser:

    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      --
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    

    This allows the header line and the data to write into files separate if necessary.

    for example

    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    
    PL/SQL procedure successfully completed.
    

    Output.txt file contains:

    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    

    The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

    Adapt to the exit of styles and different types of data are needed.

  • REF cursor kicking package compilation error

    I have a package with the following procedure:
    PROCEDURE INTERPRET_DATAVRSN (
         p_table      IN VARCHAR2)
    
    AS
       cursor Generic_Tab IS REF CURSOR;
    
       c_sub Generic_Tab;
       v_SQL VARCHAR2(2000);
       v_SQLUpdate VARCHAR2(2000);
       v_RawDataVrsn VARCHAR2(200);
    
    BEGIN
       -- Start by selecting all of the unique values in the table.
       v_SQL := 'select distinct DataVrsn_in from '||p_table||' ';
    
       OPEN c_sub for v_SQL;
       -- Then process each unique value.
       Loop
          FETCH c_sub into v_RawDataVrsn;
          exit when c_sub %notfound;
    
            v_SQL := 'update '||p_table||' set DataVrsn=''';
          if (Instr(Upper(trim(v_RawDataVrsn)), 'V') > 0) then
             begin
                v_SQL := v_SQL||Replace(v_RawDataVrsn, 'V', '')||''' ';
             end
          else
             begin
                 v_SQL := v_SQL||v_RawDataVrsn||''' ';
             end
          end if;
    
        v_SQL := v_SQL||''' where DataVrsn_in='''||v_RawDataVrsn||''' ';
    
            EXECUTE IMMEDIATE v_SQL;
       end loop;
       close c_sub;
       commit work;
    
         EXCEPTION
              WHEN OTHERS THEN
               /*DBMS_OUTPUT.PUT_LINE(' Received CODE=' || SQLCODE || '  MESSAGE=' || SQLERRM);*/
             RAISE;
    
    END INTERPRET_DATAVRSN;
    It keeps giving me the error "encountered the symbol"REF"during awaits one of the following values:" any idea of another way to do this dynamic SQL cursor, or is there something I'm not here?

    Thank you!

    Hello

    It should be

    type Generic_Tab IS REF CURSOR;
     
    

    and is not

    cursor Generic_Tab IS REF CURSOR;
    

    In addition, your if condition does not have a begin and end, you can change it to

          if (Instr(Upper(trim(v_RawDataVrsn)), 'V') > 0) then
    
                v_SQL := v_SQL||Replace(v_RawDataVrsn, 'V', '')||''' ';
    
          else
    
                 v_SQL := v_SQL||v_RawDataVrsn||''' ';
    
          end if;
    

    Arun-

  • 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 ref cursor of procedure where the cursor is defined in the specification

    Hello

    Here's pseudo-code

    create or replace package test
    as
    cursor c_emp (number cv_emp_id)
    is
    Select emp_name emp where emp_id = cv_emp_id;

    type ref_c is ref cursor;

    function get_emp_name (number p_emp_id) return ref_c;
    end test;
    /


    create or replace the test physics package
    as
    ref_c function get_emp_name (number p_emp_id)
    is
    ret_val ref_c;
    Start
    Open c_emp (p_emp_id);
    ret_val: = c_emp;
    return ret_val;

    end get_emp_name;
    end test;
    /

    Returns me "PLS-00382: expression is of the wrong type. I tried to use a strongly typed Ref cursor based on the cursor, but nothing helped.

    Clearly, I understand something... and if I can't assign as ' ret_val: = c_emp "and if there is another key way it so please let me know.

    Thank you

    Ralph

    Published by: user13024707 on May 5, 2010 04:43

    user13024707 wrote:
    Clearly the point of my question is being missed.

    Or maybe the question is not been clearly asked. ;)

    I want to set the cursor in the PACKAGE SPECIFICATION, and not in the package body. The issue of the bind variable and the string is neither here nor there because I pass parameters to the cursor.

    What you ask is to use a PL/SQL cursor (defined in the specifications of the package or elsewhere) and that convert a Ref Cursor. N ° cannot be done.
    PL/SQL cursors should be used in the PL/SQL code. REF CURSOR is primary used to pass back a reference to a cursor (and all queries are cursors) to a layer of application outside of PL/SQL for example .net, java, etc.. Once you start using the ref Cursor only really, you have the choice of opening it based on a (dynamic) or a fixed query string as in the examples given. You cannot open a cursor of a PL/SQL cursor definition Ref.

    The difference is that when you do:

      CURSOR cur_mycursor IS
        SELECT ...
    

    you declare a cursor in pl/sql definition, not actually a slider itself. The cursor itself is created when you issue an OPENING or a statement FOR etc. So a Ref Cursor (reference to a slider) cannot refer to the definition of the cursor because it is only a definition, not a cursor (i.e. it has not been sent engine sql and instantiated at that time here). Instead the Ref Cursor must reference a cursor (query), itself, and that may be presented as a string or as the query itself that is issued against the sql engine and then the ref cursor points

    Thus, slider ref and PL/SQL cursors are different concepts, both designed to manage cursors in a slightly different way of programming. You cannot mix them.

  • REP-0737: must be a function of return type 'ref cursor.

    Hi all

    I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.

    Here is my code

    function QR_1RefCurDS return sys_refcursor is
    
     My_Cur Sys_Refcursor;
    begin
      Open My_Cur for select * from scott.emp order by deptno;
      return My_Cur
    end;
    

    fate of the screen.

    Ref_Cursor_in_reports10g.jpg

    Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.

    However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.

    So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.

    The predefined SYS_REFCURSOR type is introduced in Oracle 9i.

    Use this:

    PACKAGE test_rc IS

    TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;

    END;

    FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS

    test_rc.rc_type RC;

    BEGIN

    OPEN the RC to SELECT * FROM emp;

    RETURN rc;

    END;

    Kind regards

    Zlatko

  • Apex and accept Ref Cursor?

    Apex and accept Ref Cursor?

    Apex and accept objects?

    can someone help me please.

    Hi Nani4850,

    Nani4850 wrote:

    Apex and accept Ref Cursor?

    Apex and accept objects?

    The language of business for APEX is PL/SQL, so yes you can use REF CURSOR and pass objects to you packaged functions/procedures.

    How does this relate to Oracle APEX?

    Please explain what you plan to use a REF CURSOR in the APEX.

    Kind regards

    Kiran

  • REF CURSOR as a return of a function in SQL developer

    Hi team,

    I have a function which returns a Ref from a function slider while getting an entry number. But once I have create an implementation of single test on it with a valid entry that he throws error like below and have failed. My SQL developer version is 4.0.2.15.21 and it turns on a Linux OS (GNU/Linux 3.10.0 - 123.6.3.el7.x86_64). Here is the error I get.

    Cannot be converted to NUMBER <oracle.jdbc.driver.OracleResultSetImpl@5925237>.

    oracle.dbtools.raptor.datatypes.oracle.sql.NUMBER.customUnscaledInternalValue(NUMBER.java:93)

    oracle.dbtools.raptor.datatypes.oracle.sql.NumericDatum.customInternalValue(NumericDatum.java:37)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customInternalValueFilter(DataTypeImpl.java:411)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getInternalValue(DataTypeImpl.java:399)

    oracle.dbtools.raptor.datatypes.impl.DataValueImpl. < init > (DataValueImpl.java:55)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.customDataValue(DataTypeImpl.java:196)

    oracle.dbtools.raptor.datatypes.impl.DataTypeImpl.getDataValue(DataTypeImpl.java:178)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.getDynamicValueByName (UtRunnerImplIterator.Java:324)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UtRunnerImplObject.mapDynamicValueByName (UtRunnerImplIterator.Java:301)

    Oracle.DBTools.unit_test. Runner.UtRunnerImplIterator$ UT...

    Please help me out here.

    Please do not post double fillet.

    Mark this thread ANSWER and continue to use your other thread.

    Function taking as input ref cursor but throwing error exit

  • REF CURSOR ERROR

    I get the following error when you try to select using a ref cursor

    SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Here are the steps that I have followeed. Can someone tell me what I did wrong.

    -CREATE AN OBJECT

    create or replace type rsn_rec as object
      (
     rsn_cd   varchar2(10),
     rsn_desc  varchar2(30)
    );
    

    -CREATES A TABLE OF OBJECT

    create or replace type rsn_tbl as table of rsn_rec;
    

    PACKAGE/CREATED FUNCTION

    create or replace package pkg_rept_test as
      type refcur is ref cursor;
      function get_rsn return rsn_tbl pipelined;
    end pkg_rept_test;
    create or replace package body pkg_rept_test as
      function get_rsn
        return rsn_tbl pipelined is
          o_cursor refcur;
          rec rsn%ROWTYPE;
        begin
          open o_cursor for 
           select 
            rsn_cd,         
            rsn_desc       
           from rsn;
          loop
            fetch o_cursor into rec;
            exit when (o_cursor%notfound);
            pipe row(rsn_rec(rec.rsn_cd,                                                                                                   rec.rsn_desc)
                             );
          end loop;
          return;
      end;
    end pkg_rept_test;
    

    -THE TABLE SELECTION

    select * from table(pkg_rept_test.get_rsn)
    

    -ERROR
    SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Your code works for me just as you posted.

    Connected to:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    With partitioning, OLAP, Data Mining and Real Application Testing options

    SQL > create table rsn (rsn_cd varchar2 (10), rsn_desc varchar2 (30));

    Table created.

    SQL > insert into rsn values ("cd test", "test description");

    1 line of creation.

    SQL > commit;

    Validation complete.

    SQL > create or replace the rsn_rec as an object type

    2        (

    3 rsn_cd varchar2 (10),

    rsn_desc 4 varchar2 (30)

    5      );

    6.

    Type of creation.

    SQL > create or replace type rsn_tbl in the rsn_rec table;

    2.

    Type of creation.

    SQL > create or replace package pkg_rept_test as

    2 type refcur is ref cursor;

    3 function get_rsn return rsn_tbl in pipeline;

    4 end pkg_rept_test;

    5.

    Package created.

    SQL > create or replace package body pkg_rept_test as

    2 function get_rsn

    3 return rsn_tbl pipeline is

    4 o_cursor refcur.

    5 rec rsn % ROWTYPE;

    6 start

    7. open o_cursor for

    8. Select

    rsn_cd 9,.

    10 rsn_desc

    11 of rsn;

    12 loop

    13 extract o_cursor in rec;

    When exit 14 (o_cursor % notfound);

    line 15 pipe (rsn_rec (rec.rsn_cd, rec.rsn_desc)

    16                               );

    17 end of loop;

    18 return;

    end 19;

    20 end pkg_rept_test;

    21.

    Package body created.

    SQL > select * from table (pkg_rept_test.get_rsn);

    RSN_CD RSN_DESC

    ---------- ------------------------------

    tests of cd test description

  • By the way the Ref cursor to the subprogrammes-taking islet of time to return

    Hello
    Version Oracle 11.2.0.1

    I test the way other Ref Cursor sub programs using examples of schema scott. Please see below for the code.
    create or replace package typ_ref_cursor_pkg
    as
    Type t_ref_cursor is REF CURSOR;
    end typ_ref_cursor_pkg;
    
    /
    
    
    create or replace package emp_info_pkg
    is
    Type rec_emp is record
      (
        name  emp.ename%TYPE,
        sal   emp.sal%Type
      );
    l_emp_rec rec_emp;
    Procedure get_emp_salary(p_cursor typ_ref_cursor_pkg.t_ref_cursor);
    Procedure get_emp_by_dept(p_deptno emp.deptno%type);
    end emp_info_pkg;
    /
    
    
    create or replace package body emp_info_pkg
    is
    Procedure get_emp_salary(p_cursor typ_ref_cursor_pkg.t_ref_cursor)
    is 
    begin 
    Loop
    Fetch p_cursor into l_emp_rec;
    exit when p_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(l_emp_rec.name||' - '||l_emp_rec.sal);
    end Loop;
    End get_emp_salary;
    
    Procedure get_emp_by_dept(p_deptno emp.deptno%type)
    is
    v_emp typ_ref_cursor_pkg.t_ref_cursor;
    Begin 
    open v_emp for select ename,sal from emp where deptno=p_deptno;
    LOOP
    get_emp_salary(v_emp);
    END LOOP;
    close v_emp;
    END get_emp_by_dept;
    END emp_info_pkg;
    /
    Everything compiled fine.while execution of the procedure taking a lot of time.
    execute emp_info_pkg.get_emp_by_dept(10);
    what I am doing wrong? Could you point me to the right direction?

    Thank you
    SG

    Sg049 wrote:
    Everything compiled fine.while execution of the procedure taking a lot of time.

    execute emp_info_pkg.get_emp_by_dept(10);
    

    How long is a long time? Is the code you have posted takes a lot of time, or is it just a case of quick test that works quickly?

    Start by checking the SQL code. Get an execution plan for SQL that you run and see if you do a scan of the complete table on the table - if so an index on deptno could help.

    I think you have an endless loop in get_emp_by_dept. I was unable to see a way out the manual of the WHILE loop.

  • Ref Cursor as an out parameter.

    Hi all
    Please help me with this.

    It is a small procedure where the ref cursor is used as output parameter.
    create or replace
    PROCEDURE P_REFCURSOR_OUT 
    (P_DEPTNO    IN  EMP.DEPTNO%TYPE,
    P_RECORDSET OUT SYS_REFCURSOR) AS 
    BEGIN 
          OPEN P_RECORDSET FOR
          SELECT EMPNO,
          EMPNM,
          DEPTNO
          FROM   EMP
          WHERE  DEPTNO = P_DEPTNO
          ORDER BY EMPNM;
    END P_REFCURSOR_OUT;
    There is another procedure that calls the procedure above. But during the call, it is throwing an exception that ORA-01722. What's not here? Help, please.
    CREATE OR REPLACE PROCEDURE P_CALL_REFCURSOR_OUT AS
      L_CURSOR  SYS_REFCURSOR;
      L_EMPNM   EMP.EMPNM%TYPE;
      L_EMPNO   EMP.EMPNO%TYPE;
      L_DEPTNO  EMP.DEPTNO%TYPE;
    BEGIN
      P_REFCURSOR_OUT (P_DEPTNO    => 1000,
                  P_RECORDSET => L_CURSOR);
                
      LOOP 
        FETCH L_CURSOR
        INTO  L_EMPNM, L_EMPNO, L_DEPTNO;
        EXIT WHEN L_CURSOR%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(L_EMPNM || ' | ' || L_EMPNO || ' | ' || L_DEPTNO);
      END LOOP;
      CLOSE L_CURSOR;
    END P_CALL_REFCURSOR_OUT;
    Kind regards
    BS2012

    The cursor that you open selects the EMPNO and DEPTNO EMPNM in that order.
    When you retrieve the cursor, you get in L_EMPNM, L_EMPNO, L_DEPTNO.

    It would seem that the first two columns have been inverted in your FETCH statement. Assuming that EMPNO is a NUMBER EMPNM is a VARCHAR2, this means Oracle trying implicitly converted to the EMPNM in a NUMBER that is causing the error.

    If you change the order of the variables in your FETCH statement, the error should disappear

        FETCH L_CURSOR
        INTO   L_EMPNO, L_EMPNM, L_DEPTNO;
    

    Justin

  • Ref Cursor help

    Hello


    FOR REC V_LIST LOOPING
    INSERT INTO G_ID_TEMP_COMMON (TC_TYPE, TC_NUMBER_1_COL) VALUES ('T_ID_REPORT_PARM_VALUES', REC KEY);
    END LOOP;


    The above statement a part of the package.

    V_LIST is ref cursor,

    It returns a list of values,

    If place the statement above in the package, it shows error when compiling the package.

    Error:


    Error (17887,2): PL/SQL: statement ignored
    Error (17887,13): PLS-00221: 'V_LIST' is not a procedure or is not defined



    Kind regards
    Fame

    Try this:

    DECLARE
       l_key NUMBER;
    BEGIN
    ...
    LOOP
       FETCH v_list INTO l_key;
       --
       INSERT INTO G_ID_TEMP_COMMON(TC_TYPE,TC_NUMBER_1_COL) VALUES('T_ID_REPORT_PARM_VALUES', l_key);
       --
       EXIT WHEN v_list%NOTFOUND;
    END LOOP;
    ...
    
  • using plsql table and ref cursor in oracle's 10 g

    Hi all
    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.
    And in this process, I created a pl/sql table and a Ref cursor at the database level.

    CREATE OR REPLACE PACKAGE SCOTT. TYPE BONUS_PKG IS bonus_rec
    IS (RECORD
    EmpNo bonus_EMP.empno%TYPE,
    Ename bonus_EMP.ename%TYPE,
    employment bonus_EMP.job%TYPE,
    SAL bonus_EMP.sal%TYPE,
    Comm bonus_EMP.comm%TYPE);

    TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
    TYPE bontab IS TABLE OF bonus_rec INDEX DIRECTORY.

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor);
    PROCEDURE bonus_query (bonus_data IN OUT bontab);
    END bonus_pkg;


    CREATE OR REPLACE PACKAGE BODY SCOTT. BONUS_PKG IS
    PROCEDURE bonus_query (bonus_data IN OUT bontab) IS
    II NUMBER;
    CURSOR bonselect IS
    SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    BEGIN
    OPEN bonselect.
    II: = 1;
    LOOP
    Look FOR bonselect IN
    .EmpNo bonus_data (ii),
    .ename bonus_data (ii),
    .job bonus_data (ii),
    .Sal bonus_data (ii),
    .comm bonus_data (ii);
    EXIT WHEN bonselect % NOTFOUND;
    II: = ii + 1;
    END LOOP;
    END bonus_query;

    PROCEDURE bonus_refcur (bonus_data IN OUT b_cursor) IS
    BEGIN
    Bonus_data OPEN to SELECT empno, ename, job, sal, comm bonus_EMP ORDER BY empno;
    END bonus_refcur;

    END bonus_pkg;

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Please answer...

    Can someone give me an example of a scenario where we need to create a form manually based on a stored database procedure.

    In general, you will use a block of proceedings based when you have a collection of data from several tables presented in a form and your username must be able to update the information displayed.

    In your sample code, looks like you are using Oracle Support document "Melting a block on a Stored Procedure - examples of Code [ID 66887.1]". If this is the case, continue to follow the document - it guides you through all the steps. There is no need to manually configure things that the data block Wizard will work for you!

    I want to fill in the data in the forms manually is not using Forms data block Wizard and by program.

    Why? Let the wizard block configuration data of your block based on a procedure for you. There is no need to manually browse the data! I did what you're trying, and it's more work needed. Leave forms to do the work for you. :)

    If you absolutely have to do things manually, I recommend that you use the PROCEDURE bonus_query (bonus_data IN OUT bontab) instead of bonus_refcur (bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB, and then call the bonus_query procedure. Then, it's a simple case of a loop in the table of records returned by the bonus_query procedure. For example:

    DECLARE
       t_bonus    bonus_pkb.bontab;
    BEGIN
       bonus_pkg.bonus_query(t_bonus);
    
       FOR i in 1 .. t_bonus.count LOOP
          :YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
          :YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
          :YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
          :YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
          :YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
       END LOOP;
    END;
    

    This code example shows the basics, but as is the sample code - you will need to adapt to your situation.

    Also, I highly recommend that you look at the article inol listed. It is a very thorough debate on the REF CURSOR. If you have set up using a procedure based on the data source - it is more effective to spend the record table to your form that it must pass a ref cursor Using a ref cursor, you might as well just using a standard called cursor and loops on your named cursor. The effect is the same (a line returned at the same time creating lots of network traffic). Using the table of records is more efficient because the data set is returned if the network traffic is reduced.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

Maybe you are looking for