Package and table functions

Hi i have created package like this.
create or replace
PACKAGE Package_x is
TYPE collect_tablex IS TABLE OF ASAP.tablex%RowType ;
/* TODO enter package declarations (types, exceptions, methods etc) here */
function f_tablefunc(arg_1 in number)
return collect_tablex;
END Package_x;
select * from table(cast (Package_x.f_tablefunc(54115,54114) as Package_x.collect_tablex ))
I have written function in body which is running fine when i debug.
but when i used above select giving
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
*Cause:   
*Action:
Error at Line: 15 Column: 76

how about this?
SQL> create table tablex
  2  (id number
  3  ,name varchar2(50)
  4  );
Table created.
SQL>
SQL> create or replace
  2  PACKAGE Package_x is
  3     TYPE collect_tablex IS TABLE OF tablex%RowType ;
  4  function f_tablefunc(arg_1 in number)
  5     return collect_tablex pipelined;
  6  END Package_x;
  7  /
Package created.
SQL> show error
No errors.
SQL>
SQL> create or replace package body package_x as
  2  function f_tablefunc(arg_1 in number)
  3     return collect_tablex pipelined
  4  is
  5     l_row tablex%rowtype;
  6  begin
  7     select arg_1, 'Testing' into l_row from dual;
  8     pipe row(l_row); return;
  9  end;
10  end;
11  /
Package body created.
SQL>
SQL> show error
No errors.
SQL>
SQL>
SQL> select *
  2    from table (package_x.f_tablefunc(10))
  3  /
        ID NAME
        10 Testing
SQL>
SQL>
SQL> drop table tablex
  2  /
Table dropped.
SQL> drop package package_x
  2  /
Package dropped.
SQL>

Similar Messages

  • ORA-12714 error using NVARCHAR2, REF CURSOR and TABLE FUNCTION

    Hello,
    we have tested this simple script on all the following versions of Oracle: 9.2.0.3, 10.2.0.1.0 , 11.1.0.6.0 - but we got the same error in everyone of these.
    CREATE OR REPLACE TYPE Rec_Prova IS OBJECT(
        Id INTEGER,
        NodeValue NVARCHAR2(50)
    CREATE OR REPLACE TYPE Tab_Prova IS TABLE OF Rec_Prova;
    DECLARE
        CurProva SYS_REFCURSOR;
        varTable Tab_Prova := Tab_Prova();
    BEGIN
        OPEN CurProva FOR
            SELECT Id, NodeValue FROM TABLE(CAST(varTable AS Tab_Prova));
    END;The error is: "ORA-12714: invalid national character set specified"
    We know that changing the type of NodeValue from NVARCHAR2 to NCLOB it works, but the performances are very poor.
    Therefore this solution is not acceptable for us.
    We also know that if the character set of the database is set to unicode (NLS_NCHAR_CHARACTERSET = AL16UTF16) we can use the VARCHAR2 for store also the unicode characters and the problem is solved. But some of our customers can't change the settings of theirs databases... moreover, in this forum someone says:
    "To all dba's who try to change the NLS_CHARACTERSET or NLS_NCHAR_CHARACTERSET by updating props$ . This is NOT supported and WILL corrupt your database. This is one of the best way's to destroy a complete dataset. Oracle Support will TRY to help you out of this but Oracle will NOT warrant that the data can be recoverd or recovered data is correct. Most likely you WILL be asked to do a FULL export and a COMPLETE rebuild of the database."
    Is there any workaround except the two that I have mentioned?
    Thank you in advance.
    Edited by: user11929330 on 22-set-2009 7.50

    ORA-12714: invalid national character set specified
    Cause: Only UTF8 and AL16UTF16 are allowed to be used as the national character set
    Action: Ensure that the specified national character set is valid
    So it looks like that you should change the character set or go for NCLOB (and if you're on version 11, maybe securefiles gives you the performance you want).
    -Andy

  • Inconsistent SQL results when using View with UNION-ALL and table function

    Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
    This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
    Database version: 11.2.0.3 Enterprise Edition, Single node
    Thank you.
    CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    CREATE OR REPLACE VIEW TEMP_T1T2_V AS
    SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
    CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
    SET SERVEROUTPUT ON;
    DECLARE
    TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
    TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
    TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
    PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
    BEGIN
    TEMP_OBJ_TAB.EXTEND;
    TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
    END;
    BEGIN
    ADD_TO_TEMP_OBJ_TAB(100);
    ADD_TO_TEMP_OBJ_TAB(116);
    ADD_TO_TEMP_OBJ_TAB(279);
    ADD_TO_TEMP_OBJ_TAB(364);
    DBMS_OUTPUT.PUT_LINE('=====================');
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    FROM TEMP_T1T2_V VW
    WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    END LOOP;
    ELSE
    DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    END IF;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    END;
    /

    I can reproduce it:
    SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    Enter user-name: scott
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    72883 rows updated.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
      2  SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    View created.
    SQL>
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
      2  /
    Type created.
    SQL> SET SERVEROUTPUT ON;
    SQL>
    SQL> DECLARE
      2  TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
      3  TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
      4  TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
      5  PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
      6  BEGIN
      7  TEMP_OBJ_TAB.EXTEND;
      8  TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
      9  END;
    10  BEGIN
    11  ADD_TO_TEMP_OBJ_TAB(100);
    12  ADD_TO_TEMP_OBJ_TAB(116);
    13  ADD_TO_TEMP_OBJ_TAB(279);
    14  ADD_TO_TEMP_OBJ_TAB(364);
    15  DBMS_OUTPUT.PUT_LINE('=====================');
    16  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    17  LOOP
    18  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    19  END LOOP;
    20  DBMS_OUTPUT.PUT_LINE('---------------------');
    21  SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    22  FROM TEMP_T1T2_V VW
    23  WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    24  FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    25  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    26  LOOP
    27  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    28  END LOOP;
    29  DBMS_OUTPUT.PUT_LINE('---------------------');
    30  IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    31  FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    32  LOOP
    33  DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    34  END LOOP;
    35  ELSE
    36  DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    37  END IF;
    38  DBMS_OUTPUT.PUT_LINE('---------------------');
    39  END;
    40  /
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    PL/SQL procedure successfully completed.
    SQL> column object_name format a30
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
           100 ORA$BASE
           116 DUAL
           279 MAP_OBJECT
           364 I_AUDIT
    SQL>  Works fine in:
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    100 : ORA$BASE
    116 : DUAL
    364 : SYSTEM_PRIVILEGE_MAP
    279 : MAP_OBJECT
    PL/SQL procedure successfully completed.
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
          100 ORA$BASE
          116 DUAL
          364 SYSTEM_PRIVILEGE_MAP
          279 MAP_OBJECT
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>SY.
    Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM

  • How get list of tables/functions/other objects used in a mapping?

    Hi,
    I would like to know list of objects such as tables, views, functions, procedures and table functions of all mappings in a module.
    Could any one please explain me, how can I do this using OMB+ scripting.
    Thank you,
    Regards,
    Gowtham Sen.

    OMBRETRIEVE MAPPING 'MAP_NAME' GET TABLE OPERATORS
    OMBRETRIEVE MAPPING 'MAP_NAME' GET VIEW OPERATORS
    OMBRETRIEVE MAPPING 'MAP_NAME' GET TRANSFORMATION OPERATORS
    OMBRETRIEVE MAPPING 'MAP_NAME' GET TABLE_FUNCTION OPERATORS
    Alternative variant (and maybe more simple) - use dictionary view DBA_DEPENDENCIES (or all_dependencies):
    select * from dba_dependencies where owner='MAP_OWNER' and type in ('PACKAGE','PACKAGE_BODY') and name='MAP_NAME'
    Oleg

  • Using table function in JDBC

    Hi All,
    im Oracle 9i R2 :
    there are package with table function and JDBC client .
    In client code :
    Statement st = con.createStatement() ;
    ResultSet rs = st.executeQuery("select * from table(pkg.func)") ;
    while (rs.next())
    System.out.println(rs.getString(1)) ;
    - and that not work ...
    What is wrong ? :)
    With best regards, Slava

    Can you define "not work" here... Do you get an error? If so, what is the error number you are getting (ORA-xxxxx)?
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • TABLE FUNCTION call - cast - InvalidType ORA-06550

    hello, I keep getting the following exception: +"... PL/SQL: ORA-00902: invalid datatype ORA-06550: line 7, column 1: ..."+
    I created type here:
    CREATE OR REPLACE PACKAGE types
    AS
    TYPE TmpHiearchyMapTableType IS TABLE OF TMP_HIERARCHYMAP%ROWTYPE INDEX BY BINARY_INTEGER;
    END;
    Then my TABLE FUNCTION resembles...
    CREATE OR REPLACE FUNCTION spGetParentsTable
    ObjectId number,
    ObjectClassifier varchar2
    RETURN types.TmpHiearchyMapTableType
    IS
    TmpHierarchyMap types.TmpHiearchyMapTableType;
    BEGIN
         RETURN TmpHierarchyMap;
    END;
    I tried to invoke the table function and loop through it by:
    DECLARE
    oMappingTable types.TmpHiearchyMapTableType;
    BEGIN
    -- This OKAY!
    oMappingTable := spGetParentsTable(2,'ThinkFundamentals.Util.Security.SystemUser');
    -- FAILED here! "Invalid Type"!?!
    select * from table(cast(oMappingtable as types.TmpHiearchyMapTableType));
    dbms_output.put_line('done!');
    END;
    Thanks!
    REF: http://www.databasejournal.com/features/oracle/article.php/3352091/CASTing-About-For-a-Solution-Using-CAST-and-Table-Functions-in-PLSQL.htm

    hello I managed to switched from "Associate Array" to "Nested table" but still having trouble SELECT * FROM table(...), it keep saying "Invalid DataType" - detail as follows:
    -- NOTE 1: Here's how I create the object type (Be nice if I can just say "CREATE OR REPLACE TYPE TmpHierarchyMapObjType AS OBJECT      (TMP_HIERACHICAL.ROWTYPE)" instead of having to duplicate column definition.
    CREATE OR REPLACE TYPE TmpHierarchyMapObjType AS OBJECT     
    Id numeric(19,0) ,
    ParentId numeric(19,0),
    ChildId numeric(19,0),
    TmpUID varchar2(32),
    ReferencedId numeric(19,0),
    -- NOTE 2: I can't put "TmpHierarchyMapObjType" inside the package but that's not crucial I suppose.
    CREATE OR REPLACE PACKAGE types
    AS
    TYPE cursorType IS REF CURSOR;
    TYPE TmpHiearchyMapTableType IS TABLE OF TmpHierarchyMapObjType; /* Use "Nested Table" instead of Associative Array */
    /* TYPE TmpHiearchyMapTableType IS TABLE OF TMP_HIERARCHYMAP%ROWTYPE INDEX BY BINARY_INTEGER; */
    END;
    -- NOTE 3: Here's my TABLE FUNCTION which now returns a "Nested Table" as supposed to "Associative Array" (with different enumeration syntax)
    CREATE OR REPLACE FUNCTION spGetParentsTable
    ObjectId number,
    ObjectClassifier varchar2
    RETURN ty[es.TmpHiearchyMapTableType -- Now an "Nested Table", not "Associative Array"
    IS
        TmpHierarchyMap types.TmpHiearchyMapTableType;
        ThisTempId varchar2(32);
        CURSOR spGetParents_cursor IS
            SELECT
            ReferencedId Id,
            ParentId,
            ChildId,
            FROM TMP_HIERARCHYMAP
            WHERE TmpUID = ThisTempId;
    BEGIN
        SELECT sys_guid() INTO ThisTempId FROM dual;
        spRecursiveGetParents(ObjectId, ObjectClassifier, ThisTempId);
        -- (Commented out) TmpHierarchyMapMAX := 0;
        FOR oMap in spGetParents_cursor LOOP
            -- (Commented out) TmpHierarchyMapMAX := TmpHierarchyMapMAX + 1;
              _TmpHierarchyMap.Extend();
            TmpHierarchyMap(TmpHierarchyMap.Count) := TmpHierarchyMapObjType( oMap.Id
                                                                    , oMap.ParentId
                                                                    , oMap.ChildId
              NOTE: *(Commented out)*  Not using "Associative Array", now using "Nested table" instead.
            TmpHierarchyMap(TmpHierarchyMapMAX).Id := oMap.Id;
            TmpHierarchyMap(TmpHierarchyMapMAX).ParentId := oMap.ParentId;
            TmpHierarchyMap(TmpHierarchyMapMAX).ChildId := oMap.ChildId;
        END LOOP;
        DELETE FROM TMP_HIERARCHYMAP WHERE TmpUID = ThisTempId;
        RETURN TmpHierarchyMap;
    END spGetParentsTable;
    *-- Lastly, I want to enumerate nested table.*
    DECLARE
    oMappingTable types.TmpHiearchyMapTableType;
    BEGIN
    oMappingTable := spGetParentsTable(2,'ThinkFundamentals.Util.Security.SystemUser');
    *-- NOTE 4: This is my end-goal! But still complaining "ORA-00902: invalid datatype"*
    select * from table(cast(oMappingtable as types.TmpHiearchyMapTableType));
    dbms_output.put_line('done!');
    END;
    *REF:*
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#LNPLS005
    http://www.devshed.com/c/a/Oracle/Associative-Arrays-in-Oracle-PLSQL-Introduction/2/
    http://www.devshed.com/c/a/Oracle/Database-Interaction-with-PLSQL-Nested-Tables/2/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • HOW to pass page parameter into table function in  HTMLDB

    I created this object and table function in database.
    create or replace TYPE date_flow_type
    AS OBJECT (
    time           date,
    max_time      number,
    avg_total           NUMBER,
    sum_total      NUMBER,
    max_total      NUMBER,
    change_rate      number
    create or replace TYPE date_flow_table_type AS TABLE OF date_flow_type;
    create or replace function ret_date(p_date date default sysdate) return date_flow_table_type is
    v_tbl1 date_flow_table_type :=date_flow_table_type();
    begin
    v_tbl1.extend;
    v_tbl1(v_tbl1.last):=date_flow_type (p_date,1,1,1,1,1);
    return v_tbl1;
    end;
    and it is correct in htmldb when using in these ways
    SELECT TIME da,
         max_time max_time,
         sum_total total,
         max_total max_total,
    change_rate
    FROM TABLE ( ret_icp_date_flow ) a;
    SELECT TIME da,
         max_time max_time,
         sum_total total,
         max_total max_total,
    change_rate
    FROM TABLE ( ret_icp_date_flow( sysdate-1 )) a;
    but return error
    ORA-00904: "RET_ICP_DATE_FLOW": 无效的标识符
    when pasing page parameter into the table function
    SELECT TIME da,
    max_time max_time,
    sum_total total,
    max_total max_total,
    change_rate
    FROM TABLE ( ret_icp_date_flow( to_date(:p1_date,'yyyy-mm-dd') )) a
    and this sql is correct while running in sqlplus .

    Hi!
    Thanks for your reply!
    I have tried this solution but it doesn't work!
    When I do getInitParameter in the init function, the servlet take the default values...
    Maybe I have wrote something wrong?
    Excuse me for my english,
    Thanks

  • Question about Table Function inside a Package

    Hi … I am new in PL/SQL, I am trying to use a table function to create depending on a value passed to it (I am using 10g). Everything works great but the moment I add a parameter everything explode, I am creating it on a package.
    SQL that work
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
    FUNCTION Fund_Amount
    RETURN financial_reports.Fund_Amount_Table
    pipelined parallel_enable IS
    cur_row financial_reports.Fund_Amount_Record;
    BEGIN
    FOR cur_row IN
    SELECT
    to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID
    ,to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID
    ,to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER
    ,to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID
    ,sum(be.amt) AS AMOUNT
    FROM
    linc.budgetdb_usr5@stjohnsfp bu5
    JOIN linc.budgetdb_event@stjohnsfp be ON
    bu5.keyvalue = be.acctno
    WHERE
    bu5.keyvalue like '__-__-__-____-____-_____'
    AND bu5.usrdata like '__-__-__'
    AND bu5.fieldnum = 1
    AND bu5.ispecname = 'GLMST'
    AND to_number(substr(bu5.usrdata, 7, 2)) = 1
    GROUP BY
    bu5.usrdata
    ORDER BY
    bu5.usrdata
    LOOP
    PIPE ROW(cur_row);
    END LOOP;
    END Fund_Amount;
    END financial_reports;
    SQL that do not work …
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
    FUNCTION Fund_Amount (Fund_Id IN NUMBER)
    RETURN financial_reports.Fund_Amount_Table
    pipelined parallel_enable IS
    cur_row financial_reports.Fund_Amount_Record;
    fund_id_int NUMBER;
    BEGIN
    fund_id_int := Fund_Id;
    FOR cur_row IN
    SELECT
    to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID
    ,to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID
    ,to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER
    ,to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID
    ,sum(be.amt) AS AMOUNT
    FROM
    linc.budgetdb_usr5@stjohnsfp bu5
    JOIN linc.budgetdb_event@stjohnsfp be ON
    bu5.keyvalue = be.acctno
    WHERE
    bu5.keyvalue like '__-__-__-____-____-_____'
    AND bu5.usrdata like '__-__-__'
    AND bu5.fieldnum = 1
    AND bu5.ispecname = 'GLMST'
    AND to_number(substr(bu5.usrdata, 7, 2)) = fund_id_int
    GROUP BY
    bu5.usrdata
    ORDER BY
    bu5.usrdata
    LOOP
    PIPE ROW(cur_row);
    END LOOP;
    END Fund_Amount;
    END financial_reports;
    Error … (This works without the parameter)
    Error starting at line 43 in command:
    select * from table(financial_reports.Fund_Amount(1) )
    Error at Command Line:1 Column:14
    Error report:
    SQL Error: ORA-22905: cannot access rows from a non-nested table item
    Any help would be greatly appreciated

    try renaming your parameter so as not to confuse with what you are using in your column " to_number(substr(bu5.usrdata, 7, 2)) AS FUND_ID":
    CREATE OR REPLACE PACKAGE BODY financial_reports AS
      FUNCTION Fund_Amount (pFund_Id IN NUMBER)
        RETURN financial_reports.Fund_Amount_Table
        pipelined parallel_enable IS
        cur_row financial_reports.Fund_Amount_Record;
        fund_id_int NUMBER;
      BEGIN
        fund_id_int := pFund_Id;
        FOR cur_row IN ( SELECT to_number(substr(bu5.usrdata, 1, 1)) As SECTION_ID,
                                to_number(substr(bu5.usrdata, 2, 1)) As SUB_SECTION_ID,
                                to_number(substr(bu5.usrdata, 4, 2)) AS LINE_NUMBER,
                                to_number(substr(bu5.usrdata, 7, 2)) As FUND_ID,
                                sum(be.amt) AS AMOUNT
                           FROM linc.budgetdb_usr5@stjohnsfp bu5
                                  JOIN linc.budgetdb_event@stjohnsfp be ON bu5.keyvalue = be.acctno
                          WHERE bu5.keyvalue like '__-__-__-____-____-_____'
                            AND bu5.usrdata like '__-__-__'
                            AND bu5.fieldnum = 1
                            AND bu5.ispecname = 'GLMST'
                            AND to_number(substr(bu5.usrdata, 7, 2)) = fund_id_int
                         GROUP BY bu5.usrdata
                         ORDER BY bu5.usrdata ) LOOP
          PIPE ROW(cur_row);
        END LOOP;
      END Fund_Amount;
    END financial_reports;

  • Read access to procedures,function,packages and triggers

    Hi,
    I created a user with CREATE SESSION,SELECT ANY TABLE privilege. My objective is to create a user with read only access to other schemas. But the newly created user is not able to read procedures,function,packages and triggers. The new user need read access to procedures,function,packages and triggers. What is the priviege required for this access? Please help me to resolve this issue.
    Regards,
    Mat.

    Hi,
    Grant select all will give select privileges to all schema level objects except procedures,function,packages and triggers. But I need to grant read privileges on these objects to newly created user.
    Regards,
    Mat.

  • Offline database and table, view, package organization

    Hi,
    I tried to import my database schema with package, synonyms, tables, and views into a jdev project (11.1.1.1.0) and noticed that unlike the online db view, all object types are imported/organized under one folder (the name of the schema).
    For example, online db view shows the following structure
    + my_schema
    + Tables
    + MyTable1
    + Views
    + MyView1
    + Indexes
    + MyIndex1
    + Packages
    + MyPackage1
    + ....
    But the imported offline db view shows the following structure that has all different types of db objects listed under myschema folder
    + my_schema
    + MyTable1
    + MyView1
    + MyIndex1
    + MyPackage1
    + ....
    This offline representation is hard to work with and unusable if one wants to create database diagrams for different types of large # of database objects.
    Any comments?
    Thanks,

    Hi,
    It doesn't sound like it is the different package that is causing this message.  Is SB1 a system in your landscape? Are there any differences between the tables?
    The message seems to be suggesting that either the second table, or possibly the function group you are using were imported from another system.
    Regards,
    Nick

  • How to use the Table Function defined  in package in OWB?

    Hi,
    I defined a table function in a package. I am trying to use that in owb using Table function operator. But I came to know that, owb R1 supports only standalone table functions.
    Is there any other way to use the table function defined in a package. As like we create synonyms for functions, is there any other way to do this.
    I tryed to create synonyms, it is created. But it is showing compilation error. Finally I found that, we can't create synonyms for functions which are defined in packages.
    Any one can explain it, how to resolve this problem.
    Thank you,
    Regards
    Gowtham Sen.

    Hi Marcos,
    Thank you for reply.
    OWB R1 supports stand alone table functions. Here what I mean is, the table fucntion which is not inculded in any package is a stand alone table function.
    for example say sample_tbl_fn is a table function. It is defined as a function.It is a stand alone function. We call this fucntion as "samp_tbl_fn()";
    For exampe say sample_pkg is a package. say a function is defined in a package.
    then we call that function as sample_pkg.functionname(); This is not a stand alone function.
    I hope you understand it.
    owb supports stand alone functions.
    Here I would like to know, is there any other way to use the functions which are defined in package. While I am trying to use those functions (which are defined in package -- giving the name as packagename.functionname) it is throwing an error "Invalid object name."
    Here I would like know, is there any other way to use the table functions which are defined in a package.
    Thank you,
    Regards,
    Gowtham Sen.

  • Doubt in  export, import and table para when creating Function Module

    Dear fellow ABAPers,
    I have a doubt in defining export, import and table parameter while creating a function module.
    I am calling a function module inside a user exit. Now in the user exit the SAP fills an internal table called i_lfa1 with all the data user has eneterd.
    Now I want to pass this whole internal table to function module and the perform some checks on the values of internal table.
    After that function module fills an error structure with values depending on some check.
    1)
    How do I pass this internal table to function module ? 
    When I am creating function module in se37 where do I define this iternal table type ? Is it in Import or Table parameter during function module creation?
    2)
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Please clear my doubt..
    Relevant points will be awarded.
    Regards,
    Tushar.

    Hi Tushar,
    1. How do I pass this internal table to function module ?
       I assume u are creating your own Y/Z FM.
       Pass it thru TABLES parameter.
    2. When I am creating function module in se37 where do I define this iternal table type
       Define this in TABLES interface.
       What Type ?
       THE SAME TYPE WHICH HAS BEEN DEFINED
        WHILE PASSING IN THE USER-EXIT FUNCTION MODULE.
       IF U SEE THE FM OF THE USER-EXIT,
       U WILL COME TO KNOW.
    3.
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Define it in TABLES interace. (not in export, import)
      (Since what u are going to return is an internal table)
      U can take for eg. BDCMSGCOLL.
      OR u can create your own Y/Z structure
    for the same purpose.
      (or u can use the structure type T100)
    I hope it helps.
    Regards,
    Amit M.

  • What is the difference between the function declared in the package and pac

    What is the difference between defining a function in the package and package body ?
    Edited by: user10641405 on Nov 19, 2009 1:29 PM

    If you describe a package, you will only see the functions declared in the spec.
    If you only declare them in the body then they are not available to other packages (they are private to the package, not public)

  • Find all Package and their related Procedure Names using a specifc Table

    I have 25 Packages
    Each Package holds 30-35 Procedures
    I need to find out all Packages and Procedures
    Each Procedure handles 5 - 20 Tables as Per The Need of Business Rule.
    I need All Package and Related Procedure Names Where a Specific Table Name Appears(DBA_SOURCE doesn't serve purpose.)
    Early Reply Appreciated.
    Thanks and Regards,

    I tried the solution provided to me, but unfortunately the issue remains the same.
    I was Advised to Execute the SQL utldtree.Sql, and then Execute deptree_fill.
    The output is given by a Table DEPTREE (Columns are: .'NESTED_LEVEL', 'TYPE', 'SCHEMA', 'NAME' and 'SEQ#')
    The output I am getting From the Table DEPTREE is as follows -
    Column TYPE value is PACKAGE; Column NAME Value is ACTUAL PACKAGE NAME
    Column TYPE value is PACKAGE BODY; Column NAME Value is ACTUAL PACKAGE NAME
    This repeats till the count the TABLE Name is found in the same PACKAGE
    Desired Output should be -
    Column TYPE value PACKAGE; Column NAME Value ACTUAL PACKAGE NAME
    Column TYPE value PACKAGE BODY; Column NAME Value ACTUAL PACKAGE BODY NAME
    This should repeat till the count the TABLE Name appears in different PACKAGE BODY of the same PACKAGE
    Warm Regards,

  • How to find function module's and tables used for the particulat screen or TCODE?

    Hello Nation,
    I would like to know how to find the  function modules and tables used for the particular screen or TCODE or program.
    Example : I would like know the function module used in the program RDBGFT?
                     How can i find that?
    Thanks in advance ,Awaiting your reply.

    Make use of Find function  with the keyword "CALL FUNCTION".
    Make use of the same find function with the keyword "Select" to know the database tables used.
    Regards,
    Philip.

Maybe you are looking for

  • Mail quits every time i try to open it

    i am a new mac user, i just signed up to the .mac service, everytime i now try to open mail, it quits before i can do anything, this happens if i try to open it directly or indirectly (for example when i want to send a note to people to invite them t

  • Programmatically generated hyperlinks in PDF now have boxes around them (v. 10.1.4)

    Hi I wonder if anyone has encountered this problem which only appeared in version 10.1.4 of both the Reader and Acrobat and if so, have you found a solution/workaround? Hyperlinks that are generated programmatically now have visible borders around th

  • Error while loading period dimension in planning through DIM

    Hi, I am trying to load the metadata extracted from DRM into Period dimension in Hyperion Planning through Informatica using DIM. But I am getting the following error: Record [[YearTotal, Period, Total Year, Dynamic Calc, 0, null, null, null, null, U

  • How to "select" with case ignored???

    Hi everyone, I need to select a field from table, but the data might be written in low case or upper case, even mixed case. for example, i want to select "test" or "TEST" or "Test" in column, what should I modify in my sql "select column1 from tableA

  • HELP WEBDB/Oracle 8i/LINUX!!

    Hello, I've managed to get past the pass.sys bug on webdb installation. Webdb is now giving me this error. wwv20.vrf(119): READ_ERROR while translating tablesp from /usr/local/oracle/webdb/orainst/tablespaces.lst. ; /usr/local/oracle/webdb is where i