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;

Similar Messages

  • List View Report with pipelined function in Mobile application and ORA-01007: variable not in select list

    Hi!
    I have a problem with List View Report in mobile application (theme 50 in apex) after updating to apex 4.2.2. I created Report -> List View. I used select from pipelined function in Region Source. Then when page is running and submited three times (or refreshed three times) I get an error:
    Error during rendering of region "LIST VIEW".
    ORA-01007: variable not in select list
    Technical Info (only visible for developers)
    is_internal_error: true
    apex_error_code: APEX.REGION.UNHANDLED_ERROR
    ora_sqlcode: -1007
    ora_sqlerrm: ORA-01007: variable not in select list
    component.type: APEX_APPLICATION_PAGE_REGIONS
    component.id: 21230833903737364557
    component.name: LIST VIEW
    error_backtrace:
         ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613
         ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
    I get this error only when I use select from pipelined function in Region Source (for example: "select value1, value2 from table(some_pipelined_function(param1, param2)) ").
    You can check it on http://apex.oracle.com/pls/apex/f?p=50591 (login - demo, password - demo).
    In this application:
    - I created package TAB_TYPES_PKG:
    create or replace PACKAGE TAB_TYPES_PKG IS
    TYPE cur_rest_r IS RECORD (
        STR_NAME          VARCHAR2(128),
        INFO              VARCHAR2(128)
    TYPE cur_rest_t IS TABLE OF cur_rest_r;
    END TAB_TYPES_PKG;
    - I created pipelined function TEST_FUNC:
    create or replace
    FUNCTION TEST_FUNC
    RETURN TAB_TYPES_PKG.cur_rest_t  PIPELINED IS
    r_cur_rest TAB_TYPES_PKG.cur_rest_r;
    BEGIN
    r_cur_rest.STR_NAME := 'ROW 1';
    r_cur_rest.INFO := '10';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 2';
    r_cur_rest.INFO := '20';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 3';
    r_cur_rest.INFO := '30';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 4';
    r_cur_rest.INFO := '40';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 5';
    r_cur_rest.INFO := '50';
    PIPE ROW (r_cur_rest);
    RETURN;
    END TEST_FUNC;
    - I created List View Report on Page 1:
    Region Source:
    SELECT str_name,
           info
    FROM TABLE (TEST_FUNC)
    We can see error ORA-01007 after refresing (or submiting) Page 1 three times or more.
    How to fix it?

    Hi all
    I'm experiencing the same issue.  Predictably on every third refresh I receive:
    Error
    Error during rendering of region "Results".
    ORA-01007: variable not in select list
    Technical Info (only visible for developers)
    is_internal_error: true
    apex_error_code: APEX.REGION.UNHANDLED_ERROR
    ora_sqlcode: -1007
    ora_sqlerrm: ORA-01007: variable not in select list
    component.type: APEX_APPLICATION_PAGE_REGIONS
    component.id: 6910805644140264
    component.name: Results
    error_backtrace: ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613 ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
    OK
    I am running Application Express 4.2.2.00.11 on GlassFish 4 using Apex Listener 2.0.3.221.10.13.
    Please note: this works perfectly using a classic report in my desktop application; however, no joy on the mobile side with a list view.  I will use a classic report in the interim.
    My region source is as follows:
    SELECT description AS "DESCRIPTION", reference AS "REFERENCE" FROM TABLE(AUTOCOMPLETE_LIST_VIEW_FNC('RESULTS'))
    The procedure:
      FUNCTION AUTOCOMPLETE_LIST_VIEW_FNC(
          p_collection_name IN VARCHAR2)
        RETURN list_row_table_type
      AS
        v_tab list_row_table_type := list_row_table_type();
      BEGIN
        DECLARE
          jsonarray json_list;
          jsonobj json;
          json_clob CLOB;
        BEGIN
          SELECT clob001
          INTO json_clob
          FROM apex_collections
          WHERE collection_name = p_collection_name;
          jsonobj              := json(json_clob);
          jsonarray            := json_ext.get_json_list(jsonobj, 'predictions');
          FOR i IN 1..jsonArray.count
          LOOP
            jsonobj := json(jsonArray.get(i));
            v_tab.extend;
            v_tab(v_tab.LAST) := list_row_type(json_ext.get_string(jsonobj, 'description'), json_ext.get_string(jsonobj, 'reference'));
          END LOOP;
          RETURN(v_tab);
        END;  
      END AUTOCOMPLETE_LIST_VIEW_FNC;
    Thanks!
    Tim

  • ORA-22905 and Cast function

    I am running a query with following code:
    select d.acct_num, lib.fmt_money(a.amt) Total Amount
    from account d, table(report.lib.expense (d.acct_num)) a
    where clause.
    Here:
    1. Report is another schema containing packqges for reporting development.
    2. lib is package name created in the report schema. It contains function such as expense.
    3. expense is a function under Lib package as
    function expense (p_acct number) return number is
    acct_num number;
    begin select xxxx into acct_num from xxx_table); return nvl(acct_num, 0);
    end expense;
    Then when I run this select statement, it gave me ORA-22905 error. Cause: attempt to access rows of an item whose type is not known at parse time or that is not of a nested table type. Action: use CAST to cast the item to a nested table type.
    I used CAST like this:
    select d.acct_num, CAST(a.amt as number ) Total Amount
    from account d, table(report.lib.expense (d.acct_num)) a
    where clause.
    It gave me ORA-00923 From keyword not found where expected.
    Please help me to find where the problem is and thank you for your help a lot.

    citicbj wrote:
    I have checked function and found that function was defined as this:
    function expense (p_exp varchar2) return number
    is
    l_exp number;
    begin
    select xxx into l_exp from xxxx where clause;
    return nvl(l_exp, 0);
    end expense;
    So this is not defined as the table of array. So I take the table off from select statement as
    select d.acct_num,
    to_number(a.amt) Total Amount
    from account d,
    report.lib.expense (d.acct_num) a
    where d.acct_num = a.acct_num;
    Then it return ORA-00933 SQL command not ptoperly ended. However, I couldn't see any not properly ended SQL code here. Please advise your comments.Should just be ...
    select
       d.acct_num,
       report.lib.expense (d.acct_num) as "Total Amount"
       --to_number(a.amt) Total Amount
    from account dNotice that i enclosed the column alias (Total Amount) in " ... that is because you can't have a column alias with spaces as you tried without doing this (the parser gets sad).
    Also, you cannot use a function returning a single value like this as a nested table (at least not the way you are trying) and in your case there's no reason. You don't want to join to it, you are passing in ACCT_NUM which the function will presumably use to filter out not relevant data.
    Finally, there's no reason to TO_NUMBER the function result ... it's already defined to return a number :)

  • How the performance will increase with pipelined function.

    Respects all,
    Can u please help to explain one example regarding which i have mentioned in the subject line.
    Thanks

    Hi,
    pipelined functions don't "increase performance".
    1) This is an entirely wrong way to think about Oracle features. There are no Oracle features that automatically "increase performance", like some sort of a "turbo" button (not even partitioning! not even indexes!). Most of the features can work both ways -- when used appropriately, they improve performance, when not, they can cripple it.
    2) Pipelined functions are not about performance. They simply provide a way for you to SELECT from a PL/SQL function (which otherwise is impossible to do). Not only you can generate sets of values this way, but also you can join it with other tables/views, that can be very convenient. Pipelined functions can also be very convenient for generating formatted text reports they allow you to bypass limitations of long/lob data types). But none of this has to do with performance.
    3) Pipelined functions are inevitably associated with row-by-row processing (because there is no way to pipe a set of rows at once). So when the choice is between returning a refcursor (from which you can do a bulk fetch), and using a pipelined function, from which you'll be returning rows one by one, and none of items listed in 2) applies, then chances are that pipelined function is going to be slower.
    So whoever claimed that "pipelined functions increase performance", either he/she is incompetent, or you took his/her words out of the context or misintepreted them.
    Best regards,
      Nikolay

  • BUG : ORA-21779 with REGEXP_INSTR function

    Hi,
    When we use REGEXP_INSTR in a validation with the primary_language = 'en-us'
    we get an Oracle Error : ORA-21779
    We tried moving the REGEXP_INSTR in a stored function and we get the same error.
    When we change the primary language of the application to 'fr-ca' we don't have the error anymore (??)
    As a workaround , instead of using REGEXP_INSTR we use OWA_PATTERN and it works fine.
    Here is the function using REGEXP_INSTR that causes the ORA-21779 :
    FUNCTION validate_email_format(p_email IN VARCHAR2)
    RETURN BOOLEAN
    IS
    BEGIN
    IF REGEXP_INSTR(upper(p_email),'^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z0-9]{2,4}+$') > 0 THEN
    return true;
    ELSE
    return false;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    return false;
    END validate_email_format;
    END;
    Would it be possible to fix this in the next release ??
    Database version is : 10.1.0.5
    Thanks
    Francis.

    with  paragraph as (
                         select  'This is the first sentence. This is the second sentence. ... This is the last sentence. but there is more text here' par
                           from  dual
                        union all
                         select  'This is the first sentence. This is the second sentence. ... This is the last sentence? but there is more text here' par
                           from  dual
                        union all
                         select  'This is the first sentence. This is the second sentence. ... This is the last sentence! but there is more text here' par
                           from  dual
    select regexp_instr(par,'(\.|\!|\?)[^.!?]*$') from paragraph
    REGEXP_INSTR(PAR,'(\.|\!|\?)[^.!?]*$')
                                        87
                                        87
                                        87
    SQL> SY.

  • Pipelined function with huge volume

    Hi all,
    I have a table of 5 million rows with an average length of 1K for each row (dss system).
    My SGA is 2G and PGA 1G.
    I wonder if a pipelined function could support a such volume ?
    Does anyone have already experienced a pipelined function with a huge volume ?
    TIA
    Yang

    Hello
    Well, just over a month later and we're pretty much sorted. Our pipelined functions were not the cause of the excessive memory consumption and the processes are are now no longer consuming as much PGA as they were previously. Here's what I've learnt.
    1. Direct write operations on partitioned tables require two direct write buffers to be allocated per partition. By default, these buffers are 256K each so it's 512K per partition. We had a table with 241 partitions which meant we inadvertently allocating 120MB of PGA without even trying. This is not a problem with pipelined functions.
    2. In 10.2 the total size of the buffers will be kept below the pga_aggregate_target, or 64k per buffer, whichever is higher. This is next to useless though as to really constrain the size of the buffers at all, you need a ridiculously small pga_aggregate_target.
    3. The size of the buffers can be as low as 32k and can be set using an undocumented parameter "_ldr_io_size". In our environment (10.2.0.2 Win2003 using AWE) I've set it to 32k meaning there will be 64k worth of buffers allocated to each partition significantly reducing the amount of PGA required.
    4. I never want to speak to Oracle support again. We had a severity 1 SR open for over a month and it took the development team 18 days to get round to looking at the test case I supplied. Once they'd looked at it, they came back with the undocumented parameter which worked, and the ridiculous suggestion that I set the PGA aggregate target to 50MB on a production box with 4GB and 300+ dedicated connections. No only that, they told me that a pga_aggregate_target of 50MB was sensible and did so in the most patronising way. Muppets.
    So in sum, our pipelined functions are working exceptionally well. We had some scary moments as we saw huge amounts of PGA being allocated and then 4030 memory errors but now it's sorted and chugging along nicely. The throughput is blistering especially when running in parallel - 200m rows generated and inserted in around 1 hour.
    To give some background on what we're using pipelined functions for....
    We have a list of master records that have schedules associated with them. Those schedules need to be exploded out to an hourly level and customised calendars need to be applied to them along with custom time-zone-style calculations. There are various lookups that need to be applied to the exploded schedules and a number of value calculations based on various rules. I did originally implement this in straight SQL but it was monsterous and ran like a dog. The SQL was highly complex and quite quickly became unmanageable. I decided to use pipelined functions because
    a) It immensely simplified the logic
    b) It gave us a very neat way to centralise the logic so it can be easily used by other systems - PL/SQL and SQL
    c) We can easily see what it is doing and make changes to the logic without affecting execution plans etc
    d) Its been exceptionally easy to tune using DBMS_PROFILER
    So that's that. I hope it's of use to anyone who's interested.
    I'm off to get a "pipelined fuinctions rule" tattoo on my face.
    David

  • 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();
            }

  • Tabular forms based on pipelined functions - can it be done?

    Hi there,
    Pipelined functions are great, specially when you want to encapsulate the access to tables instead of just SELECTing from them (what I am doing a lot in my current project.)
    However Apex 4 does not like them, at least not for tabular forms...
    I want to handle myself the update/insert/delete process, so I don't need the MRU default functionality (all the access to the data is via APIs). But at the same time I want to just SELECT from my pipelined function and set the item types using the builder interface as with any tabular form (without having to use the apex_item API). Also I want to be able to use tabular form validation.
    To start with, you can only create a tabular form based on a table or view. To overcome this issue, I created a dummy view with the fields I wanted and created my tabular form on it. Then I changed the FROM clause to FROM TABLE(myfunction). It didn't work as it seems it tries to select the ROWID for each row... Of course my pipelined function doesn't return one but I don't need one anyway as I will be doing the data manipulation myself based on the PK.
    For this to work, I had to create a collection, populate it with the result of the pipelined function in a page process every time the page is loaded, create a view on that collection and base the tabular form on the view... A lot of work and overhead for something that should be very simple in principle.
    Then, I found out that if I remove the default MRU process that is automatically created, the tabular form validations stop working (as I posted in another thread). So I have to leave a "dummy" MRU process there with condition = never for it to work.
    The application I am working on is all based on API calls and pipelined functions so all this work has to be repeated for each tabular form that is needed.
    If it was possible to base a tabular form directly on a pipelined function it would be such an elegant solution.
    Is there a better way to implement this? Shouldn't Apex be more compatible with pipelined functions? (at least in regards to tabular forms, they work well with normal forms, reports, LOVs etc)
    Thanks
    Luis

    As I mentioned before, I don't handle inserts (well, I cheat).... On my page, there is a form to set up a request - prompts for a few things, and when submitted, calls a stored procedure:
    :P2_REQUEST_RESULT := Simon.Apex_Campus_Guest.Setup_Request(:P2_GROUP_NAME,
           :P2_COAS_ORGN, :P2_START_DATE, :P2_END_DATE, :P2_Quantity, :P2_Generic_Names);
    Which creates an APEX collection, which in turn is made visible via a pipelined function turned into a view:
    create or replace view Apex_Campus_Guest_Request_va as
    select seq_no,
            user_name,
           group_name,
            comments
      from table ( Apex_Campus_Guest.Request_Result )
    I have a second region which is tabular form on a query - conditional on select 1 from Simon.apex_campus_guest_request_va (the view defined above).
    When this submitted, I have standard MRU and MRD processes (Seq_No is the primary key). This then runs into the appropriate trigger - the update trigger is as follows:
    trigger Apex_Campus_Guest_Req_Upd
    instead of update on Apex_Campus_Guest_Request_va
    for each row
    declare
            cg_rec  campus_guest_maint.rec;
    begin
            cg_rec := Campus_Guest_Maint.Request(
                            name => :new.user_name,
                            group_name => :new.group_name,
                            comments => :new.comments);
    end;I don't know off hand why it isn't asking for a rowid - but may be that I specified a PKEY column. The insert case fails, as it tries to add a "Returning" statement in the original select. I actually find that annoying as a function is defined to allocate the PKEY from a sequence, so it doesn't need to ask for it that way.

  • 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 with execute immediate

    Hello Experts,
    I have created a Pipe lined function with execute immediate, due to below requirement;
    1) Columns in where clause is passed dynamically.
    2) I want to know the data stored into above dynamic columns.
    3) I want to use it in report, so I don't want to insert it into a table.
    I have created a TYPE, then through execute immediate i have got the query and result of that query will be stored in TYPE.
    But when calling the function i am getting
    ORA-00932: inconsistent datatypes: expected - got -
    Below is my function and type, let me know i am going wrong, and is my logic correct.
    CREATE OR REPLACE TYPE OBJ_FPD AS OBJECT
                      (LOW_PLAN_NO VARCHAR2 (40),
                       FPD VARCHAR2 (5),
                       SERIAL_NO NUMBER,
                       CEDIA_CODE VARCHAR2 (2),
                       DT DATE);
    CREATE OR REPLACE TYPE FPD_TBL_TYPE AS TABLE OF OBJ_FPD;
    CREATE OR REPLACE FUNCTION FUNC_GET_FPD_DATE (P_LOW_PLAN_NO    VARCHAR2,
                                                  P_CEDIA_CODE     VARCHAR2,
                                                  P_SERIAL_NO      NUMBER)
       RETURN FPD_TBL_TYPE
       PIPELINED
    AS
       CURSOR C1
       IS
              SELECT 'FPD' || LEVEL TBL_COL
                FROM DUAL
          CONNECT BY LEVEL <= 31;
       V_STR        VARCHAR2 (5000);
       V_TBL_TYPE   FPD_TBL_TYPE;
    BEGIN
       FOR X IN C1
       LOOP
          V_STR :=
                'SELECT A.low_PLAN_NO,
               A.FPD,
               A.SERIAL_NO,
               A.cedia_code,
               TO_DATE (
                     SUBSTR (FPD, 4, 5)
                  || ''/''
                  || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''MM'')
                  || ''/''
                  || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''RRRR''),
                  ''DD/MM/RRRR'')
                  DT FROM ( SELECT low_PLAN_NO, '
             || ''''
             || X.TBL_COL
             || ''''
             || ' FPD, '
             || X.TBL_COL
             || ' SPTS, SERIAL_NO, cedia_code FROM M_low_PLAN_DETAILS WHERE NVL('
             || X.TBL_COL
             || ',0) > 0 AND SERIAL_NO = '
             || P_SERIAL_NO
             || ' AND cedia_code = '
             || ''''
             || P_CEDIA_CODE
             || ''''
             || ' AND low_PLAN_NO = '
             || ''''
             || P_LOW_PLAN_NO
             || ''''
             || ') A,
               M_low_PLAN_DETAILS B,
               M_low_PLAN_MSTR C
         WHERE     A.low_PLAN_NO = B.low_PLAN_NO
               AND A.cedia_code = B.cedia_code
               AND A.SERIAL_NO = B.SERIAL_NO
               AND B.low_PLAN_NO = C.low_PLAN_NO
               AND B.CLIENT_CODE = C.CLIENT_CODE
               AND B.VARIANT_CODE = C.VARIANT_CODE
    CONNECT BY LEVEL <= SPTS';
          EXECUTE IMMEDIATE V_STR INTO V_TBL_TYPE;
          FOR I IN 1 .. V_TBL_TYPE.COUNT
          LOOP
             PIPE ROW (OBJ_FPD (V_TBL_TYPE (I).LOW_PLAN_NO,
                                V_TBL_TYPE (I).FPD,
                                V_TBL_TYPE (I).SERIAL_NO,
                                V_TBL_TYPE (I).CEDIA_CODE,
                                V_TBL_TYPE (I).DT));
          END LOOP;
       END LOOP;
       RETURN;
    EXCEPTION
       WHEN OTHERS
       THEN
          RAISE_APPLICATION_ERROR (-20000, SQLCODE || ' ' || SQLERRM);
          RAISE;
    END;Waiting for your views.
    Regards,

    Ora Ash wrote:
    Hello Experts,
    I have created a Pipe lined function with execute immediate, due to below requirement;
    1) Columns in where clause is passed dynamically.No, that's something you've introduced, and is due to poor database design. You appear to have columns on your table called FPD1, FPD2 ... FPD31. The columns do not need to be 'passed dynamically'
    2) I want to know the data stored into above dynamic columns.And you can know the data without it being dynamic.
    3) I want to use it in report, so I don't want to insert it into a table.That's fine, though there's no reason to use a pipelined function.
    You also have an pointless exception handler, which masks any real errors.
    I'm not quite sure what the point of your "connect by" is in your query as we don't have your tables or data or know for sure what the expected output is.
    However, in terms of handling the 'dynamic' part that you've introduced, then you would be looking at doing something along the following lines, using a static query that requires no poor dynamic code, and no pipelined function...
    with x as (select level as dy from dual connect by level <= 31)
    select a.low_plan_no
          ,a.fpd
          ,a.serial_no
          ,a.cedia_code
          ,trunc(c.low_plan_period_from)+a.dy-1 as dt
    from  (select low_plan_no
                 ,dy
                 ,'FPD'||dy as fpd
                 ,spts
                 ,serial_no
                 ,cedia_code
           from (
                 select low_plan_no
                       ,x.dy
                       ,case x.dy when 1 then fpd1
                                  when 2 then fpd2
                                  when 3 then fpd3
                                  when 4 then fpd4
                                  when 5 then fpd5
                                  when 6 then fpd6
                                  when 7 then fpd7
                                  when 8 then fpd8
                                  when 9 then fpd9
                                  when 10 then fpd10
                                  when 11 then fpd11
                                  when 12 then fpd12
                                  when 13 then fpd13
                                  when 14 then fpd14
                                  when 15 then fpd15
                                  when 16 then fpd16
                                  when 17 then fpd17
                                  when 18 then fpd18
                                  when 19 then fpd19
                                  when 20 then fpd20
                                  when 21 then fpd21
                                  when 22 then fpd22
                                  when 23 then fpd23
                                  when 24 then fpd24
                                  when 25 then fpd25
                                  when 26 then fpd26
                                  when 27 then fpd27
                                  when 28 then fpd28
                                  when 29 then fpd29
                                  when 30 then fpd30
                                  when 31 then fpd31
                        else null
                        end as spts
                       ,serial_no
                       ,cedia_code
                 from   x cross join m_low_plan_details
                 where  serial_no = p_serial_no
                 and    cedia_code = p_cedia_code
                 and    low_plan_no = p_low_plan_no
           where  nvl(spts,0) > 0
          ) A
          join m_low_plan_details B on (    A.low_plan_no = B.low_plan_no
                                        and A.cedia_code = B.cedia_code
                                        and A.serial_no = B.serial_no
          join m_low_plan_mstr C on (    B.low_plan_no = C.low_plan_no
                                     and B.client_code = C.client_code
                                     and B.variant_code = C.variant_code
    connect by level <= spts;... so just remind us again why you think it needs to be dynamic?

  • Pipeline function raised ORA-06519: active autonomous transaction detected

    Hi All,
    My name is John and I've got a problem which I need to share with all of you guru and experts. I've created the following pipeline function under the Oracle user ABC:
    CREATE OR replace FUNCTION SomeFunction(p_from_date DATE, p_to_date DATE) RETURN T_TAB_A pipelined
    IS
    PRAGMA autonomous_transaction;
    BEGIN
    DELETE FROM temp_rcm;
    INSERT INTO temp_rcm
    SELECT * FROM int.facility fd,
    int.capacity co
    WHERE co.resource_name = fd.resource_name
    AND co.trade_date = fd.trade_date
    AND co.trade_date BETWEEN p_from_date AND p_to_date;
    COMMIT;
    FOR rec IN (SELECT co.*
    FROM temp_rcm co
    left join int.outage o
    ON ( o.flag = 'Y'
    AND o.reason_flag = 'F'
    AND o.INTERVAL = co.INTERVAL
    AND co.resource_name = o.resource_name )
    ORDER BY co.INTERVAL,
    co.name) LOOP
    pipe ROW (T_A( rec.INTERVAL, rec.trade_date,
    rec.resource_name,rec.day_of_week_long, rec.working_day, rec.peak));
    END LOOP;
    RETURN;
    END SomeFunction;
    I was able to compile and create the SomeFunction function successfully but when I executed it using the following command:
    select * from table(SomeFunction(to_date('01/01/2010',to_date('01/01/2010')));
    I was returned with the Oracle error - ORA-06519: active autonomous transaction detected and rolled back
    I have searched through the web, such Oracle error occurs whenever the function has a missing 'COMMIT' or 'ROLLBACK' command inside an autonomous_transaction. But the fact is I have already included the 'COMMIT;' in the function. I suspected that the error was caused by the tables which I queried against (like int.facility and int.capacity) were all views that belonged to another schema called int. Or is that something that I miss in the function? Thank you for your time and assistance.
    Regards,
    John

    johnwanng wrote:
    Hi Guys,
    Thank you for all your feedback. In addition to your reply, Bill, can you spare some time and provide us a simple example of the steps involved to implement the 'correct' implementation based on the queries that I've used. As I do not understand your vanilla approach. Much appreciated and thank you for the time again.
    Regards,
    JohnIf I had to guess, Billy may have meant something like this (untested):
    CREATE OR REPLACE FUNCTION SomeFunction
    ( p_from_date IN int.facility.trade_date%TYPE
    , p_to_date   IN int.facility.trade_date%TYPE
    RETURN SYS_REFCURSOR
    AS
         rcur     SYS_REFCURSOR;
    BEGIN
         OPEN rcur FOR
              SELECT co.interval
                   , co.trade_date
                   , co.resource_name
                   , co.day_of_week_long
                   , co.working_day
                   , co.peak
              FROM   int.capacity co
              JOIN   int.facility fd        ON fd.resource_name = co.resource_name
                                           AND fd.trade_date    = co.trade_date
              LEFT OUTER JOIN int.outage o  ON o.interval       = co.interval
                                           AND o.resource_name  = co.resource_name
              WHERE  co.trade_date BETWEEN p_from_date AND p_to_date
              AND    o.reason_flag = 'F'
              AND    o.flag        = 'Y'
              ORDER BY co.interval
                     , co.name
         RETURN rcur;
    END;
    /I made the following modifications:
    1. I set the input parameter data types to match that of the table column you are checking against. A good practice to get into.
    2. Removed the autonomous transaction and inserting into a temp table. In Oracle it's a good practice to perform everything in a single SQL statement if possible.
    3. Changed the return data type to a SYS_REFCURSOR
    Hope this helps and provides a good example.

  • Clob datatype with pipelined table function.

    hi
    i made two functions one of them which use varchar2 data type with pipelined and
    another with clob data type with pipelined.
    i am giving parameters to both of them first varch2 with pipelined is working fine.
    but another is not.
    and i made diff type for both of them.
    like clob object type for second.
    and varchar2 type for first.
    my first function is like
    TYPE "CSVOBJECTFORMAT"  AS OBJECT ( "S"   VARCHAR2(500));
    TYPE "CSVTABLETYPE" AS TABLE OF CSVOBJECTFORMAT;
    CREATE OR REPLACE FUNCTION "FN_PARSECSVSTRING" (p_list
        VARCHAR2, p_delim VARCHAR2:=' ') RETURN CsvTableType PIPELINED
        IS
    l_idx PLS_INTEGER;
    l_list VARCHAR2(32767) := p_list;
    l_value VARCHAR2(32767);
    BEGIN
    LOOP
    l_idx := INSTR(l_list, p_delim);
    IF l_idx > 0 THEN
    PIPE ROW(CsvObjectFormat(SUBSTR(l_list, 1, l_idx-1)));
    l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    ELSE
    PIPE ROW(CsvObjectFormat(l_list));
    EXIT;
    END IF;
    END LOOP;
    RETURN;
    END fn_ParseCSVString;
    and out put for this function is like
    which is correct.
    SQL>   SELECT s  FROM  TABLE( CAST( fn_ParseCSVString('+588675,1~#588675^1^99^~2~16~115~99~SP5601~~~~~0~~', '~') as CsvTableType)) ;
    S
    +588675,1
    #588675^1^99^
    2
    16
    115
    99
    SP5601
    S
    0
    14 rows selected.
    SQL>
    my second function is like
    TYPE "CSVOBJECTFORMAT1"  AS OBJECT ( "S"   clob);
    TYPE "CSVTABLETYPE1" AS TABLE OF CSVOBJECTFORMAT1;
    CREATE OR REPLACE FUNCTION "FN_PARSECSVSTRING1" (p_list
        clob, p_delim VARCHAR2:=' ') RETURN CsvTableType1 PIPELINED
        IS
    l_idx PLS_INTEGER;
    l_list  clob := p_list;
    l_value VARCHAR2(32767);
    BEGIN
    dbms_output.put_line('hello');
      LOOP
      l_idx := INSTR(l_list, p_delim);
      IF l_idx > 0 THEN
    PIPE ROW(CsvObjectFormat1(substr(l_list, 1, l_idx-1)));
    l_list :=  dbms_lob.substr(l_list, l_idx+LENGTH(p_delim));
    ELSE
    PIPE ROW(CsvObjectFormat1(l_list));
    exit;
    END IF;
      END LOOP;
    RETURN;
    END fn_ParseCSVString1;
    SQL>   SELECT s  FROM  TABLE( CAST( fn_ParseCSVString1('+588675,1~#588675^1^99^~2~16~115~99~SP5601~~~~~0~~', '~') as CsvTableType1)) ;
    S
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    +588675,1
    and it goes on until i use ctrl+C to break it.
    actually i want to make a function which can accept large values  so i am trying to change first function.thanks

    RTFM DBMS_LOB.SUBSTR. Unlike built-in function SUBSTR, second parameter in DBMS_LOB.SUBSTR is length, not position. Also, PL/SQL fully supports CLOBs, so there is no need to use DBMS_LOB:
    SQL> CREATE OR REPLACE
      2  FUNCTION FN_PARSECSVSTRING1(p_list clob,
      3                              p_delim VARCHAR2:=' '
      4                             )
      5    RETURN CsvTableType1
      6    PIPELINED
      7    IS
      8        l_pos   PLS_INTEGER := 1;
      9        l_idx   PLS_INTEGER;
    10        l_value clob;
    11    BEGIN
    12        LOOP
    13          l_idx := INSTR(p_list, p_delim,l_pos);
    14          IF l_idx > 0
    15            THEN
    16              PIPE ROW(CsvObjectFormat1(substr(p_list,l_pos,l_idx-l_pos)));
    17              l_pos := l_idx+LENGTH(p_delim);
    18            ELSE
    19              PIPE ROW(CsvObjectFormat1(substr(p_list,l_pos)));
    20              RETURN;
    21          END IF;
    22        END LOOP;
    23        RETURN;
    24  END fn_ParseCSVString1;
    25  /
    Function created.
    SQL> SELECT rownum,s  FROM  TABLE( CAST( fn_ParseCSVString1('+588675,1~#588675^1^99^~2~16~115~99~SP5
    601~~~~~0~~', '~') as CsvTableType1)) ;
        ROWNUM S
             1 +588675,1
             2 #588675^1^99^
             3 2
             4 16
             5 115
             6 99
             7 SP5601
             8
             9
            10
            11
        ROWNUM S
            12 0
            13
            14
    14 rows selected.
    SQL> SY.

  • Performance issues with pipelined table functions

    I am testing pipelined table functions to be able to re-use the <font face="courier">base_query</font> function. Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? The <font face="courier">processor</font> function is from [url http://www.oracle-developer.net/display.php?id=429]improving performance with pipelined table functions .
    Edit: The underlying query returns 500,000 rows in about 3 minutes. So there are are no performance issues with the query itself.
    Many thanks in advance.
    CREATE OR REPLACE PACKAGE pipeline_example
    IS
       TYPE resultset_typ IS REF CURSOR;
       TYPE row_typ IS RECORD (colC VARCHAR2(200), colD VARCHAR2(200), colE VARCHAR2(200));
       TYPE table_typ IS TABLE OF row_typ;
       FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
          RETURN resultset_typ;
       c_default_limit   CONSTANT PLS_INTEGER := 100;  
       FUNCTION processor (
          p_source_data   IN resultset_typ,
          p_limit_size    IN PLS_INTEGER DEFAULT c_default_limit)
          RETURN table_typ
          PIPELINED
          PARALLEL_ENABLE(PARTITION p_source_data BY ANY);
       PROCEDURE with_pipeline (argA          IN     VARCHAR2,
                                argB          IN     VARCHAR2,
                                o_resultset      OUT resultset_typ);
       PROCEDURE no_pipeline (argA          IN     VARCHAR2,
                              argB          IN     VARCHAR2,
                              o_resultset      OUT resultset_typ);
    END pipeline_example;
    CREATE OR REPLACE PACKAGE BODY pipeline_example
    IS
       FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
          RETURN resultset_typ
       IS
          o_resultset   resultset_typ;
       BEGIN
          OPEN o_resultset FOR
             SELECT colC, colD, colE
               FROM some_table
              WHERE colA = ArgA AND colB = argB;
          RETURN o_resultset;
       END base_query;
       FUNCTION processor (
          p_source_data   IN resultset_typ,
          p_limit_size    IN PLS_INTEGER DEFAULT c_default_limit)
          RETURN table_typ
          PIPELINED
          PARALLEL_ENABLE(PARTITION p_source_data BY ANY)
       IS
          aa_source_data   table_typ;-- := table_typ ();
       BEGIN
          LOOP
             FETCH p_source_data
             BULK COLLECT INTO aa_source_data
             LIMIT p_limit_size;
             EXIT WHEN aa_source_data.COUNT = 0;
             /* Process the batch of (p_limit_size) records... */
             FOR i IN 1 .. aa_source_data.COUNT
             LOOP
                PIPE ROW (aa_source_data (i));
             END LOOP;
          END LOOP;
          CLOSE p_source_data;
          RETURN;
       END processor;
       PROCEDURE with_pipeline (argA          IN     VARCHAR2,
                                argB          IN     VARCHAR2,
                                o_resultset      OUT resultset_typ)
       IS
       BEGIN
          OPEN o_resultset FOR
               SELECT /*+ PARALLEL(t, 5) */ colC,
                      SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
                      SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
                      SUM (CASE WHEN colD = colE AND colD != '0' THEN '1' END) de_one,
                      SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
                 FROM TABLE (processor (base_query (argA, argB),100)) t
             GROUP BY colC
             ORDER BY colC
       END with_pipeline;
       PROCEDURE no_pipeline (argA          IN     VARCHAR2,
                              argB          IN     VARCHAR2,
                              o_resultset      OUT resultset_typ)
       IS
       BEGIN
          OPEN o_resultset FOR
               SELECT colC,
                      SUM (CASE WHEN colD > colE AND colE  != '0' THEN colD / ColE END)de,
                      SUM (CASE WHEN colE > colD AND colD  != '0' THEN colE / ColD END)ed,
                      SUM (CASE WHEN colD = colE AND colD  != '0' THEN 1 END) de_one,
                      SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
                 FROM (SELECT colC, colD, colE
                         FROM some_table
                        WHERE colA = ArgA AND colB = argB)
             GROUP BY colC
             ORDER BY colC;
       END no_pipeline;
    END pipeline_example;
    ALTER PACKAGE pipeline_example COMPILE;Edited by: Earthlink on Nov 14, 2010 9:47 AM
    Edited by: Earthlink on Nov 14, 2010 11:31 AM
    Edited by: Earthlink on Nov 14, 2010 11:32 AM
    Edited by: Earthlink on Nov 20, 2010 12:04 PM
    Edited by: Earthlink on Nov 20, 2010 12:54 PM

    Earthlink wrote:
    Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
    Like:
    - a database version
    - how did you test
    - what data do you have, how is it distributed, indexed
    and so on.
    If you want to find out what's going on then use a TRACE with wait events.
    All nessecary steps are explained in these threads:
    HOW TO: Post a SQL statement tuning request - template posting
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    Another nice one is RUNSTATS:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701

  • Interactive Report using a View with a Pipelined Function

    Hello fellow Apex people,
    I'm Using Application Express 4.1.0.00.32
    I've got an interactive report that references a view (STOCK) and a pipelined function
    The basic query is listed below.
    SELECT S.CHANGED_TIME "Changed Time"
    , S.CHANGED_BY "Changed By"
    , S.ID "Id"
    , STKST_DESCRS.STOCK_STATUS_CODES "Stock Status Codes"
    , STKST_DESCRS.STOCK_STATUS_DESCRS "Stock Status"
    , S.ORIGINAL_CONTAINER "Original Container"
    FROM STOCK S
    , table(LWS_StkstStatus (S.ID)) STKST_DESCRS
    ORDER BY S.CO_ID,
    S.SEQUENCE_NUM;
    When the page is first run all the data is displayed correctly,
    If I define a filter, sort or a blank search the data from the pipelined function (STKST_DESCRS.) becomes null and isn't displayed.
    Does anyone know what is happening?
    Many Thanks

    I'm curious why you find this dangerous. I want a report that looks like this:
    Opportunity X:
    4 - 2-apr-2008 - Closed deal
    3 - 1-mar-2008 - Called Joe again
    2 - 12-feb-2008 - Called Joe
    1 - 14-jan-2008 - Initial call with customer.
    When you enter a new note, I want it to be numbered 5. The only problem I can imagine is someone deleting a note, which will almost never happen, and if it does, it just leaves a numbering gap. I don't see how using the function in a SELECT will accomplish this.

  • Pipelined function with lagre amount of data

    We would like to use pipelined functions as source of the select statements instead of tables. Thus we can easily switch from our tables to the structures with data from external module due to the need for integration with other systems.
    We know these functions are used in situations such as data warehousing to apply multiple transformations to data but what will be the performance in real time access.
    Does anyone have any experience using pipelined function with large amounts of data in the interface systems?

    It looks like you have already determined that the datatable object will be the best way to do this. When you are creating the object, you must enter the absolute path to your spreadsheet file. Then, you have to create some type of connection (i.e. a pushbutton or timer) that will send a true to the import data member of the datatable object. After these two things have been done, you will be able to access the data using the A3 - K133 data members.
    Regards,
    Michael Shasteen
    Applications Engineering
    National Instruments
    www.ni.com/ask
    1-866-ASK-MY-NI

Maybe you are looking for

  • B1最新消息及时更新-B1中文社区计划!!!

    号外,号外,好消息,好消息,SAP中国研究院Business One研发部门大力推出B1中文社区计划, 目的在与更方便快捷有效地与B1顾问及用户进行互动,主要包含以下三个方面的内容: 1. B1共同创新邮箱 B1CoInnovate.CN at sap.com (把at换成邮箱符号) 中国合作伙伴在开发解决方案过程中如果遇到问题或对B1的功能提出需求都可以通过该邮箱告诉我们.B1开发团队会为我们的解决方案供应商提供最快速有效的技术及开发支持. 2. SDN中文论坛 为了提升现有中文论坛的影响力,

  • I'm a Rookie and need some help PLEASE

    My daughters purchased an IPod for my for my birthday and filled it with music from their PC. Their PC is gone. Can I download my IPOD to my computer so I can use Itunes to listen to my music when my IPOD is elsewhere and to have a backup of my music

  • Lightroom Linked to Business Application

    July 15, 2011 Hello: I'm interested in a business application that links to Lightroom 2.7; the operating system is Windows XP.  The application would link Photoshop files to cost, sale price, customers, etc.  Hopefully, a thumbnail of the photo could

  • Payment procedure

    Hi experts actually i am ABAP guy .. i am going through Purchasing business scenario functiopnally , now learned from PO creation to Invoice my doubt is how can i proceed to make the payment againist the created invoice. i have cretaed  purchsing -po

  • Mobile Application in FlashBuilder 4.5

    Hi friends... I developed one mobile application in flash builder 4.5,But am getting the output as Blank Screen. Anybody give the solution.