Opening cursor on pipelined functions

Hi forum,
Is it possible to open a cursor /any iteration of rows possible in pipelined functions ?
Pls see the example below :
cursor c is select * from TABLE ( generate_pipelined_rows())
and iterate through cusror variable of C?
Thaks,
Aneesh

may be something like this
FOR c IN (SELECT * from TABLE(generate_pipelined_rows()))
Loop
--process data
END LOOP;

Similar Messages

  • Open Cursor using other function/procedure

    Hi
    I have a procedure that return a cursor to Java, but if it send a parameter or other I wanted to call a procedure or function and return cursor to java , Is possible it ?
    Example
    PROCEDURE  XYZ ( P_ORD    IN  NUMBER,
                     p_CURSOR OUT SYS_REFCURSOR)
    IS
    BEGIN
       IF P_ORD  =1 THEN
          -- here I want to open cursor from other procedure/function
          OPEN P_CURSOR 
       ELSIF P_ORD  = 2 THEN
       END IF;
    END XYZ;Message was edited by:
    muttleychess

    Looking at your example code, you say you want to open a cursor from another procedure.
    I would suggest taking a step back and looking into the basics of procedural programming, especially in the area of variable scopes.
    The scope of the cursor declared in another procedure will be that it exists within that procedure only.
    In order to use another procedure's cursor you would have to call that procedure and have it return a SYS_REFCURSOR to your first procedure in the same manner you are trying to return a sys_refcursor to your Java code.

  • Use PipeLine function as datasource

    Hi all.
    Does anybody use PipeLine function as datasource for Bi EE ? Do you have any experience ?

    For more discuss :
    I was read article from Venkatakrishnan
    http://oraclebizint.wordpress.com/2007/09/21/oracle-bi-ee-101323-ref-cursors-and-pipelined-functions/
    and in that case all lok's fine and work. But in my case I was neded disable aggregate and order by functionality , becouse have some Issues. can anybody comment this situation :What's wrong in using PipeLine and BIee ?

  • Metrics " Current Open Cursors Count "

    Hi,
    I get an Alert message Metrics " Current Open Cursors Count is at 1201 '" on 10g database version 10.2.0.1.0 . Can anyone help me to solve this.
    Thanks
    Sree

    Sree,
    The Metric corresponds to the number of records in V$OPEN_CURSOR internal view.
    The number of open cursors is a function of the number of concurrent users and the application code ,so 1201 may not necessaryly indicate a problem – it could be that you system is genuinely very busy.
    You should start worrying if the number of open cursors consistently grows over time (while the workload is steady). In this case you may have a “cursor leak” – a piece of code that opens a cursor, but does not close it.
    You can check that with
    select substr(sql_text,1,30) , count(*) cnt
    from v$open_cursor
    group by substr(sql_text,1,30)
    order by 2 desc
    If the current open cursor are getting close to the max allowed(OPEN_CURSOR parameter), you may reset them using share pool flush (note that the shared pool flush may have some small performance impact on the system).
    Hope that helps,

  • XSL Database Functions throwing "ORA-01000: maximum open cursors exceeded"

    In my BPEL process, I have a large dataset requiring enrichment of the data by looking up values in a database. I'm doing this in an XSL transformation using either; orcl:lookup-table() or orcl:query-database() functions. This works ok for a number of records, but then fails with "ORA-01000: maximum open cursors exceeded".
    This implies that these functions are not closing down open cursors after use. Is this a bug, or can I configure the data-sources to handle this?
    Thanks.

    I don't see any settings to fix this on the data-source itself.
    http://download-uk.oracle.com/docs/cd/B31017_01/integrate.1013/b28988/trouble.htm#BABCBFHA
    4.11.2 ORA-00604: Error Occurred at Recursive SQL Level 1 ORA-01000: Maximum Open Cursors Exceeded
    If i see this..Oracle just advices just to set the PROCESSES parameter on the database high enough so it wont happen :)

  • Question about cursors in a function and how to return the results

    Hi all,
    Some tech info:
    I'm using Oracle 11G database and APEX 4.0.2.00.06
    I use three cursors in a function. My function is called in an APEX standard report, like this by example:
    SELECT fnc_exp(tab.arg1, tab,arg2) FROM table_exp tab;
    My question is: how can I return the values calculated from my function to a standard APEX report? Before, this function was used like this by Oracle Forms to fetch the cursors in the right table columns:
    open c_a;
    fetch c_a into :loc.arg1;
    close c_a;
    open c_b;
    fetch c_b into :loc.arg2, :loc.arg3, :loc.arg4, :loc.arg5;
    close c_b;
    Thanks for your advices!
    Maybe my solution is not right, if you have better ideas, please suggest :)
    PS: If you need more details, please ask which you need.

    Hi,
    I don't think you can do exactly like that in APEX.
    Go for a pipelined function if you want the value be returned from the function.

  • How do you pass parameters to a Pipelined function?

    I am using Oracle 10G and the ODP .NET 32 bit client.
    I am facing an issue trying to use variable binding with a pipeline function in Oracle. I am using ODP .NET for connecting to the database.
    If you want to be familiar with PIPELINED functions, you can read [this  blog.|http://oradim.blogspot.com/2007/10/odpnet-tip-using-pipelined-functions.html]
    I have very similar code with a difference. My function takes in two parameters that I need to pass to get the table. This is working in SQLPLUS without any issues.
    In my C# code, however things change. My function no longer returns a recordset (data reader), if I use the standard method of assigning the parameters.
    The code will work if I concat the variables in a string.
    Here is the example that doesn't work.
            static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
                try
                    OracleCommand od = oc.CreateCommand();
                    od.CommandType = System.Data.CommandType.Text;
                    od.CommandText = "select * from table(pkg_fetchPOInfo.getPORowsTable(:1,:2))";
                    OracleParameter op1 = new OracleParameter();
                    op1.ParameterName = "1";
                    op1.OracleDbType = OracleDbType.Varchar2;
                    op1.Direction = System.Data.ParameterDirection.Input;
                    op1.Size = 7;
                    op1.Value = strPONumber;
                    od.Parameters.Add(op1);
                    OracleParameter op2 = new OracleParameter();
                    op2.ParameterName = "2";
                    op2.OracleDbType = OracleDbType.Varchar2;
                    op2.Direction = System.Data.ParameterDirection.Input;
                    op2.Size = 3;
                    op2.Value = "US";
                    od.Parameters.Add(op2);
                    OracleDataReader or = od.ExecuteReader();
                    return or;
                catch (Exception e)
                    Console.WriteLine("Error " + e.ToString());
                    return null;
            }Here is the example that does.
          static OracleDataReader fetchData(OracleConnection oc, string strPONumber)
                try
                    OracleCommand od = oc.CreateCommand();
                    string formSQL = "Select * from table(pkg_fetchPOInfo.getPORowsTable('"+strPONumber+"','US'))";
                    od.CommandType = System.Data.CommandType.Text;
                    od.CommandText = formSQL;
                    OracleDataReader or = od.ExecuteReader();
                    return or;
                catch (Exception e)
                    Console.WriteLine("Error " + e.ToString());
                    return null;
            }

    throw it into an anonymous block and it should work for you.
    --create or replace type varcharTableType as table   of varchar2 (4000);
    create or replace
    PACKAGE TESTP AS
      function TESTPIPE(nr in number, nr2 in number) return varchartabletype pipelined;
    END TESTP;
    CREATE OR REPLACE
    PACKAGE BODY TESTP AS
      function TESTPIPE(nr in number, nr2 in number) return varchartabletype pipelined AS
          CURSOR TESTPIPE_cur
           IS
              SELECT (level + 1) datam
                FROM dual
              connect by level < nr;
         vtt varchartabletype ;
      BEGIN
             OPEN TESTPIPE_cur;
               LOOP
                  FETCH testpipe_cur
                  BULK COLLECT INTO vtt LIMIT nr2;
                  FOR indx IN 1 .. vtt.COUNT
                  LOOP
                      Pipe Row ( vtt( indx ) )  ;
                  END LOOP;
                  EXIT WHEN testpipe_cur%NOTFOUND;
               END LOOP;
      END TESTPIPE;
    END TESTP;
           public static void pipeTest()
                String conString = GetConnectionString();
                OracleConnection _conn = new OracleConnection(conString);
                _conn.Open();
                OracleCommand oCmd = new OracleCommand();
                oCmd.CommandText = "begin open :crs for Select * from table(testp.testpipe(:nr,:nr2)); end;";
                oCmd.CommandType = CommandType.Text ;
                oCmd.Connection = _conn;
                OracleParameter crs = new OracleParameter();
                crs.OracleDbType = OracleDbType.RefCursor;
                crs.Direction = ParameterDirection.Output;
                crs.ParameterName = "crs";
                oCmd.Parameters.Add(crs);
                OracleParameter nr = new OracleParameter();
                nr.OracleDbType = OracleDbType.Int64;
                nr.Direction = ParameterDirection.Input ;
                nr.ParameterName = "nr";
                nr.Value = 25;
                oCmd.Parameters.Add(nr);
                OracleParameter nr2 = new OracleParameter();
                nr2.OracleDbType = OracleDbType.Int64;
                nr2.Direction = ParameterDirection.Input;
                nr2.ParameterName = "nr2";
                nr2.Value = 10;
                oCmd.Parameters.Add(nr2);
                using (OracleDataReader MyReader = oCmd.ExecuteReader())
                    int ColumnCount = MyReader.FieldCount;
                    // get the data and add the row
                    while (MyReader.Read())
                        String s = MyReader.GetOracleValue(0).ToString();
                        Console.WriteLine(string.Format("i={0}", s));
                Console.ReadLine();
            }

  • ORA-22905 with pipelined function

    Hi,
    I have a strange behaviour that I do not understand.
    The code below does not work. It gives me the following errors:
    ORA-22905: cannot access rows from a non-nested table item
    ORA-06512: at line 10
    ORA-06512: at line 19
    The problem comes from the line 14 in that function
    adm_usergroup.GET_GROUPIDS (userid_in)
    If I replace the variable userid_in by its values then it perfectly works.
    Can someone give me an explanation ?
    The adm_usergroup.GET_GROUPIDS (userid_in) is a pipelined function that querry a group of tables and return IDs which are number.
    A call to the function works fine as using it directly in a select statement.
    Cheers,
    Sebastien
    1 DECLARE
    2 l_groups AUTH_TYPE.GROUP_RT;
    3 l_groups_rec authgroup%ROWTYPE;
    4
    5 FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
    6 RETURN AUTH_TYPE.GROUP_RT
    7 IS
    8 l_groups_rt AUTH_TYPE.GROUP_RT;
    9 BEGIN
    10 OPEN l_groups_rt FOR
    11 SELECT ag.*
    12 FROM authgroup ag
    13 WHERE AG.GROUPID IN
    14 (SELECT * FROM table (adm_usergroup.GET_GROUPIDS (userid_in)));
    15
    16 RETURN l_groups_rt;
    17 END GET_GROUPS;
    18 BEGIN
    19 l_groups := GET_GROUPS (1);
    20
    21 LOOP
    22 FETCH l_groups INTO l_groups_rec;
    23
    24 EXIT WHEN l_groups%NOTFOUND;
    25 DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
    26 END LOOP;
    27
    28 CLOSE l_groups;
    29 END;

    by the way here is the full code
    CREATE OR REPLACE PACKAGE AUTHDB.ADM_USERGROUP
    IS
       -- get the group and sub-group ids of a given user id
       FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN authgroup_set
          PIPELINED;
    END;
    CREATE OR REPLACE PACKAGE BODY AUTHDB.ADM_USERGROUP
    IS
    FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN authgroup_set
          PIPELINED
       IS
          CURSOR group_cur
          IS
             SELECT   mo.groupid
               FROM   memberof mo
              WHERE   MO.USERID = userid_in
             UNION
                 SELECT   gh.groupid
                   FROM   GROUPHIERARCHY gh
             CONNECT BY   PRIOR GH.GROUPID = GH.PARENTGROUP_ID
             START WITH   GH.PARENTGROUP_ID IN (SELECT   mo.groupid
                                                  FROM   memberof mo
                                                 WHERE   MO.USERID = userid_in);
       BEGIN
          FOR rec IN group_cur
          LOOP
             PIPE ROW (authgroup_type (REC.GROUPID));
          END LOOP;
       END;
    END;
    CREATE OR REPLACE
    TYPE        AUTHDB.AUTHGROUP_TYPE AS OBJECT (GROUPID NUMBER (10));
    CREATE OR REPLACE
    TYPE        AUTHGROUP_SET AS TABLE OF authgroup_type;
    DECLARE
       l_groups       AUTH_TYPE.GROUP_RT;
       l_groups_rec   authgroup%ROWTYPE;
       FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN AUTH_TYPE.GROUP_RT
       IS
          l_groups_rt   AUTH_TYPE.GROUP_RT;
       BEGIN
          OPEN l_groups_rt FOR
             SELECT   ag.*
               FROM   authgroup ag
              WHERE   AG.GROUPID IN
                            (SELECT   * FROM table (cast(adm_usergroup.GET_GROUPIDS (userid_in) as authgroup_set)));
          RETURN l_groups_rt;
       END GET_GROUPS;
    BEGIN
       l_groups := GET_GROUPS (1);
       LOOP
          FETCH l_groups INTO   l_groups_rec;
          EXIT WHEN l_groups%NOTFOUND;
          DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
       END LOOP;
       CLOSE l_groups;
    END;

  • Use of Pipelined Function in Forms10g(10.1.0.2)...

    Hi ,
    I test the routines found in http://sheikyerbouti.developpez.com/recordset/record_set.htm
    I have a problem in the sample routine in Forms10g regarding pipelined function.
    Whereas , the whole routine database part and client side in SQL*PLUS works fine.... the client side on Forms10g does not.......
    I used two versions in when-button-pressed trigger:
    1)Declare
            cur SYS_REFCURSOR ;
    begin
           Open cur for SELECT * FROM  TABLE(Pkg_Cur_.Get_Raws2(CURSOR(SELECT * FROM EMP WHERE DEPTNO = 10)));
    end;
    The error message in compilation time is..
    Error 606: The subquery cursor is invalid in the client side
    and the second version is:
    2)Declare
          tab Pkg_Cur_.REC_EMP_;
    begin
           tab:=Pkg_Cur_.GET_RAWS2('SELECT * FROM EMP WHERE DEPTNO = 10');
    end;whereas the database package is defined as:
    CREATE OR REPLACE PACKAGE Pkg_Cur_
    IS
      TYPE REC_EMP_ IS TABLE OF EMP%ROWTYPE INDEX BY BINARY_INTEGER ;
      FUNCTION Get_Raws RETURN REC_EMP_ ;
      FUNCTION Get_Raws2 ( cur_lig IN SYS_REFCURSOR )
        RETURN TYPE_TAB_REC_EMP_ PIPELINED ;
    END  Pkg_Cur_ ;and the database package body is as follows:
    CREATE OR REPLACE PACKAGE BODY Pkg_Cur_
    IS
      FUNCTION Get_Raws RETURN REC_EMP_
      IS
         TAB REC_EMP_;
      BEGIN
         SELECT * BULK COLLECT INTO TAB FROM EMP ;
           RETURN TAB ;
      END ;
      FUNCTION Get_Raws2 ( cur_lig IN SYS_REFCURSOR )
      RETURN TYPE_TAB_REC_EMP_ PIPELINED
      IS
       Trec  TYPE_REC_EMP_ := TYPE_REC_EMP_(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL ) ;
       Remp  EMP%ROWTYPE ;
      BEGIN
       LOOP
         FETCH cur_lig INTO Remp ;
         EXIT WHEN cur_lig%NOTFOUND ;
           -- Handling datas --
           Trec.EMPNO    := Remp.EMPNO ;
           Trec.ENAME    := Remp.ENAME ;
           Trec.JOB      := Remp.JOB ;
           Trec.MGR      := Remp.MGR ;
           Trec.HIREDATE := Remp.HIREDATE ;
           Trec.SAL      := Remp.SAL * 1.1 ;
           Trec.COMM     := Remp.COMM ;
           Trec.DEPTNO   := Remp.DEPTNO ;
           -- Return value --
           PIPE ROW( Trec ) ;
       END LOOP ;
       RETURN ;
      END ;
    END  Pkg_Cur_ ;
    So , how the form trigger should be written...????
    If somebody could help me i would be grateful...!!!!
    Thanks a lot
    Simon

    In the second anonymous block you're trying to populate a record with a table. You would need to select from the function and either bulk collect into a table variable or fetch into a record variable in a loop. Bulk collect is also not supported on the client side.
    I've been looking at pipelined function possibilities in another thread:
    table functions
    The problem you have is actually with the Cursor functions, not the Pipelined functions.

  • PL/SQL Pipelined Function to Compare *ANY*  2 tables

    I am trying to create a pipelined function in 10g R1 that will take the name of two tables, compare the the tables using dynamic SQL and pipe out the resulting rows using the appropriate row type. The pipelined function will be used in a DML insert statement.
    For example:
    create table a (f1 number, f2, date, f3 varchar2);
    create table b (f1 number, f2, date, f3 varchar2);
    create table c (f1 number, f2, date, f3 varchar2);
    create or replace TYPE AnyCollTyp IS TABLE OF ANYTYPE;
    create or replace TYPE CRowType IS c%ROWTYPE;
    create or replace TYPE CRowTabType IS table of CRowType;
    CREATE OR REPLACE FUNCTION compareTables (p_source IN VARCHAR2, p_dest IN VARCHAR2)
    RETURN AnyCollTyp PIPELINED
    IS
    CURSOR columnCur (p_tableName IN user_tab_columns.table_name%TYPE)
    IS
    SELECT column_name, column_id
    FROM user_tab_columns
    WHERE table_name = p_tableName
         ORDER BY column_id;
    l_cur sys_refcursor;
    l_rec ANYTYPE;
    l_stmt VARCHAR2 (32767);
    BEGIN
    l_stmt := 'select ';
    FOR columnRec IN columnCur (p_dest)
    LOOP
    l_stmt := l_stmt || CASE
    WHEN columnRec.column_id > 1
    THEN ','
    ELSE ''
    END || columnRec.column_name;
    END LOOP;
    l_stmt := l_stmt || ' from ' || p_source;
    l_stmt := l_stmt || ' minus ';
    l_stmt := l_stmt || ' select ';
    FOR columnRec IN columnCur (p_dest)
    LOOP
    l_stmt := l_stmt || CASE
    WHEN columnRec.column_id > 1
    THEN ','
    ELSE ''
    END || columnRec.column_name;
    END LOOP;
    l_stmt := l_stmt || ' from ' || p_dest;
    OPEN l_cur FOR l_stmt;
    LOOP
    FETCH l_cur
    INTO l_rec;
    PIPE ROW (l_rec);
    EXIT WHEN l_cur%NOTFOUND;
    END LOOP;
    CLOSE l_cur;
    RETURN;
    END compareTables;
    The pipelined function gets created without error. However, the testCompare procedure gets an error:
    SQL> create or replace procedure testCompare is
    begin
    insert into c
    select *
    from (TABLE(CAST(compareTables('a','b') as cRowTabType)));
    dbms_output.put_line(SQL%ROWCOUNT || ' rows inserted into c.');
    end;
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE TESTCOMPARE:
    LINE/COL ERROR
    3/4 PL/SQL: SQL Statement ignored
    5/47 PL/SQL: ORA-22800: invalid user-defined type
    Does anyone know what I am doing wrong? Is there a better way to compare any two tables and get the resulting rows?

    904640 wrote:
    Hi All,
    Is it possible to post messages to weblogic JMS queue from pl/sql procedure/function?
    From this Queue, message will be read by OSB interface.
    Any help will be highly appreciated.
    http://www.lmgtfy.com/?q=oracle+pl/sql+weblogic+jms+queue

  • Pipelined function with Union clause(Invalid Number(ORA-01722) error )

    Hi,
    I have a pipelined function.
    I am fetching the data with the use of a REF cursor.
    The query has two part: query1 and query2
    when I am opeing the cursor with query1 UNION query2,it is giving me Invalid Number(ORA-01722) error.
    but when I open the cursor separately for query1 and query2,I am getting the resultset for each of the query.
    query1 and query2 are running fine with UNION in the sql editor.
    But,when I put them into two variables (var1 :='query1' and var2:='query2' and try to open the cursor with var1 UNION var2 , it's giving me the error.
    But when I put query2 as 'Select ..... from dual' and then try to open the cursor for query1 UNION query2,
    then getting the result of query1 and one extra row for query2(dual).
    The FROM table set is same for query1 and query2..
    can anyone please help me , why this Invalid Number(ORA-01722) error is coming.

    query1 := 'SELECT to_char(st.store_no) STORE_NUMBER,pp.name PROGRAM_NAME, ''HBS'' DISPENSING_SYSTEM,
    pt.PATIENT_SRC_NO SOURCE_ID, null RX2000_PATIENT_IDENTIFIER, pt.last_name PATIENT_LAST_NAME, pt.first_name
    PATIENT_FIRST_NAME, to_char(LPAD (pppd.rx_number, 7, '' '')|| ''-''|| LPAD (pppd.refill_number, 2, 0)) RX_REFILL
    FROM
    pega_patient_program_dispense pppd,pega_patient_program_reg pppr,health_care_profs hcp1,
    health_care_profs hcp2,prescription_dispenses pd,prescriptions p, pega_program_status_reason ppsr ,master_doctors md,
    prescription_disp_orders pdo, hbs_shipment_extract hse,stores st,master_stores ms,pega_programs pp,patients pt,master_patients mpt
    WHERE
    pppr.referring_hcp_id=md.id(+) and md.dispensing_system_id=hcp1.hcp_id and
    pppr.ID=pppd.PEGA_PATIENT_PROGRAM_REG_ID and pppd.prescription_dispense_id=pd.id and pd.prescriptions_id=p.id and
    p.hcp_id=hcp2.hcp_id and ppsr.ID=pppd.PEGA_PROGRAM_STATUS_REASON_ID and pppd.prescription_dispense_id = pdo.prescriptions_dispenses_id(+) AND
    pdo.shipment_number = hse.shp_no(+) and pppd.store_id=ms.id and st.id=ms.dispensing_system_id and pppr.pega_program_id=pp.id
    and pppr.patient_id=mpt.id and pt.patient_id=mpt.dispensing_system_id and pppd.dispensing_system=''HBS'' and pp.name LIKE ''REV%''
    AND
    ((pppd.prescription_dispense_id IS NOT NULL AND pppd.quantity_dispensed &gt; 0 AND pppd.reported_date IS NULL AND
    pppd.src_delete_date IS NULL AND ((pppr.program_specific_patient_code IS NULL ) OR (hcp1.last_name IS NULL) OR
    (hcp1.first_name IS NULL) OR (hcp2.first_name IS NULL) OR (hcp2.last_name IS NULL) OR (hcp2.address_1 IS NULL) OR
    (hcp2.city IS NULL) OR (hcp2.state_cd IS NULL) OR (hcp2.zip_1 IS NULL)OR (pppr.referral_date is NULL) OR
    (hcp1.state_cd IS NULL) OR (hcp1.zip_1 IS NULL)
    OR (hcp2.zip_1 IS NULL) OR (pppr.last_status_change_date IS NULL) OR (pppr.varchar_1 IS NULL) OR
    (pppr.varchar_7 IS NULL OR pppr.varchar_7 LIKE ''NOT AVAILABLE AT REFERRAL%'') OR (pppr.varchar_5 IS NULL OR
    pppr.varchar_5 LIKE ''NOT AVAILABLE AT REFERRAL%'')) ) AND ppsr.INCLUDE_ON_EXCEPTION_RPT_IND=''Y'')
    OR
    ((pppd.authorization_number IS NULL OR NVL(TRUNC(pdo.shipped_date),TRUNC(hse.shp_act_date_dt)) NOT BETWEEN
    TRUNC(pppd.date_1) AND TRUNC(pppd.date_2)) OR (pppd.varchar_4 IS NULL OR NVL(TRUNC(pdo.shipped_date),
    TRUNC(hse.shp_act_date_dt)) NOT BETWEEN TRUNC(pppd.date_3) AND TRUNC(pppd.date_5)))
    OR
    (pppr.pega_program_competitors_id IS NULL AND (ppsr.manufacturer_status=''TRIAGE'' AND ppsr.manufacturer_reason=''COMPETITOR''))
    OR
    (ppsr.manufacturer_reason IS NULL)
    query2 := ' SELECT ''150'' STORE_NUMBER,''test'' PROGRAM_NAME , ''RX2000'' DISPENSING_SYSTEM
    ,''01'' SOURCE_ID, null RX2000_PATIENT_IDENTIFIER, ''test'' PATIENT_LAST_NAME, ''test'' PATIENT_FIRST_NAME,
    ''rx01'' RX_REFILL
    FROM
    pega_patient_program_reg pppr,health_care_profs hcp1, pega_program_status_reason ppsr ,
    master_doctors md,stores st,master_stores ms,pega_programs pp,patients pt,master_patients mpt
    WHERE
    pppr.referring_hcp_id=md.id(+) and md.dispensing_system_id=hcp1.hcp_id and
    ppsr.ID=pppr.REFERRAL_STATUS_ID and st.store_type=''M'' and pppr.store_id=ms.id and st.id=ms.dispensing_system_id
    and pppr.pega_program_id=pp.id and pppr.patient_id=mpt.id and pt.patient_id=mpt.dispensing_system_id and pp.name LIKE ''REV%''
    AND
    ((((pppr.program_specific_patient_code IS NULL ) OR (hcp1.last_name IS NULL) OR (hcp1.first_name IS NULL) OR
    (pppr.referral_date is NULL) OR (hcp1.state_cd IS NULL) OR (hcp1.zip_1 IS NULL) OR (pppr.last_status_change_date IS NULL)
    OR (pppr.varchar_1 IS NULL) OR (pppr.varchar_7 IS NULL) OR (pppr.varchar_5 IS NULL OR pppr.varchar_5 LIKE
    ''NOT AVAILABLE AT REFERRAL%'')) ) AND ppsr.INCLUDE_ON_EXCEPTION_RPT_IND=''Y'')
    OR
    (pppr.pega_program_competitors_id IS NULL AND (ppsr.manufacturer_status=''TRIAGE'' AND ppsr.manufacturer_reason=''COMPETITOR''))
    OR
    (ppsr.manufacturer_reason IS NULL)
    AND
    pppr.id NOT IN(select pppd.PEGA_PATIENT_PROGRAM_REG_ID from PEGA_PATIENT_PROGRAM_DISPENSE pppd)';
    BUT IF I put
    query2 := ' SELECT ''150'' STORE_NUMBER,''test'' PROGRAM_NAME , ''RX2000'' DISPENSING_SYSTEM
    ,''01'' SOURCE_ID, null RX2000_PATIENT_IDENTIFIER, ''test'' PATIENT_LAST_NAME, ''test'' PATIENT_FIRST_NAME,
    ''rx01'' RX_REFILL
    FROM DUAL';
    then it is giving result.

  • Pipelined function..please help

    hi all...
    i need a fuction which will split the data n insert into the table...
    i created a fuction like this :
    CREATE OR REPLACE FUNCTION FN_SPLIT(text      IN VARCHAR2 DEFAULT NULL,delimiter      IN VARCHAR2 DEFAULT ' ')
    RETURN SPLIT_TYPE_TABLE PIPELINED
    IS
    PRAGMA AUTONOMOUS_TRANSACTION;
    TYPE ref0 is REF CURSOR;
    myCursor ref0;
    out_rec SPLIT_TYPE := SPLIT_TYPE(null, null);
    --CURSOR MSTFRC IS SELECT * FROM TEMP_SPLIT;
    index_      NUMBER(10,0);
    BEGIN
         BEGIN
              /*index_ := -1;
              cnt:=0;
              l_str:=text;
              loop
    l_n := instr( l_str, delimiter );
    exit when (nvl(l_n,0) = 0);
                   cnt:=cnt+1;
                   INSERT INTO TEMP_SPLIT (ID,NAME)
                             VALUES (cnt,ltrim(rtrim(substr(l_str,1,l_n-1))));
    l_str := substr( l_str, l_n+1 );
    end loop;*/
              Load_Temp_Splitting(text,delimiter);
              open myCursor for select * from temp_split;
              LOOP FETCH myCursor into out_rec.ID,out_rec.NAME;
                   EXIT WHEN myCursor%NOTFOUND;
                   PIPE ROW(out_rec);
              END LOOP;
              CLOSE myCursor;
              RETURN;
    END;
    END FN_SPLIT;
    it created succesfully without errors but when i run this function it showing an error like cannot evaluate pipelined function..
    my requirement is to split the data like 'as,af,er,yt' split this by comma n insert into the table with row id like
    1 as
    2 af
    3 er
    like...
    please help friends....
    thnks in advance...
    lol
    Neethu

    > when i run this function it showing an error like cannot evaluate pipelined
    function.
    And that is one of the most important pieces of the puzzle - the actual error displayed. What is it? (full error, i.e. number + message)
    As for the code in the function. That looks a bit like an ugly hack to me. Why the INSERT into table? Why not simply use a local collection or array?
    And why a pipelined table function specifically?
    The following code demonstrates a string split function:
    SQL> create or replace type TStrings as table of varchar2(4000);
    2 /
    Type created.
    SQL>
    SQL> create or replace function tokenise( cString varchar2, cSeparator varchar2 DEFAULT ',' ) return TStrings AUTHID CURRENT_USER is
    2 strList TStrings;
    3 str varchar2(4000);
    4 i integer;
    5 l integer;
    6
    7 procedure AddString( cLine varchar2 ) is
    8 begin
    9 strList.Extend(1);
    10 strList( strList.Count ) := cLine;
    11 end;
    12
    13 begin
    14 strList := new TStrings();
    15
    16 str := cString;
    17 loop
    18 l := LENGTH( str );
    19 i := INSTR( str, cSeparator );
    20
    21 if i = 0 then
    22 AddString( str );
    23 else
    24 AddString( SUBSTR( str, 1, i-1 ) );
    25 str := SUBSTR( str, i+1 );
    26 end if;
    27
    28 -- if the separator was on the last char of the line, there is
    29 -- a trailing null column which we need to add manually
    30 if i = l then
    31 AddString( null );
    32 end if;
    33
    34 exit when str is NULL;
    35 exit when i = 0;
    36 end loop;
    37
    38 return( strList );
    39 end;
    40 /
    Function created.
    SQL>
    SQL> select tokenise( 'as,af,er,yt' ) from dual;
    TOKENISE('AS,AF,ER,YT')
    TSTRINGS('as', 'af', 'er', 'yt')
    SQL>
    SQL> select * from TABLE( tokenise( 'as,af,er,yt' ) );
    COLUMN_VALUE
    as
    af
    er
    yt
    SQL>

  • Opening cursor to collection of records?

    Hi,
    I am researching an issue at work, and I wanted to see if any of you knew whether or not what I'm attempting to do is possible.
    Essentially, what we have is a large number of stored procedures that return data in the form of OUT parameters. If there is more than 1 row, the procedures return a special integer, and the client code (a Java process) repeatedly calls the procedure until it gets all of the data.
    We want to convert these procedures so that they return a result set (i.e., they will
    return a reference cursor variable.) However, we'd rather not work directly with the procedures themselves. What we were hoping to do was develop a set of "proxy" procedures. Java calls these proxies, which call the original procedures, accumulating all the data. Then, the proxy opens a cursor to the final data set, so that in terms of network accesses, there is a single Java-side network access, and multiple local accesses on the Oracle end of things.
    The problem is, I'm not sure that we can return a cursor to the data. What follows are the issues:
    First, we can't open a cursor to the original function calls (AFAIK.) We have to somehow get all of the data from the function into the proxy, and open a cursor to that in the form of a SELECT on all of the data (from SYS.DUAL, or some similar method.)
    So, I decided that maybe the answer was to use a collection. Logically, I thought it best to create a RECORD data type, with a pseudo-column for each of the OUT parameters in the original function call. Then, I created a nested table of these records. I call the original function from the proxy, populating this collection of records with all of the data. That works fine. However, I thought it would be relatively straightforward to open a cursor to this collection, using i.e.:
    OPEN ref_cursor FOR
    SELECT * FROM TABLE(CAST(my_collection_variable AS my_collection_table_type));
    (Or some variant of that.) Unfortunately, it is not. This results in an Oracle error, when I actually open the
    cursor:
    ORA-00600: internal error code, arguments: [15419], [severe error during PL/SQL
    execution], [], [], [], [], [], []
    ORA-06544: PL/SQL: internal error, arguments: [pfrrun.c:pfrbnd1()], [], [], [],
    ORA-06553: PLS-801: internal error [0]
    ERROR:
    ORA-24338: statement handle not executed
    After some research, I found that I could not define the nested table at the PL/SQL level (All of these functions live in packages.) It had to be defined at the database SQL level. So I created a nested table of NUMBER variables at the SQL level (from within sqlplus), tested opening a cursor to that, and everything worked fine.
    Then, I hit the next snag. I can't define the RECORD type at the SQL level, and I can't reference it from the nested table definition (which is defined at the SQL level) when it is defined at the PL/SQL level. This is the error for that:
    1/29 PLS-00201: identifier 'REF_TYPES.FUND_RT' must be declared
    (Where FUND_RT is a RECORD declared in package REF_TYPES.)
    See below for the SQL scripts.
    So, I would have to create literally hundreds of nested tables of VARCHAR2's, NUMBER's, etc., for each OUT parameter at the database level for this approach to work, which is not feasible.
    Does anyone know of a work around for this situation? Is there a way to access a RECORD type defined at the package level, from within a SQL-level nested table
    definition? Is there a way to accomplish what seems like a very simple task that I'm somehow missing?
    Thank you,
    Gabriel Weinstock
    SQL to create the record type, executed first from sqlplus:
    conn owner/password
    CREATE OR REPLACE PACKAGE ref_types
    AS
    TYPE ref_cursor IS REF CURSOR;
    TYPE fund_rt IS RECORD
    ( var1 NUMBER,
    var2 VARCHAR2,
    var3 DATE );
    END;
    grant execute on owner.ref_types to public;
    ** ("owner" is the owner of the table-- is that a problem? I tried "owner.REF_TYPES.fund_rt" and that didn't work either). **
    Next, to create the collection, which generates an error, the following script is called from sqlplus:
    conn owner/password;
    CREATE OR REPLACE TYPE fund_tab_t AS TABLE OF ref_types.fund_rt;
    Error, see above:
    1/29 PLS-00201: identifier 'REF_TYPES.FUND_RT' must be declared

    I agree with Stephen as well that given more time a rewrite of the stored procedures would be optimal.
    Todd-- thanks for the answer. What had me baffled was that I don't think you can define a record at the SQL level, but an object is acceptable. Is that correct?
    However, this raises more issues. I'm not sure management is going to go head over heels for all of these anonymous objects defined at the SQL level, not belonging to any package, so, as I looked further, I think I might have to use a "pipelined function". Which will mean one function calls the original stored procedure, and gathers up all the data into a collection of records. Then, it returns that collection. A second (!) function, opens a ref cursor for a SELECT that includes the returned collection from the first function.
    This way, nothing has to be defined at the SQL level, and I can do everything in the package. (I'll probably eat my words on that.)
    It definitely is NOT pretty, but it might be the way things turn out for an interim solution.

  • Maximum open cursors

    Hi,
    I have an application running on NT station versus Oracle 8.0.5 database on NT server.
    I'm getting the ORA-01000 error while running a report. This error doesn't appear regulary while running the concerned report. it appears after calling the report several times (closing then opening).
    After the error appear everytime I call the report this error appear until the user restart the PC. I did check the report and I'm closing the cursors I opened.
    I had the open_cursors parameter in the INIT file set for 400 then I changed to 600 but this didn't change a thing (I restarted my database).
    I'm using recursive functions but I'm always closing the cursors before calling the function recursively.
    And I also want to notes that the recursive function depending on the data I have won't go more than 2 or 3 levels deeper.
    Please confirm it is bug 492362: NT/95/3.1.1 - REPORTS DOES NOT RELEASE OPENED CURSORS. and how to fix it.
    THANKS

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ali DHAINI ([email protected]):
    Hi,
    I have an application running on NT station versus Oracle 8.0.5 database on NT server.
    I'm getting the ORA-01000 error while running a report. This error doesn't appear regulary while running the concerned report. it appears after calling the report several times (closing then opening).
    After the error appear everytime I call the report this error appear until the user restart the PC. I did check the report and I'm closing the cursors I opened.
    I had the open_cursors parameter in the INIT file set for 400 then I changed to 600 but this didn't change a thing (I restarted my database).
    I'm using recursive functions but I'm always closing the cursors before calling the function recursively.
    And I also want to notes that the recursive function depending on the data I have won't go more than 2 or 3 levels deeper.
    Please confirm it is bug 492362: NT/95/3.1.1 - REPORTS DOES NOT RELEASE OPENED CURSORS. and how to fix it.
    THANKS<HR></BLOCKQUOTE>
    Hi, i have the same problem. Have you solve this problem? Can you tell me how to fix it?
    Thank yoy
    null

  • Confused about Open Cursors :(

    Hi all,
    i need some clarification on this issue, i've read throught the documentation and i'm a bit confused.
    I'm using 10.1.0.2
    select sum(value)
    from v$statname sn,
    v$sesstat st,
    v$session s
    where sn.statistic# = st.statistic#
    and st.sid = s.sid
    and sn.name = 'session cursor cache count'
    The result of the above query is 4926, meaning i have 4926 CLOSED cursors in the session cursor cache.
    select count(1)
    from v$open_cursor
    The result of the above query is 16968, meaning i have 16968 cached cursors
    So there are two distinct cursor Caches ?
    now lets look at other statistic
    select sum(value)
    from v$statname sn,
    v$sesstat st,
    v$session s
    where sn.statistic# = st.statistic#
    and st.sid = s.sid
    and sn.name = 'opened cursors current'
    this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
    I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection) ... so i'm trying to help my developers to find the potencial bug in application.
    How can i get the SQL from OPEN cursors ???
    V$open_cursor gives me SQL from CLOSED cached cursors ...
    Best Regards
    Rui Madaleno

    Hi,
    >>this one gives me 12212 , so i have 12212 opened cursors (NOT CACHED , REALLY OPENED CURSORS ...is this correct???)
    For your instance, yes because you use the sum(value) aggregate function. But I think that the best is get this value per session.
    select count(1) from v$open_cursor
    v$open_cursor shows cached cursors, not currently open cursors, by session. If you're wondering how many cursors a session has open, don't look in v$open_cursor. It shows the cursors in the session cursor cache for each session, not cursors that are actually open. To monitor open cursors, query v$sesstat where name='opened cursors current'. This will give the number of currently opened cursors, by session:
    select a.value, s.username, s.sid, s.serial#
    from v$sesstat a, v$statname b, v$session s
    where a.statistic# = b.statistic#  and s.sid=a.sid
    and b.name = 'opened cursors current';
    >>I suspect that my applications are not closing resultsets (java build application, deployed in oracle application server, database connections in pooled connection)
    In this case, you need to monitor you application. If want, you can use the OEM Database Console and go to [Top Sessions | Session Details] link, or to use this SQL above.
    By the way, do you are getting ORA-1000 errors ?
    If so, set the OPEN_CURSORS parameter high enough that you never get an ORA-1000 during normal operations.
    Cheers

Maybe you are looking for

  • How can I sync the address book from Mail to my Address book?

    Ok, I open a new message and click on the Address Book icon in the new message to find my contacts on the address book, I choose the group I am looking for and the group has people on it that I have already deleted from my address book! How can I syn

  • Inspection lot qualtity

    Hi, I am using source inspection for Quality check. Now the scneraio is as follows: I created one PO with one line item and quality 100. After PO creation i go to QI07 and created a manual inspection lot. I do the result recording , UD etc. And if th

  • No frames visible in Reports 2.5 Layout on Win2000

    Hello: I upgraded my OS to Win2000 and run Reports 2.5. I am unable to see the frames in the layout editor (the reports displayed/worked fine on Win 98). Please help. Thanks Peter

  • IPhoto doesn't ask to delete imported photos

    For years, iPhoto on my MacBook Pro always asked if I wanted to delete the photos from the camera after importing them. For the last year or so, iPhoto 11 didn't always do that with my previous camera, although it sometimes did. Since I got the new C

  • How to get notified when new comment  is left on blog?

    I'd like to be notified (preferrably by e-mail) when a new comment is left on my blog. Is that possible in iWeb '09?