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.

Tags: Database

Similar Questions

  • 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

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

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

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

  • 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

  • Ref cursor error message

    Hello expert;

    I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message

    ORA-06503: PL/SQL: function returned no value - slider Ref

    .. Please see below.

    function f_de return latest_cur is
    my_l_cur l_cur;
    
    begin
    open my_l_cur for
    select max(dateadded) as dateadded
    from tbl_test;
    end;
    

    I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.

    user13328581 wrote:

    Hello expert;

    I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message

    ORA-06503: PL/SQL: function returned no value - slider Ref

    .. Please see below.

    1. latest_cur the f_de function return is
    2. my_l_cur l_cur;
    3. Start
    4. Open the my_l_cur for
    5. Select max (dateadded) as dateadded
    6. of tbl_test;
    7. end;

    I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.

    by definition a FUNCTION returns a value, but your code isn't working; Therefore, the error is thrown.

    RETURN MY_L_CUR;

    the top line should take place before the END; statement.

  • Alternatives to a PIPELINED table function

    I'm writing a piece of code that display student attendance from Monday to Friday for a given date. I provide the code with the date, it determines the dates for the Monday, Tuesday... Friday of the week and then determines the days during the week the student was or was not present. My data includes two tables:

    Students
    -----------
    number of student_id,
    first name varchar2,
    last_name varchar2,
    number of campus_id

    Attendance
    -------------
    number of student_id,
    date of date_of_attendance

    I would like for the release of the tables to be in the following format:

    student_id name | last_name Mon Mar sea game Fri
    -------------------------------------------------------------------------------
    123456 x 0 1 0 1 1
    163452 Unetelle 1 1 1 1 1

    1 is if there is a record in the table of attendance for the student that day and 0 is it does not exist.

    I tried to do this using a function table in pipeline. Whenever I run the query, I get the following error:

    ORA-06552: PL/SQL: analysis of completed Compilation unit
    ORA-06553: PLS-801: internal error [hshuid: READ invalid]
    06552 00000 - "PL/SQL: %s.
    * Cause:
    * Action:
    Error on line: column 14:12

    I'm using Oracle 10gXE and according to support notes 559786.1 it "should" be due to a bug which follows from the definition of type, including a reserved word. I checked and I have all these words in my definition of type. I tried to run the same code in an 11g database and it worked. Unfortunately using 11 g is not an option for this task.

    Anyone can suggest that another way to achieve this?

    You can use a function table.

    See the "Concepts of function Table" section of the RFSO: http://docs.oracle.com/cd/B19306_01/appdev.102/b14289/dcitblfns.htm

    It shows a simple example. You can change your service (remove PIPELINED) to return a collection in bulk or can return the ref cursor).

  • Casting table PL/SQL for the type of existing table and back ref cursor

    Hello



    I have the problem of casting a pl/sql table for the type of an existing table and turning the ref cursor to the application. Casting a ref cursor back and number of pl/sql table works well.



    Declarant

    < strong > TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities >

    within the stored procedure, fill in a table of this type temp_table_name and returning the ref cursor help

    < strong > results OPEN to SELECT * FROM TABLE (CAST (temp_table_name AS type_table_name)); < facilities >

    generates an error. type_table_name is unknown in this distribution. According to me, this happens because of the declaration of the type locally.



    Statement type_table_name inside the package specification does not work neither. Incredible, cast to the said dbms_sql.number_table to specify ref cursor back and dbms_sql package works very well!



    < strong > CREATE TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities > deals without any error but creates an invalid type complain a reference to package_name.table_name



    I don't want to declare every column in the table in type_table_name, because any change the table_name table would result in an inconsistent type_table_name.



    Thanks in advance!

    Edited by: user6014545 the 20.10.2008 01:04

    In any case you are right that there is a problem around anchorage (or maintaining) types of objects persistent to match the table structures, they may represent.

    In the case you describe, you might be better off just open the refcursor immediately the using one of the techniques described in the http://www.williamrobertson.net/documents/comma-separated.html to manage the delimited list.

    In the more general case where the line of treatment is necessary, you may make the pipeline functions.

    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    SQL> CREATE TABLE table_name
      2  AS
      3     SELECT ename column_name
      4     FROM   emps;
    
    Table created.
    
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3     TYPE type_name IS TABLE OF table_name%ROWTYPE;
      4
      5     FUNCTION function_name_pipelined (
      6        parameter_name IN VARCHAR2)
      7        RETURN type_name PIPELINED;
      8
      9     FUNCTION function_name_refcursor (
     10        parameter_name IN VARCHAR2)
     11        RETURN sys_refcursor;
     12  END package_name;
     13  /
    
    Package created.
    
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3     FUNCTION function_name_pipelined (
      4        parameter_name IN VARCHAR2)
      5        RETURN type_name PIPELINED
      6     IS
      7     BEGIN
      8        FOR record_name IN (
      9           SELECT table_alias.*
     10           FROM   table_name table_alias
     11           WHERE  table_alias.column_name LIKE parameter_name) LOOP
     12
     13           PIPE ROW (record_name);
     14        END LOOP;
     15
     16        RETURN;
     17     END function_name_pipelined;
     18
     19     FUNCTION function_name_refcursor (
     20        parameter_name IN VARCHAR2)
     21        RETURN sys_refcursor
     22     IS
     23        variable_name sys_refcursor;
     24     BEGIN
     25        OPEN variable_name FOR
     26           SELECT table_alias.*
     27           FROM   TABLE (package_name.function_name_pipelined (
     28                     parameter_name)) table_alias;
     29
     30        RETURN variable_name;
     31     END function_name_refcursor;
     32  END package_name;
     33  /
    
    Package body created.
    
    SQL> VARIABLE variable_name REFCURSOR;
    SQL> SET AUTOPRINT ON;
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME
    -----------
    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    
    7 rows selected.
    
    SQL> ALTER TABLE table_name ADD (new_column_name VARCHAR2 (1) DEFAULT 'X');
    
    Table altered.
    
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME NEW_COLUMN_NAME
    ----------- ---------------
    ALLEN       X
    WARD        X
    MARTIN      X
    BLAKE       X
    CLARK       X
    ADAMS       X
    JAMES       X
    
    7 rows selected.
    
    SQL>
    
  • Irregular data loss - function from PL/SQL returning data using Ref Cursor

    Database Version: 10.2.0.4.0 (node 2 CARS)

    The high-level process flow is as below:
    (1) insert records in a few tables & commit the same
    (2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
    -> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
    Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
    (3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.

    We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
    Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.

    Guidance on what could be the reason?

    * Examples of Code for the function:
    CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
    outinstrid in NUMBERS
    outinstrkey in NUMBERS
    rownumberstart in NUMBERS
    rownumbereend in NUMBERS
    err_code OUT VARCHAR2,
    err_msg OUT VARCHAR2)
    RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
    IS
    REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
    BEGIN

    OPEN FOR REF_HRCH_TOTAL_CURSOR
    SELECT *.
    FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
    OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
    WHERE A.outputid = B.outputid
    AND A.outputid = C.outputid AND A.outputkey = B.outputkey
    AND A.outputkey = C.outputkey AND A.outputid = outinstrid
    AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
    AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
    ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
    WHERE ROWNUMBER < rownumbereend
    AND ROWNUMBER > = rownumberstart;


    RETURN REF_HRCH_TOTAL_CURSOR;
    EXCEPTION
    WHILE OTHERS
    THEN
    err_code: = x_progress | ' - ' || SQLCODE;
    err_msg: = SUBSTR (SQLERRM, 1, 500);

    END FUNC_GET_HRCH_TOTAL_DATA;
    /

    Published by: meet_sanc on February 16, 2013 10:42

    Your SELECT statement is almost certainly incorrect

    SELECT *
      FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER
               FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
              WHERE A.outputid = B.outputid
                AND A.outputid = C.outputid AND A.outputkey = B.outputkey
                AND A.outputkey = C.outputkey AND A.outputid = outinstrid
                AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
                AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
              ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
     WHERE ROWNUMBER < rownumbereend
       AND ROWNUMBER >= rownumberstart;
    

    Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.

    You definitely want to do something in the sense of the canonical askTom wire

    select *
      from ( select a.*, rownum rnum
               from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
              where rownum <= MAX_ROWS )
     where rnum >= MIN_ROWS
    

    That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.

    As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.

    Justin

  • join a Ref cursor to a table

    Hello all;

    Can you please show me a simple example on how to join a Ref cursor to a table, because I have a function that returns a Ref Cursor and I want to call this function in another function (B) and then he join a table in this function (B)

    How do I join a Ref cursor to a table

    I can do on my 11 GR 2

    SQL> declare
      c         sys_refcursor;
      l_ename   emp.ename%type;
    begin
      open c for
        select * from dept where loc = 'DALLAS';
    
      select ename
        into l_ename
        from emp, xmltable ('ROWSET/ROW' passing xmltype (c) columns deptno number path 'DEPTNO') x
       where emp.deptno = x.deptno
         and rownum = 1;
    
      dbms_output.put_line (l_ename);
    end;
    /
    SCOTT
    PL/SQL procedure successfully completed.
    
  • parallel in pipeline table function

    Hi all

    To "allow the parallel pipeline" table function, what I need to turn a query parallel session first?

    I read a few white papers or web pages on map and reduce implemented with function table Oracle and see that, based on the table.

    Use the cursor in the loop to get a line, run out! This replaces SQL pl/sql.

    What is the cost that must be paid according to the table?

    Finally, how can I confirm that Oracle has put the table function in parallel?

    Best regards

    Leon

    user12064076 wrote:

    In my application, I wrote stored procedures that return a collection of user-not of the types of objects to Java.

    Flawed approach using memory expensive private server (PL/SQL PGA) caching SQL data and then push this data to the client - when the customer can use instead the more scalable and higher shared cache buffer memory instead.

    With the types of objects, we can remove most of the redundent data.

    This statement makes no sense that it is the same for SQL and sliders. And remove redundant data is preferable to the SQL itself - through partitioning engine pruning, predicates, only by selecting the columns there is place for the projection of SQL and so on.

    This OO design reduces the load on the network and makes it easy for Java to parse.

    Incorrect answer. It does not reduce network load - it can actually increase. Regarding Java 'parsing' - it's wrong from the beginning approach if the customer is required to analyze the data it receives from the server database. The analysis requires time CPU. Many average general processor muscle which will degrade the performance of analysis.

    You may be using the analysis out of context here? Find it me hard to believe that one could design an application and use a server database in this way. The analysis of means for example to receive XML data (text) and then he analysis in an object - like structure for use.

    Data of the database must be recovered by the customer in a binary structured format and not in a free format that requires the client to analyze in a structured format.

    But the problem is that we accumulate all data in memory first and push them to the client as a whole. If it's too huge, ORA-22813 occurs.
    This is why I intend to use the table of piplelined function.

    How that will solve the problem?

    As I followed your logic:
    (1) you do not use the cursor for some obscure (and probably completely unjustified) reason.
    (2) you may not return large collection PL/SQL variables without significantly dent PGA (process private memory) on the server and running into errors (this approach is conceptually incorrect anyway)
    (3) you are now using an array of pipeline that executes PL/SQL code to execute SQL code - and in turn must be executed by the client as a SQL using a slider

    So why put all the other moving parts (the pipeline code) between the two when the customer
    (a) must use SQL to access?
    (b) create a cursor?

    If, as you say, I returned a cursor, it would be very difficult for Java organize data.

    A table of pipeline must be able to be used through a cursor. All the DML statements from a client by Oracle are analyzed as cursors.

    Read the language PL/SQL Oracle® Database reference guide section on ' + chaining Pipelined Table Functions for Multiple Transformation + ".

    The format using a pipeline is (from the manual):

    SELECT * FROM TABLE(table_function_name(parameter_list))
    

    The "+ pipeline + ' is created by the SQL engine-, he need SQL to execute the PL/SQL code via the function TABLE() SQL.

    You said that the reason to use a pipeline transforms a structure of relational data stored in a structure of the object. You don't need a pipeline for it. Plain vanilla SQL can do the same thing, without the fixed costs of use PL/SQ, SQL data recovery and change within the pipeline between PL/SQL and SQL context engines.

    You simply call the constructor of the class of object in the projection of SQL and the cursor SQL returning the instantiated objects. For example

    create or replace type TEmployee is object(
     .. property definitions ...
    );
    
    create or replace type TEmployeeCollection is table of TEmployee;
    
    select
      TEmployee( col1, col2, .., coln ) as EMP_COLLECTION
    from emp
    where dept_id = :0
    and salary > :1
    and date_employed >= :2
    order by
      salary, date_employed
    

    No need for PL/SQL code. No need for a pipeline. The client will open the cursor and extraction of objects in a collection. The same approach that the customer would have used during extraction of a cursor on a table of pipeline function.

    Pipelines are best used as a process of transformation of data where only SQL cannot perform the transformation. I never in many years of design and writing applications used Oracle PL/SQL pipeline into production on a SQL table. Simply because the SQL itself is capable and powerful enough to do the job - and do it faster and better.

    I used pipeline is to transform the data from external sources into sets of SQL data. For example, a pipe on a web service. When the code PL/SQL of the constructions of the SOAP envelope, the HTTP call, analyzes the XML and returns the content in form of lines and columns - that allows to run a SQL SELECT on web-service-turned-into-a-SQL-table.

    If you'd told me that Leon - it seems to me that your approach is a typical approach to Java that has very little understanding of the concepts of database and Oracle databases. You can't deal with Oracle as a simple persistence layer. You can't treat SQL and PL/SQL as a simple i/o interface for the extraction of data from Oracle and grinding that in Java. Not if you think that your system to run Java and scaling.

    Rethink the Oracle layer, use properly - and your application will occur and will scale. Guaranteed.

    However, from my experience, many J2EE developers choose to treat the Oracle as a black box, not further that a kind of file system loaded to store structured data and try to do it in the Java layer. And this fail. And I saw him failing - of the jaw dropping kind epic failures (knocking all the national newspapers and media as a result and an impact on ordinary people who have to deal with the Government).

    And it's a shame... SQL and PL/SQL are superior to Java in this regard and are the layers much more able to cope and a power of data in the database. Example of the real world - largest table in our busiest database develops between 350 and 450 million lines per day and all our calculations of the data in this table is inside the database layer - and not in a layer of Java. Oracle performs and scales beautifully... when used correctly.

  • 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

  • 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

  • Made Oracle 6i LOV with ref cursor returned by a function of database

    Hi all

    I want to dynamically create a LOV in oracle forms 6i using the value of ref cursor returned by the function of database.

    is this possible?

    Using loop, I could able to display the values returned by the ref cursor, but how can I assign these values in the LOV?

    You will need to loop through your REF Cursor and assign each value to a group of registration of forms and then assign the Group Record to your LOV.  Take a look at the built-ins CREATE_GROUP, ADD_GROUP_COLUMN and ADD_GROUP_ROW in the help system of forms for more information about how to use these built-ins and examples of how to use them.

    Craig...

Maybe you are looking for

  • Linux on M52 8113 D1U

    XP installs and runs very well. When I try and install Linux (Fedora Core 10 or 12, Ubuntu) I get sporadic crashes during installation. Aybody got Linux installation on this machine or any recommendation for the core or the bios options? I suspect ev

  • The lamp indicator yellow LED on Dell PowerEdge 1950

    Hello You asked me to "remove" the warnings of several Dell PowerEdge 1950 LED amber. I looked at the LED and was unable to 'remove' the warning using the controls on the LED display on the front the 1950s. How this is done? Thank you.

  • Notifications push on BB 10 Simulator

    Hello I want to send notifications push for BlackBerry 10 Simulator. What should I install? With 7 BB Simulator, I had 6 MDS, which delivered the push notifications. Thank you Nick

  • Confused about accts Admin and users

    Windows 7: I have an Admin account, and then I have a user account, then a guest account.  I worked in my user account. While in the user account, I can't turn on the firewall. When I log into the Admin account, it indicates that the firewall is enab

  • How to play .vob files

    Hello I'm playing files .vob to an external hard drive to usb on my netbook. I assumed that they would play with Windows Media Player but I can't get this to work, I need to convert the files? If yes how can I do this? Maybe that was an upgrade that