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.

Tags: Database

Similar Questions

  • Recovery of the records by using the Ref Cursor or indexes per Table (which is better)

    Hi all

    I am interested to know if there is a performance (or other) advantages to return a result set from an Oracle stored procedure for a client application (for example, in Java) by using a Ref Cursor or Index by Table, respectively. Most of the people I met who know Java seem to use a Ref Cursor but did not say why this method is preferable. I'm not too familiar with Java and do not have the opportunity to test the difference between either method, but I am very interested in the other user forum about this view, gauging

    Kind regards

    Kevin.

    KevinFitz wrote:
    Hi zerathul,

    Thanks for the quick and helpful response. A REF CURSOR would be the best solution if the same set of results (content and number of records returned) should be dealt with by the application of the 'customer '. I'm guessing that maybe in this situation 'theoretical' that there might be less network traffic to return the set of results through an associative array,

    Kind regards

    Kevin.

    Yes, it would always be the best solution, because an associative array would mean collecting all the data in memory of expensive PGA on the database server before they pass any return on the network, while a fair Ref cursor is to feed the data over the network (maybe a little extra load, but you were unlikely to notice). Also the client application would treat a ref as of rows returned cursor data recovery and could treat them upon their arrival, an associative array is a collection of data which will then be entirely spent before any treatment could be done and then the treatment should go through the entire table to do.

    REF CURSOR will also provide other information such as the error codes etc regarding SQL if necessary. If you get an error when filling a table on the side of the database, it is not so easy to recover this error to the client.

    REF CURSOR is designed for this purpose. Use them.

  • help how to extract the ref cursor in the table field

    Hello.


    I have a query similar to the following:
    select department_id, cursor (select employee_id from employees where department_id = d.department_id)
      from departments d
    Expecting to get several lines, I want this select this option to be in bulk sampled in a table variable nested (of another type of nested table) which is copied to an out parameter in a procedure. I have some doubts:
    1 should. what I create the column in the inner nested table that will keep the result of the ref cursor? Ref cursor colunm? A sort of column Adrien?
    2. If the column in the nested table inside that will keep the result of the ref cursor is another array, how can I write the result of the entire query in a single volume?

    (I want to bulk collect everything in a single query, I know how to do with pl/sql do not inflate but using two nested for loops, that's what I try to avoid).


    Thanks in advance.

    It would be simpler:

    declare
        type dep_emp_list_tbl_type
          is table of sys.OdciVarchar2List;
        v_dep_emp_list_tbl dep_emp_list_tbl_type;
        v_dep_id_tbl sys.OdciNumberList;
    begin
        select  department_id, cast(multiset(select employee_id from hr.employees where department_id = d.department_id) as sys.OdciVarchar2List)
          bulk collect into v_dep_id_tbl,v_dep_emp_list_tbl
          from hr.departments d;
    end;
    /
    

    SY.

  • 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

  • How to pass a REF CURSOR from a function

    I tried to compile the following function:

    CREATE or REPLACE FUNCTION example
    RETURN REFCURSOR
    IS
    heart REFCURSOR;
    BEGIN
    OPEN FOR heart
    "SELECT x FROM table";
    RETURN cur;.
    END;

    but I get:

    PLS-00201: identifier 'REFCURSOR' must be declared.

    Can you help me in the right syntax? I never return a REF CURSOR to a function.
    Is my Version of Oracle 8.1.7

    Thank you!

    You cannot use SYS_REFCURSOR in Oracle 8i.
    The work is approximately as follows

    create or replace package my_pk as
    type my_cur is REF CURSOR;
    end my_pk;
    
    -- Now write your function
    create or replace function my_func return my_pk.my_cur
    as
    l_cur my_pk.my_cur;
    begin
    open l_cur for select * from table_name;
    return l_cur;
    end my_func;
    

    Thank you
    Andy

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

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

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

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

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

  • What is the difference between the ref cursor and the sys_refcursor.

    create or replace procedure GetEmployeesInDept (c sys_refcursor)

    Hello


    I have a query related to the above stored procedures.
    When you set the cursor, we mentioned as sys_refcursor and in some US sites I saw him as a REF CURSOR as shown

    create or replace procedure GetEmployeesInDept (Ref Cursor c)


    Please tell me what is the difference between the ref cursor and the sys_refcursor.

    http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14261/tuning.htm#sthref2376

    Concerning

    Etbin

  • How print/store in the ref cursor block pl/sql folder?

    How print/store in the ref cursor block pl/sql folder?

    return to the SQL * the method I showed above:

    SQL> create or replace procedure test (p_refcur out sys_refcursor)
      2  is
      3  begin
      4    open p_refcur for select * from dual union all select * from dual;
      5  end test;
      6  /
    
    Procedure created.
    
    SQL> var r refcursor;
    SQL> begin
      2    test(:r);
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> print r;
    
    D
    -
    X
    X
    
    2 rows selected.
    
  • Pipelined table vs ref cursor in a function return

    Hi gurus,

    Everybody has discovered that a (subject) is faster on the other? Data will be primarily consumed from an external application (.net). What are the benefits? I can't decide if that use is

    Thank you very much.

    user12868294 wrote:
    Hi gurus,

    Everybody has discovered that a (subject) is faster on the other? Data will be primarily consumed from an external application (.net). What are the benefits? I can't decide if that use is

    Thank you very much.

    They are two different things.

    A pipeline table acts as an array, but you must always choose in it and so if your consumption that in .net, you would still use a Ref Cursor I guess to query this table in pipeline (I guess .net is not query the tables directly, but must use some sort of slider Ref?)

    Tables in pipeline can be fast, but it depends on what you need to. Is there a reason why you really need a feature in pipeline? If this is not the case, just use a normal query with a Ref Cursor, so your .net application only retrieves the data properly.

  • Insert data from variables in the Ref Cursor

    I do not know how to return data from ref cursor variables That's what I've tried so far...
    CREATE OR REPLACE type num_obj as object (
      t_number number ,
      t_type varchar2(10) ,
      t_desc varchar2(40)
    ); 
    CREATE OR REPLACE type num_table as table of num_obj; 
    
    procedure get_all_data(p_p1 in varchar2, p_rc OUT SYS_REFCURSOR) is
       l_dat1 number := 2;
       l_dat2 varchar2(10);
       l_dat3 varchar2(40);
       t_num_o num_obj;
       t_num_t num_table;
    begin
      for l_indx in 1..5 loop
         l_dat1 := l_dat1 + l_indx;
         if ( mod(l_dat1,2)=0) then
           l_dat2 := 'EVEN';
         else
           l_dat2 := 'ODD';
         end if;
         l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number'; 
         l_num_o := num_obj (l_dat1, l_dat2, l_dat3);
         l_num_t := num_table(l_num_o);
      end loop;
      open p_rc for select * from table(l_num_t);
      close p_rc;
    end;
    At the end, to achieve this in Ref Cursor:
    t_number | t_type | t_desc
    ---------------------------------------
    3        | ODD    | Number 3 is ODD number
    5        | ODD    | Number 5 is ODD number
    8        | EVEN   | Number 8 is EVEN number
    12      | EVEN    | Number 12 is EVEN number
    17      | ODD     | Number 17 is ODD number
    Can something like that, where I did wrong?

    BTW. I did this with the function in pipeline, now I want to try a different method.

    The refcursor can not be closed in the procedure - you must return refcursor open to the appellant.
    the appellant must read and then close it.
    There are also some errors in the names of variables and an assignment to the collection.

    Try this version:

    CREATE OR REPLACE
    PROCEDURE GET_ALL_DATA(P_P1 IN VARCHAR2, P_RC OUT SYS_REFCURSOR) IS
       l_dat1 number := 2;
       l_dat2 varchar2(10);
       L_DAT3 VARCHAR2(40);
       L_NUM_O NUM_OBJ;
       l_num_t num_table := num_table() ;
    BEGIN
      for l_indx in 1..5 loop
         l_dat1 := l_dat1 + l_indx;
         if ( mod(l_dat1,2)=0) then
           l_dat2 := 'EVEN';
         else
           l_dat2 := 'ODD';
         end if;
         l_dat3 := 'Number ' || l_dat1 || ' is ' || l_dat2 || ' number';
         L_NUM_O := NUM_OBJ (L_DAT1, L_DAT2, L_DAT3);
         L_NUM_T.EXTEND;
         l_num_t( l_indx ) := l_num_o;
      end loop;
      OPEN P_RC FOR SELECT * FROM TABLE(L_NUM_T);
    END;
    /
    
    SQL> variable xx refcursor
    SQL> execute GET_ALL_DATA( '', :xx );
    
    PL/SQL procedure successfully completed.
    
    SQL> print :xx
    
      T_NUMBER T_TYPE     T_DESC
    ---------- ---------- ----------------------------------------
          3 ODD           Number 3 is ODD number
          5 ODD           Number 5 is ODD number
          8 EVEN       Number 8 is EVEN number
         12 EVEN       Number 12 is EVEN number
         17 ODD           Number 17 is ODD number
    
  • 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.

Maybe you are looking for

  • MacBook Air no longer recognizes the printer wireless Epson WF-7620

    It worked well always. Recently, my MacBook Air (I have two with the same problem), the Ipad and the Iphone can not recognize the printer Epson WF - 7620 Airprint wireless. This medication is properly updated, and wifi is okay. If I connect it by USB

  • Inroom Pro A300 - 2 3 PSAG9E - choppy video playback, CPU at 100% of fortification

    Hello I have problems with my Toshiba laptop for a week about playback of AVI files. This happens both WMP and VLC, so I'm sure it is impossible either of those. I checked my laptop computer for viruses, spyware and malware and found nothing. I've be

  • 6.18 Skype starts, the process ends directly after startup

    Running Windows 7 family SP1, X 64, the latest version of Skype. Whenever I run Skype, the output connected icon in the taskbar, but it disappears as soon as I have the mouse over it. Looking at the Task Manager, Skype starts and ends and then right

  • Satellite A500 - failure WLAN

    Hello. My wife has a Satellite A500 PSAR3A-026002 running 32-bit win7 and the Wi - Fi connection has suddenly stopped working for no apparent reason. In common with a previous thread, this coincided with the death of the battery. Shows Device Manager

  • El Capitan installed with problems

    Hi people, I just installed El Capitan of Snow Leopard 10.6.8. Everything seemed okay... until I opened the first application, which is a PDF file. I tried to close the new Acrobat 8 pro installed with El Capitan, but it does not close and the screen