Using table function with merge

I wanna use table function on a table type in a merger statement inside a procedure .
1 create or replace procedure fnd_proc as
2          cursor fnd_c is
                    select * from fnd_columns;
3          type test_t is table of fnd_columns%rowtype;
4          fnd_t test_t;
5 begin
6          merge into sample s using (select * from table  (fnd_pkg1.get_records(cursor(select * from fnd_columns)))) f
7          on (s.application_id = f.application_id)
8          when matched then
9                  update set last_update_date=sysdate
10          when not matched then
11                 insert(APPLICATION_ID,TABLE_ID,COLUMN_ID) values(f.APPLICATION_ID,f.TABLE_ID,f.COLUMN_ID);
12 end;
create or replace package fnd_pkg1 as
     type fnd_type is table of fnd_columns%rowtype;
     function get_records(p_cursor IN  SYS_REFCURSOR) return fnd_type;
end;
create or replace package body fnd_pkg1 as
        function get_records(p_cursor IN  SYS_REFCURSOR) return fnd_type is
                fnd_data fnd_type;
        begin
                fetch p_cursor bulk collect into fnd_data;
                return fnd_data;
        end;
end;
/When i compile the procedure fnd_proc I get the following error
LINE/COL ERROR
6/11 PL/SQL: SQL Statement ignored
6/52 PL/SQL: ORA-22905: cannot access rows from a non-nested table
item
6/67 PLS-00642: local collection types not allowed in SQL statements
Let me know what has to be done

michaels>  CREATE TABLE fnd_columns (application_id ,table_id ,column_id ,last_update_date )
AS SELECT object_id,data_object_id,ROWNUM,created FROM all_objects
Table created.
michaels>  CREATE TABLE SAMPLE (application_id INTEGER,table_id INTEGER,column_id INTEGER,last_update_date DATE)
Table created.
michaels>  CREATE OR REPLACE TYPE fnd_obj AS OBJECT (
   application_id     INTEGER,
   table_id           INTEGER,
   column_id          INTEGER,
   last_update_date   DATE
Type created.
michaels>  CREATE OR REPLACE TYPE fnd_type AS TABLE OF fnd_obj
Type created.
michaels>  CREATE OR REPLACE PACKAGE fnd_pkg1
AS
   FUNCTION get_records (p_cursor IN sys_refcursor)
      RETURN fnd_type;
   PROCEDURE fnd_proc;
END fnd_pkg1;
Package created.
michaels>  CREATE OR REPLACE PACKAGE BODY fnd_pkg1
AS
   FUNCTION get_records (p_cursor IN sys_refcursor)
      RETURN fnd_type
   IS
      fnd_data   fnd_type;
   BEGIN
      FETCH p_cursor
      BULK COLLECT INTO fnd_data;
      RETURN fnd_data;
   END get_records;
   PROCEDURE fnd_proc
   AS
      CURSOR fnd_c
      IS
         SELECT *
           FROM fnd_columns;
      TYPE test_t IS TABLE OF fnd_columns%ROWTYPE;
      fnd_t   test_t;
   BEGIN
      MERGE INTO SAMPLE s
         USING (SELECT *
                  FROM TABLE
                          (fnd_pkg1.get_records
                                     (CURSOR (SELECT fnd_obj (application_id,
                                                              table_id,
                                                              column_id,
                                                              last_update_date
                                                FROM fnd_columns
                          )) f
         ON (s.application_id = f.application_id)
         WHEN MATCHED THEN
            UPDATE
               SET last_update_date = SYSDATE
         WHEN NOT MATCHED THEN
            INSERT (application_id, table_id, column_id)
            VALUES (f.application_id, f.table_id, f.column_id);
   END fnd_proc;
END fnd_pkg1;
Package body created.
michaels>  BEGIN
   fnd_pkg1.fnd_proc;
END;
PL/SQL procedure successfully completed.
michaels>  SELECT COUNT (*)
  FROM SAMPLE
  COUNT(*)
     47469Now I'd like to see the stats and the ferrari too ;-)

Similar Messages

  • How can I use AGO function with aggregates

    I use aggregated table and a detailed table
    I have time hierarchy whose lowest level is date. For sales I
    created year-to-year (YTD) comparision with AGO function. It
    works OK.
    BUT, I want to speed it up, so I used aggregates. I created new
    time table grouped by MONTH and corresponding agg_SALES table. I
    created connections and mapped the fields. It works OK for
    normal queries, that means my queries at month level use
    aggregates. BUT when I add YTD measures or YAGO measure in query, it goes to
    then SALES table whose grain is date.
    How can I force BI Server to use AGO function with aggregates?
    I use OBIEE 10.1.3.4
    Thank you
    Ishaq
    (Question originally taken from ITtoolbox and posted by Gorazd)
    SORRY - THE QUESTION IS IN THE WRONG FORUM
    Edited by: ishaq12 on Nov 19, 2008 12:21 PM

    Hi,
    you can not do it in Administration tool but you can set agregation for that field in Answers (fx->Agregation rule->Sum) and effect should be the same. Note that it may not work properly on Oracle 10g as generated SQL is not 100% recognized, on 11g everything is OK (at least in my case).
    Regards,
    Marko
    Edited by: user10449532 on 2008.11.19 06:29

  • Returning Collection using table function

    Hi,
    I'm trying to return a collection with record type using table function but facing some issues.
    Could someone help me with it.
    SUNNY@11gR1> create or replace package test_pack as
      2  type rec_typ is record (
      3  empname varchar2(30),
      4  empage number(2),
      5  empsal number(10));
      6  type nest_typ is table of rec_typ;
      7  function list_emp return nest_typ;
      8  end;
      9  /
    Package created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> create or replace package body test_pack is
      2  function list_emp return nest_typ is
      3  nest_var nest_typ := nest_typ();
      4  begin
      5  nest_var.extend;
      6  nest_var(nest_var.last).empname := 'KING';
      7  nest_var(nest_var.last).empage := 25;
      8  nest_var(nest_var.last).empsal := 2500;
      9  nest_var.extend;
    10  nest_var(nest_var.last).empname := 'SCOTT';
    11  nest_var(nest_var.last).empage := 22;
    12  nest_var(nest_var.last).empsal := 3500;
    13  nest_var.extend;
    14  nest_var(nest_var.last).empname := 'BLAKE';
    15  nest_var(nest_var.last).empage := 1;
    16  return nest_var;
    17  end;
    18  end;
    19  /
    Package body created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> select * from table(test_pack.list_emp);
    select * from table(test_pack.list_emp)
    ERROR at line 1:
    ORA-00902: invalid datatype
    Elapsed: 00:00:00.01
    SUNNY@11gR1>Regards,
    Sunny

    But if I use pipelined function instead then I'm able to retrieve the records
    SUNNY@11gR1> create or replace package test_pack as
      2  type rec_typ is record (
      3  empname varchar2(30),
      4  empage number(2),
      5  empsal number(10));
      6  type nest_typ is table of rec_typ;
      7  function list_emp return nest_typ pipelined;
      8  end;
      9  /
    Package created.
    SUNNY@11gR1> ed
    Wrote file afiedt.buf
      1  create or replace package body test_pack as
      2  function list_emp return nest_typ pipelined is
      3  rec_var rec_typ;
      4  begin
      5  rec_var.empname := 'KING';
      6  rec_var.empage := 24;
      7  rec_var.empsal := 10000;
      8  pipe row(rec_var);
      9  rec_var.empname:='SCOTT';
    10  rec_var.empage:=22;
    11  rec_var.empsal:=2000;
    12  pipe row(rec_var);
    13  rec_var.empname:='BLAKE';
    14  rec_var.empage:='1';
    15  pipe row(rec_var);
    16  return;
    17  end;
    18* end;
    SUNNY@11gR1> /
    Package body created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> select * from table(test_pack.list_emp);
    EMPNAME                            EMPAGE     EMPSAL
    KING                                   24      10000
    SCOTT                                  22       2000
    BLAKE                                   1       2000
    Elapsed: 00:00:00.00Why is that?
    Regards,
    Sunny

  • Ora-600 using table function over db link

    Hi,
    I have a table function n my target schema (OWB 9.2.0.4 on Oracle 9.2.0.5) with the following signature:
    function uii_get_exchange_data_tf(
    p_input_values in sys_refcursor
    ) return uii_exchange_table_t pipelined
    When I try to use this with a remote table over a db link, e.g.:
    =============
    select * from table(uii_get_exchange_data_tf(cursor (select sub_zone || '/' || exch_grp_cd exchange_id,
    exch_name exchange_name FROM cds_exchange_test@uiid1@uiidraconn order by exchange_id)))
    ==============
    I get this:
    ================
    ORA-00600: internal error code, arguments: [kokbnp2], [942], [], [], [], [], [],
    ORA-06512: at "UII_ODS_OWNER_DEV.UII_GET_EXCHANGE_DATA_TF", line 21
    =================
    However, if I create a local view with the same remote select like this:
    ===================
    CREATE OR REPLACE FORCE VIEW UII_CDS_EXCHANGE_RV
    AS SELECT sub_zone || '/' || exch_grp_cd exchange_id,
    exch_name exchange_name
    FROM cds_css_exch_detail@uiid1@uiidraconn;
    ====================
    Then everything works fine.
    Can someone help ? I'm sure I'm dooing something silly, since so many people seem to be using table functions from OWB just fine; but I can't figure out what :-(
    Thanks in advance.
    Regards,
    Biswa.

    Hello,
    Is this query works fine without creating mview
    SELECT COL1,COL2, CASE when COL3 = Y then (select X from MASTER2@DBLINK) FROM MASTER1@DBLINK.
    try something like this
    SELECT col1, col2, CASE
                          WHEN col3 = y
                          THEN
                             (SELECT x
                              FROM master2@dblink)
                       END
                          my
    FROM master1@dblinkregards

  • Creating Report using EPM Functions with Dynamic Filters

    Hi All,
    I am new to BPC, In BPC 7.5 i seen like we can generate EPM report using EVDRE function very quickly and easy too. Is the same feature is existing in BPC 10.0 ? if no how can we create EPM reports using EPM Functions with Dynamic Filters on the Members of the dimension like in BPC 7.5.
    And i searched in SDN, there is no suitable blogs or documents which are related to generation of Reports using EPM Functions. All are described just in simple syntax way. It is not going to be understand for the beginners.
    Would you please specify in detail step by step.
    Thanks in Advance.
    Siva Nagaraju

    Siva,
    These functions are not used to create reports per se but rather assist in building reports. For ex, you want to make use of certain property to derive any of the dimension members in one of your axes, you will use EPMMemberProperty. Similary, if you want to override members in any axis, you will make use of EPMDimensionOverride.
    Also, EvDRE is not replacement of EPM functions. Rather, you simply create reports using report editor (drag and drop) and then make use of EPM functions to build your report. Forget EvDRE for now.
    You can protect your report to not allow users to have that Edit Report enabled for them.
    As Vadim rightly pointed out, start building some reports and then ask specific questions.
    Hope it clears your doubts.

  • Using modular functions with movieclips

    hi guys, this morning i was looking a tutorial that shows how to make modular functions, the user only used numbers, i was wandering if there is a way to use this with movieclips or childs.
    The example was:
    function addNumber(num1:Number,  num2:Number,  num3:Number):void
    trace(num1+num2*num3);
    addNumber(3, 4, 7);
    i tried using a movieclip called cuadro and triying to move on the x axis, but it didnt work out:
    function mObj(obj1:MovieClip,  num1:Number):void
    obj1.x = num1;
    addNumber(cuadro, 50);
    any sugestion?
    thnks in advance

    oh sorry my bad, i was trying another stuff
    i know that the last line must say
    mObj(cuadro, 50);
    what im trying to do is use the function with some objects in the stage, and for example when i press the first button, it will write mObj(cuadro1, 50) , button2  mObj(cuadro2, 80), so i can use the same function for diferents objects

  • Using Multiple Functions with in members selection of Hyperion Financial St

    Hello everyone, I am trying to retrieve all the level 0 entity members from a specific Level 3 entity member. Can I use multiple Functions with in Report studio to do this?? Or is creating an alt hierarcy my only option?
    Thanks

    You can try doing System Defined member list Lev 0 AND Descendants of Lv 3 member
    JTS

  • How to use aggregate function with Date

    Hi All,
    I have a group of date from that is it possible to Max and Min of date.
    I have tried like this but its errored out <?MIN (current-group()/CREATION_DATE)?>.
    I have also tried like this but it doesnt works
    <?xdoxslt:minimum(CREATION_DATE)?>
    Is it possible to use aggregate function with date values.
    Thanks & Regards
    Srikkanth

    Hi KAVI PRIYA,
    if date is not in cannonical format, how can we change it in BI publisher, then how to calcualte minimum and as well as maximum.
    please advise me,
    Thanks,
    Sri

  • How to use TRUNC function with dates in Expression Builder in OBIEE.

    Hi There,
    How to use TRUNC function with dates in Expression Builder in OBIEE.
    TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
    Thanks in advance

    use this instead:
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE)

  • How to use INVOKE function with INT parameter types

    Can you tell me how to use invoke function with int parameter type ?

    Pass the int as an Integer.

  • C++: Is it possible using callback function with ncacn_http and rpcproxy server ?

    I have a remote procedure and I can call it using http over rpc. I pass trough an rpc proxy server for arriving to my rpc server.
    But I cannot call a callback function to my client inside the server function.
    Is it possible using callback function with ncacn_http and rpcproxy server ?
    We are using IIS on windows server 2008 R2 and the server rpc and the client on the same PC with rpc rpoxy.
    If I use ncan_ip_tcp all works fine.
    Thanks
    Gianluca

    Hi,
    About the develop question please post to the MSDN forum.
    MSDN forum Developer Network
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=WAVirtualMachinesVirtualNetwork&filter=alltypes&sort=lastpostdesc
    Thanks for your understanding and support.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Can I use table function inside Dynamic query ?

    Dear Gurus,
    I have following code
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
              'CAST (OtherNoList AS CRITERIA_LIST_TABLE) '||
                   ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING;
    END;
    Can I use Table function inside dynamic query.
    Thanking in advance
    Sanjeev

    Try:
    DECLARE
    TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
    OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
    QUERY_STRING VARCHAR2(4000);
    BEGIN
    OtherNoList := CRITERIA_LIST_TABLE();
    SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
    FROM DUAL
    CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
    QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
    'SELECT C1,'||
    'C2 '||
    'FROM TAB1 ,'||
    'TABLE( '||
    'CAST (:OtherNoList AS CRITERIA_LIST_TABLE) '||
    ') OTHRNOS '||
    'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
    DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
    EXECUTE IMMEDIATE QUERY_STRING using OtherNoList;
    END;p.s. not tested
    Amiel Davis

  • Use private function with interface

    I'm working with ActionScript 2 and wanted to use an
    interface for one of my classes. However, the functions that it
    would define should be private in the classes that implement the
    interface. The problem is that I can't define private functions in
    the interface, and if I leave off any scope in the interface
    ("function findAndSetInformation():Void;") and make it private in
    the implementing class ("private function
    findAndSetInformation():Void {...") I get the error: "The
    implementation of the interface method doesn't match its
    definition.

    WHATS UP ?? WHERE IS TEH MODERATOR ?!!!!
    NO REPLY TELL NOW !!!!
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Yh:
    hi,
    how can i used REPLACE function with LOB database item????!!!1<HR></BLOCKQUOTE>
    null

  • Using Pipeline Table functions with other tables

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables. In my tests, selecting from just the pipelined table perform pretty well (whether it is directly from the pipleined table or the view I created on top of it). Where I start to see some degregation when I try to join the pipelined tabe view to other tables and add where conditions.
    ie:
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'
    I have seen some articles and blogs that mention this as a cardinality issue, and offer some undocumented methods to try and combat.
    Can someone please give me some advice or tips on this. Thanks!
    I have created a simple example using the emp table below to help illustrate what I am doing.
    DROP TYPE EMP_TYPE;
    DROP TYPE EMP_SEQ;
    CREATE OR REPLACE TYPE EMP_SEQ AS OBJECT
           ( EMPNO                                         NUMBER(10),
             ENAME                                         VARCHAR2(100),
             JOB                                           VARCHAR2(100));
    CREATE OR REPLACE TYPE EMP_TYPE AS TABLE OF EMP_SEQ;
    CREATE OR REPLACE FUNCTION get_emp return EMP_TYPE PIPELINED AS
    BEGIN
      FOR cur IN (SELECT
                    empno,
                    ename,
                    job
                  FROM emp
             LOOP
               PIPE ROW(EMP_SEQ(cur.empno,
                                cur.ename,
                                cur.job));
             END LOOP;
             RETURN;
    END get_emp;
    create OR REPLACE view EMP_VIEW as select * from table(get_emp());
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables
    Which begs the question: WHY? What PROBLEM are you trying to solve and what makes you think using pipelined table functions is the best way to solve that problem?
    The lack of information about cardinality is the likely root of the degradation you noticed as already mentioned.
    But that should be a red flag about pipelined functions in general. PIPELINED functions hide virtually ALL KNOWLEDGE about the result set that is produced; cardinality is just the tip of the iceberg. Those functions pretty much say 'here is a result set' without ANY information about the number of rows (cardinality), distinct values for any columns, nullability of any columns, constraints that might apply to any columns (foreign key, primary key) and so on.
    If you are going to hide all of that information from Oracle that would normally be used to help optimize queries and select the appropriate execution plan you need to have a VERY good reason.
    The use of PIPELINED functions should be reserved for those use cases where ordinary SQL and PL/SQL cannot get the job done. That is they are a 'special case' solution.
    The classic use case for those functions is for the transform stage of ETL where multiple pipelined functions are chained together: one function feeds its rows to the next function which feeds its rows to another and so on. Each of those 'chained' functions is roughly analogous to a full table scan of the data that often does not need to be joined to other data except perhaps low volumn lookup tables where the data may even be cached.
    I suggest that any exploratory or prototyping work you do use standard relational tables until such point as you run into a problem whose solution might require PIPELINED functions to solve.

  • Getting ORA-00600 when using table functions

    Hello,
    I am trying to use simple table function:
    create or replace type StatCall AS OBJECT (
    dial_number varchar2(255),
    start_date date,
    duration number(20)
    create or replace type StatCallSet AS TABLE OF StatCall;
    create or replace package ref IS
    type refcall_t IS REF CURSOR RETURN calls%ROWTYPE;
    end ref;
    create or replace function GetStats(p ref.refcall_t) return StatCallSet pipelined is
    out_rec StatCall;
    in_rec p%ROWTYPE;
    BEGIN
    LOOP
    FETCH p INTO in_rec;
    EXIT WHEN p%NOTFOUND;
    out_rec.dial_number := in_rec.dial_number;
    out_rec.start_date := in_rec.start_date;
    out_rec.duration := in_rec.duration;
    PIPE ROW(out_rec);
    END LOOP;
    CLOSE p;
    RETURN;
    END;
    select * from TABLE(GetStats(CURSOR(select * from call)));
    And I get:
    ORA-00600: internal error code, arguments: [17285], [0xFFFFFFFF7C4900A8], [1], [0x3943BA5E0], [], [], [], []
    Oracle 9.2.0.2
    Are there any ideas about how to fix this?

    What version of the database?
    Which flavor of Disco (Plus, Desktop, Viewer)?
    Standars EUL or Apps EUL?
    Can you post the code for the calculation?
    ORA-600 errors, as you mentioned, are internal, and may require opening a dialog with Oracle support. Then again, it could be something else in the calculation that is causing the sky to fall.

Maybe you are looking for

  • 11.1.0.7 solaris 两节点rac 因ora-07445 kjcvmsc()+232错误导致一个实例重启

    有一套两节点11.1.0.7版本的数据库,一节点因ora-07445 kjcvmsc()+232错误导致实例重启,在mos上没有查到关于ora-07445 kjcvmsc()+232的太多信息,请ML帮忙看下. alert日志报错信息 Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0x69] [PC:0x104C7A0A8, kjcvmsc()+232] Errors in file /export/home/orac

  • Domestic Partner needs to be added to payroll register in order

    Hi llll, Domestic Partner needs to be added to payroll register in order to reconcile during recon. Help me on this

  • Difference between 'Camera Raw Defaults' option and Default button

    I am using ACR 4.6 under CS3 in Windows. If I open an image and click the Default button above the exposure sliders, all the tonal settings are reset to the defaults, but Clarity, Vibrance and Saturation are not altered. If I select 'Camera Raw Defau

  • Report broadcast problem

    Hi, Daily we are broadcasting the reports through process chains and some reports through normal schedlues.today when I am trying to execute manually they  are not broadcasting and in SM50 I cant see any log. In sost also there is no reports availabl

  • IDE does not close

    Hello, I am using Forte, Enterprise Edition (Build 020624) on Windows XP. When I choose File > Exit, my processor usage goes to 100% and Forte just stays open as if I never selected exit. I have to go to task manager and kill the process for it to cl