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.

Tags: Database

Similar Questions

  • getting this error on the function g 10 isn't a return type

    See the function down
      TYPE ptr IS REF CURSOR;
      FUNCTION check (check_part IN VARCHAR2, check_vendor in varchar2) RETURN ptr;
    FUNCTION check(check_part IN VARCHAR2, check_vendor in varchar2) RETURN ptr is
      
       my_ptr ptr;
        
       check_cnt number(30);
       default_cnt number(30);
          
      BEGIN
        
      select count(*) into check_cnt
      from table_one ps
      where ps.part_number = check_part
      and ps.vendors = check_vendor;
      
      select count(*) into default_cnt 
      from table_one lm 
      where lm.part_number = check_part
      and lm.vendors = 'UNKNOWN';
      
      if (check_cnt = 1 and default_cnt = 0) then
       
        OPEN my_ptr  FOR
        
          SELECT tp.id,
                FROM table_one tp 
          WHERE tp.part_number = (check_part)
          and tp.vendors = (check_vendor);
      return my_ptr;  
        
    elsif (default_cnt = 1 and check_cnt = 0)  then
    
          open my_ptr for 
          
          SELECT tp.id,
           FROM table_one tp 
          WHERE tp.part_number = (check_part)
         and tp.vendors = 'UNKNOWN';
    
    return my_ptr;
    end if;
    
      
    END check;
    Please note that I use oracle 10g all the... Any help is appreciated. Thank you.

    Published by: user13328581 on February 6, 2011 19:36

    sql_dev wrote:
    Hello

    Better just to have a simple statement in the else block

    ELSE
    open my_ptr for
    SELECT NULL
    FROM DUAL;
    return my_ptr;
    

    So whenever the IF fails, your other work without value in the cursor.

    In fact, this slider returns a single row that contains a NULL value.
    Better add a condition that will always evaluate to false (0 = 1).

  • How to start the view off of the ref cursor Oracle as input/output param

    Hello world

    We use JDev 11.1.2.3 WL 10.3.6 and Java 7.

    We are at the beginning of our transition from Oracle Forms to ADF.  We have a very large forms that uses many store procedures that have IN/OUT ref Cursor parameters and tables plsql.  I tried to find information on best practices to achieve, but only seemed to find tutorials on SEO of the Oracle ref Cursor return functions.  I hope we don't have to rewrite our code of database to work with ADF.

    This is an example of a proc currently a block on a form based on directly

    The ref cursor parameter is input/output to satisfy the way the form handles this type of paradigm.

    ADF we want I hope to reuse these procs existing (without the need to wrap/overload them) on the basis of the display objects.

    Example:

    / * my record type which houses the information I want to go back * /.

    TYPE rec_hist_vacpac_status IS RECORD)

    rec_order NUMBER (5),

    rec_rownum NUMBER (5),

    return_column SAM_VACPAC.vacpac_status%TYPE,

    rec_login_id SAM_VACPAC.ins_user%TYPE,

    status_date SAM_VACPAC.status_date%TYPE

    );

    / * Sets the ref cursor type * /.

    TYPE lcur_hist_vacpac_status IS REF CURSOR;

    / * This is a procedure that would take some info link go / return

    Return the ref cursor of this information as an in / out * /.

    PROCEDURE prc_myinfo_refcur)

    pnum_identify_seq_id in NUMBERS

    pcur_myinfo IN OUT lcur_hist_vacpac_status);

    Can anyone point me in the right direction on documentation on this?

    Thank you!

    Hi Cemerson:

    See this example:

    1. 1. create a TYPE as an object

    CREATE OR REPLACE

    TYPE GOTYOB_EQUI

    AS AN OBJECT

    (

    CDELEM VARCHAR2 (50).

    TIELEM VARCHAR2 (2)

    );

    1. 2. create a TABLE TYPE AS

    CREATE OR REPLACE

    TYPE GOTYTA_EQUI

    AS THE GOTYOB_EQUI TABLE;

    1. 3 create a function, it returns the TYPE of the TABLE

    FUNCTION fn_equiposarriba)

    pa_cdelem IN VARCHAR2,

    pa_nucomp in NUMBERS

    pa_anperi in NUMBERS

    pa_meperi in NUMBERS

    )

    Gotyta_equi RETURN PIPELINED IS

    CURSOR trae_equimani (va_cdelem VARCHAR2) IS

    SELECT cdelem, tielem, cdelempadr,

    (SELECT cdequi

    Of evm_alim

    WHERE anperi = eq.anperi

    AND meperi = eq.meperi

    AND nucomp = eq.nucomp

    AND cdalim = eq.cdalim) cdalim

    Of evm_equimani eq

    WHERE anperi = pa_anperi

    AND meperi = pa_meperi

    AND nucomp = pa_nucomp

    AND cdelem = va_cdelem

    AND cdelempadr <> cdelem

    AND tielem <> 'A ';

    equimani trae_equimani % ROWTYPE;

    va_cdalim VARCHAR2 (100);

    BEGIN

    -Loading los equipos aguas arriba

    WHILE equimani.cdelempadr IS NOT NULL LOOP

    OPEN trae_equimani (equimani.cdelempadr);

    equimani: = NULL;

    SEEK trae_equimani INTO equimani;

    CLOSE Trae_equimani;

    IF equimani.cdelem IS NOT NULL THEN

    PIPE ROW (gotyob_equi (equimani.cdelem, equimani.tielem));

    END IF;

    END LOOP;

    RETURN;

    END;

    1. 4 SQL Query with the help of the function... you can use this SQL in a display object

    SELECT

    *

    Of

    TABLE (gopq_eventos.fn_equiposarriba (' F-SCZ-043-103', '))

    1,

    2013,

    6

    )

    )

    Best regards, Marcelo

  • Initialize the Ref Cursor to avoid ORA-01001: Invalid cursor

    Hello

    I write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.

    Any help is greatly appreciated...

    Thank you
    Christine

    cad0227 wrote:
    Hello

    I write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.

    Any help is greatly appreciated...

    Thank you
    Christine

    The most appropriate way would be the caller to handle the situation. The caller must capture the exception of INVALID_CURSOR and do what is necessary.

    Other suggestions like having a separate Pavilion or a model select all will lead the appellant to act to the particular situation, that slider is not being opened. What is the case with the exception of INVALID_CURSOR raised by oracle.

    All the need for the appellant to do is manage the exception of INVALID_CURSOR and you should be good. And also INVALID_CURSOR is not a mistake, it's an exception that has a special meaning for her. In the case you sense it takes the condition when not together to return a cursor.

  • View BC item from the ref cursor oracle

    Is there an easy way to jdev 11.1.1.4 to create a view based on a ref cursor oracle object?

    It's in the docs http://docs.oracle.com/cd/E21043_01/web.1111/b31974/bcadvvo.htm#sm0341 search for 'How to create a display on a REF CURSOR object'
    An example can be found here http://adfpractice-fedor.blogspot.de/2011/01/adf-bc-programmatically-populated-vo.html

    Timo

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • Best approach - whether to return Collections or the Ref Cursor?

    I have the table that the column is a nested table (column address) type. Now, I want to fill the same
    in a jsp page.

    As his collection type I am thinking to send variable Collection to front-end. And most of java professionals
    argue that the collections are the best approach.

    But here, in a lot of posts, I read that collections at the front end is the worst approach and it degrades performance
    and increases the load.

    But java assert that even if connection fails they can always display the data as the data set is with them
    How to get a set of results COLLECTION.

    As ref cursor is just a pointer to the real cursor lies in the comics... they're going to make one record of the other instead and once the connection is lost... they can no longer display the data. This assertion seems
    to be reasonable!

    How you condemn it? and prove ref Cursor is good way?


    Here's the example scenario that I have with me.
    create type t_adress is object(t_h_no varchar2(500),t_pin_code number);
     /
     
     create type t_address_tbl is table of t_adress;
     /
     
     create table r_dummy (emp_name varchar2(200),emp_id number,emp_address t_address_tbl)
     nested table emp_address store as emp_address_tbl;
     
     insert into r_dummy values('raghu',1,t_address_tbl(t_adress('598',500035),t_adress('600',500036)))
     
     insert into r_dummy values('raghu nadh',2,t_address_tbl(t_adress('598',500035),t_adress('600',500036)))
    Using the Collection
    Create or replace procedure p_using_col
     (
     p_emp_id          in     r_dummy.emp_name%type,
     p_emp_dtls          out     t_address_tbl
     )
     is
     begin
              Select     t_adress(cl.t_h_no,cl.t_pin_code)
              bulk collect into p_emp_dtls
              from     r_dummy,table(emp_address) cl
              where     emp_id = p_emp_id;
     
     end;
     /
     
     set serveroutput on;
     declare
              l_emp_id          r_dummy.emp_name%type := 1;
              l_emp_dtls          t_address_tbl;
     begin
              p_using_col(l_emp_id,l_emp_dtls);
              
              for i in 1..l_emp_dtls.count
              loop
              
                   dbms_output.put_line(l_emp_dtls(i).t_h_no);
              
              
              
              
              end loop;
     
     
     end;
    Using Ref Cursor
    Create or replace procedure p_using_ref
     (
     p_emp_id          in     r_dummy.emp_name%type,
     p_emp_dtls          out     sys_refcursor
     )
     is
     begin
              Open p_emp_dtls for
                   Select     cl.t_h_no,cl.t_pin_code
                   from     r_dummy,table(emp_address) cl
                   where     emp_id = p_emp_id;
     
     end;
     /
     
     set serveroutput on;
     declare
              l_emp_id          r_dummy.emp_name%type := 1;
              l_emp_dtls          sys_refcursor;
              
              l_h_no               varchar2(500);
              l_pin_code          number;
              
              
     begin
              p_using_ref(l_emp_id,l_emp_dtls);
              
                   loop
                        fetch l_emp_dtls into l_h_no,l_pin_code;
                        
                        exit when l_emp_dtls%notfound;
                        dbms_output.put_line(l_h_no||'    '||l_pin_code);
                   
                   
                   end loop;
              
                   close l_emp_dtls;
     end;
    Concerning
    RUSSO

    RUSSO says:
    I would like to know what really happens behind the screen IE in PGA... when we return collections...

    A collection is a PL/SQL variable. Like all PL/SQL variables, it resides in the global area of the server process that executes PL/SQL code. This memory is part of the process the process's private memory.

    If need more memory, more memory server be malloc' ed by the process.

    As he is dedicated and private memory, no other process can reap the benefits of this memory in use. It is not 'ideal' - shared memory however benefits all the processes that are involved in sharing that allocated the memory. As is the case with the SGA

    How long my set of data will reside in the PGA? He immediately fade after returning to the calling procedure? and how it degrades performance. Help me with a good link.

    Assume that you create a collection of 10 MB. The process server malloc' ed 10 MB of server memory. The PGA has thus extended.

    When your code executes the variable usage (it is out of reach of runtime), the PL/SQL engine can theoretically free up 10 MB of memory. However, it may have allocated 4 KB memory after this assignment of 10 MB. Only 4 KB is still in use. This moment results in that the process cannot shrink its allocated memory - as this free piece of 10 MB is slapbang in the middle of the used memory space.

    PGA memory is 'expensive' because it's not shared memory is private, with only the current process. PGA in memory is not so easy to decline. Memory management is a complex issue and you who ceases to use a large part of the PGA memory almost never means that this memory suddenly become free and available for other processes to use.

    Also, you have to ask yourself why you want to copy data from disk blocks into the SGA buffer (for SQL procedures) cache, then copy these data blocks of APG in the PGA (using a collection and extraction in bulk) and then copy this PGA memory on the network to the client process (TOAD or .net or Java or whatever).

    It's a lot of moving parts - which increases the complexity, lowers the performance and scalability and ups the risk of something going wrong due to the increased complexity.

    It is much simpler and much stronger, to maintain the number of moving parts to a minimum. For example to copy data directly from cache buffers of the SGA to the customer via a ref cursor

  • 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.

  • Is it possible to combine dynamic &amp; static queries in the ref cursor?

    Hi all

    I was wondering if it is possible to combine dynamic & static queries in the ref-cursor?
    CREATE OR REPLACE FUNCTION dynamic_static_kk
       RETURN sys_refcursor
    AS
       o_cursor   sys_refcursor;
    BEGIN
      open 'select 1 fom dual'
           union
           select 2 from dual;
    
       RETURN o_cursor;
    END;
    In the existing code, the two parts of the query are static, but I need to improve & replacement of part would do the trick.

    So, I was wondering if it is possible to keep the static part 2. Of course, do both dynamic parts seems the only possible treatment for me.

    So, I was wondering if it is possible to keep the static part 2.

    No, you can't.

    Of course, do both dynamic parts seems the only possible treatment for me.

    Yes, it's the only way.

  • I know the example of Ref Cursor

    I tried to learn the Ref cursor, I can't find simple example. can anyone of you please tell me a Ref Cursor?

    Okies, I'll try that...

    Thank you very much.

  • Report regions - use of the Ref Cursor?

    APEX 4.2

    See http://mikesmithers.wordpress.com/2012/02/22/getting-apex-to-play-with-ref-cursors

    The above article is older than 2 years. The techniques shown in the link above still valid today if we want to create a report region in the APEX are based on a function that returns a Ref Cursor? Are there improvements in this area for the next APEX 5.0 and/or database Oracle 12 c?

    Thank you

    HELEN wrote:

    APEX 4.2

    See http://mikesmithers.wordpress.com/2012/02/22/getting-apex-to-play-with-ref-cursors

    The above article is older than 2 years. The techniques shown in the link above still valid today if we want to create a report region in the APEX are based on a function that returns a Ref Cursor?

    If the function returns the ref cursor is the only point of access that you have data then Yes, it probably is. If you have direct access to the underlying database objects and the function does not have something very complicated, then you are probably better off creating your own body of the function returning SQL query data source.

    Everything about the dynamics of ref Cursor now I divided in 2 layers, with a function for generating the dynamic SQL and another for bind parameters open the ref cursor. APEX apps can then reuse the functions of SQL query in function body return SQL query data sources (if you take a bit of care to keep the bind variable names vaguely APEX-point-friendly).

    Are there improvements in this area for the next APEX 5.0 and/or database Oracle 12 c?

    See this for the technical background on why APEX is not yet support ref Cursor and this for more information of the Oracle team on the possibility of future support. Obviously, he did not he in 4.1. I suspect that data REF CURSOR region sources depended on a minimum requirement of DB of the 11.1.0.6 (where was introduced support for the conversion of the REF CURSOR in the cursors DBMS_SQL). As minimum DB for APEX 5.0 version is 11.1.0.7, it would be a possible feature for 5.0, but it is not classified as one.

  • Fetch the Ref Cursor several times

    create or replace 
    PROCEDURE refcursor1
    AS
    TYPE r_cursor IS REF CURSOR;
    rcv_emp r_cursor;
    TYPE rec_emp IS record
    (
    empno NUMBER,
    ename VARCHAR2(20 CHAR),
    deptno number
    );
    recv_emp rec_emp;
    recv_emp2 rec_emp;
    -------------------------------------------------------
    PROCEDURE printemployeedetails AS
    BEGIN
      loop
      fetch rcv_emp INTO recv_emp;
      exit WHEN rcv_emp%notfound;
        dbms_output.put_line(recv_emp.empno||'-'||recv_emp.ename||'-'||recv_emp.deptno);
      END loop;
    END;
    -------------------------------------------------------
    PROCEDURE printemployeedetails2(p_emp r_cursor) IS
    BEGIN
      loop
      fetch p_emp INTO recv_emp2;
      exit WHEN p_emp%notfound;
        dbms_output.put_line(recv_emp2.empno||'-'||recv_emp2.ename||'-'||recv_emp2.deptno);
      end loop;
    END;
    -------------------------------------------------------
    BEGIN
      FOR i IN (SELECT deptno FROM dept order by deptno)
      loop
        OPEN rcv_emp FOR SELECT empno,ename,deptno FROM emp WHERE deptno=i.deptno;
        dbms_output.put_line(i.deptno);
        dbms_output.put_line('--------------------');
        dbms_output.put_line('calling printemployeedetails');
        printemployeedetails;
        dbms_output.put_line('                    ');
        dbms_output.put_line('calling printemployeedetails2');
        dbms_output.put_line('                    ');
        printemployeedetails2(rcv_emp);
        CLOSE rcv_emp;
      END loop;
    end;
    

    Output:

    10
    --------------------
    calling printemployeedetails
    7839-KING-10
    7782-CLARK-10
    7934-MILLER-10
                        
    calling printemployeedetails2
                        
    20
    --------------------
    calling printemployeedetails
    7566-JONES-20
    7788-SCOTT-20
    7902-FORD-20
    7369-SMITH-20
    7876-ADAMS-20
                        
    calling printemployeedetails2
                        
    30
    --------------------
    calling printemployeedetails
    7698-BLAKE-30
    7499-ALLEN-30
    7521-WARD-30
    7654-MARTIN-30
    7844-TURNER-30
    7900-JAMES-30
                        
    calling printemployeedetails2
                        
    40
    --------------------
    calling printemployeedetails
                        
    calling printemployeedetails2
                        
    
    

    Hi all

    If I open a cursor once can I collect the elements of a cursor n times as above? I see one of these procedures to print the details, but not both.

    Wonder why that I'm passing same ref cursor to a second procedure.

    It doesn't throw me an error indicating that the elements of the ref cursor is already read.

    Thank you.

    Your condition is not clear. Cursor is a pointer. He points to the result set of your query. At the time wherever you collect once, it advances the pointer to the next line and so on. I wonder if the pointer can return to the previous line once you recovered.

  • How to clear the Ref Cursor runtime error

    Hello everyone,
    the code as follows
    create or replace 
    procedure Country_sel(key in varchar2)
    as
    cc Res_RelcountryLan.countrycode%type;
    len Res_Language.langname_en%type;
    lid Res_Language.langid%type;
    ab Res_Language.Abrivation%type;
    type refcursorr is ref cursor;
    cur refcursorr;
    d_stmt varchar2(100);
    begin
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',
    RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId';
    open cur for d_stmt;
    loop
    fetch cur into cc,lid,len,ab;
    if cur%found then
    dbms_output.put_line(cc||lid||len||ab);
    else
    exit;
    end if;
    end loop;
    close cur;
    commit;
    end  Country_sel;
    When I run this code im getting
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "RASOOL.COUNTRY_SEL", line 11
    ORA-06512: at line 6
    can you please help me get rid of this problem.


    thanking you,
    Prakash
    
    d_stmt varchar2(100); 
    

    Increase the size of d_stmt. Your an a larger string assignment

    
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId'; 
    

    The size of the string above is more than 100 characters.

  • Adding the ability to use a ref Cursor in future versions of Apex

    Currently, it has been established that the Apex does not play well with the ref Cursor and how to get around that. What is a characteristic that the Apex team seeks in future versions? Currently we use Oracle 11 g and 1 g with 4.0.2 Apex. Your answer is most appreciated.

    JudJasRis

    Until the APEX development team adds this feature, I'd be:

    (1) write a pipeline function that will consume the ref cursor and return your data in pipeline to the calling report

    (2) write a procedure that will be called before the call to your report, who built a collection of apex you run your report off the coast of...

    Thank you

    Tony Miller
    Ruckersville, WILL

  • The stored procedure PL/SQL - t - it accept the custom Ref Cursor type?

    I am not able to compile the following procedure in the HR schema comes with default oracle... I use Oracle 11g Release 11.2.0.2.0 Express edition. It gives me an error (given after the code block):

    Block of code:
    CREATE OR REPLACE PROCEDURE TEST_REF IS
    DECLARE
    TYPE REF_EMP IS REF CURSOR RETURN % ROWTYPE EMPLOYEES;
    RF_EMP REF_EMP;
    V_EMP EMPLOYEES % ROWTYPE;
    BEGIN
    DBMS_OUTPUT. ENABLE (1000000);
    OPEN FOR RF_EMP
    SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
    EXTRACT THE RF_EMP IN V_EMP;
    DBMS_OUTPUT. PUT_LINE (V_EMP. FIRST_NAME. ' ' || V_EMP. LAST_NAME);
    CLOSE RF_EMP;
    EXCEPTION
    WHILE OTHERS
    THEN DBMS_OUTPUT. PUT_LINE (SQLERRM);
    END TEST_REF;
    /

    Error:
    Errors in PROCEDURE TEST_REF:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    2/1 PLS-00103: encountered the symbol "DECLARE" when waiting for an a
    What follows:
    Start function < an ID > pragma procedure subtype type
    < between double quote delimited identifiers > delete the current cursor
    There are the external language prior
    The symbol 'start' is substituted for 'DECLARE' continue.

    16/13 PLS-00103: encountered the symbol "end-of-file" when waiting for him
    one of the following values:
    (begin case declare exit end exception for goto if loop mod)
    pragma raise return null select update while with

    Get rid of the DECLARED:

    SQL> CREATE OR REPLACE PROCEDURE TEST_REF IS
      2  TYPE REF_EMP IS REF CURSOR RETURN HR.EMPLOYEES%ROWTYPE;
      3  RF_EMP REF_EMP;
      4  V_EMP EMPLOYEES%ROWTYPE;
      5  BEGIN
      6  DBMS_OUTPUT.ENABLE(1000000);
      7  OPEN RF_EMP FOR
      8  SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID > 100;
      9  FETCH RF_EMP INTO V_EMP;
     10  DBMS_OUTPUT.PUT_LINE(V_EMP.FIRST_NAME || ' ' || V_EMP.LAST_NAME);
     11  CLOSE RF_EMP;
     12  EXCEPTION
     13  WHEN OTHERS
     14  THEN DBMS_OUTPUT.PUT_LINE(SQLERRM);
     15  END TEST_REF;
     16  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL> exec TEST_REF;
    Donald OConnell
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

Maybe you are looking for

  • Firefox crashes and crash report opens

    At launch, Firefox window opens and closes immediately followed by a crash report window. I tried to uninstall and reinstall but it still would not work. I can run on the cause of Mode he opens not at all safe. I can't find a different way to open or

  • A lot of Sims 2 Double Deluxe community never stop loading

    In the Sims 2 Double Deluxe, when I try to open a large number of community or move in a family, the lot is constantly loading and never stops.  He could stay there for a whole day and the loading screen would always be there.

  • I need to uninstall Intel(r) ProSet - how to find?

    Try to install the updated driver Installer tells me that I must uninstall "Intel (R) ProSet" for windows, the Device Manager before I can continue. Can you tell me how to find it? Gateway FX7026 Windows Vista 64-bit Home Premium SP1 4 GB memory Hard

  • I lost its icon in the taskbar

    lost its icon in the task bar and have no sound

  • OfficeJet 7590

    I have problems with my officejet pro 7590 all-in-one.   It all started when I moved the printer from a network location wired and tried to use it as a wireless printer, which I thought he was capable of... I never got it to work wireless so I handed