Constructor of nested table subtype

The following code gives me an error PLS-00355: use of pl/sql table not allowed in this context (I checked in 11.2.0.2.0):
DECLARE
  TYPE    t_number_tab     IS TABLE OF NUMBER;
  SUBTYPE t_number_tab_sub IS t_number_tab;
  v_sub t_number_tab_sub;
BEGIN
  -- throws "PLS-00355: use of pl/sql table not allowed in this context":
  v_sub := t_number_tab_sub();
END;I looked in docs and can't find a reason why this doesn't work. I know I can initialize v_sub with t_number_tab(), but I would like to know why my example above doesn't work.

Welcome to the forum!
Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION)
>
The following code gives me an error PLS-00355: use of pl/sql table not allowed in this context (I checked in 11.2.0.2.0):
DECLARE
  TYPE    t_number_tab     IS TABLE OF NUMBER;
  SUBTYPE t_number_tab_sub IS t_number_tab;
  v_sub t_number_tab_sub;
BEGIN
  -- throws "PLS-00355: use of pl/sql table not allowed in this context":
  v_sub := t_number_tab_sub();
END;I looked in docs and can't find a reason why this doesn't work. I know I can initialize v_sub with t_number_tab(), but I would like to know why my example above doesn't work.
>
You haven't really defined a subtype; just a different name for the type.
Subtypes have to be based on scalar types. See the PL/SQL Language doc
http://docs.oracle.com/cd/E11882_01/appdev.112/e10472/datatypes.htm#CHDEAFDJ
>
PL/SQL lets you define your own subtypes. The base type can be any scalar PL/SQL type, including a previously defined user-defined subtype.
>
Even though the compiler seems to allow it you have the equivalent of an 'unconstrained' subtype which is just another name for the type
>
Unconstrained Subtypes
An unconstrained subtype has the same set of values as its base type, so it is only another name for the base type.
>
Since all you have changed is the name you still have to use the constructor for the actual type: t_number_tab()

Similar Messages

  • Oracle object, nested table on a subtype

    Hello,
    Is it possible to have a nested table on a subtype? If it is, can someone help me?
    Here is what I need help for:
    I have a supertype WORK, that have:
    multivalued attribute ADDRESS
    a attribute NAME, also the primary key
    The subtype is called EMPLOYEE, that have:
    multivalued attribute SPECIALTY
    a attribute NAME
    a attribute SSN
    So far have I got:
    //* The supertype *//
    create or replace type ADRESS_TP as object(
    ADRESS varchar2(50));
    create or replace type ADRESSTP as table of ADRESS_TP;
    create or replace WORK_TP as object(
    NAME varchar2(30),
    ADRESS ADRESSTP)
    NOT FINAL;
    create table WORK_TBL of WORK_TP(
    Primary key(NAME))
    nested table ADRESS store as NT_ADR(
    (Primary key(nested_table_id, ADRESS))
    organization index compress);
    //* The subtype *//
    create or replace type SPECIALTY_TP as object(
    ADRESS varchar2(50));
    create or replace type SPECIALTYTP as table of SPECIALTY_TP;
    create or replace EMPLOYEE_TP under work_tp(
    NAME varchar2(30),
    SSN number)
    FINAL;
    The multivalued attribute SPECIALTYTP has to be declared in WORK_TBL have I been told, but how can I do that?
    I'm using oracle 9i

    I'm not really sure what your problem is. In future please be specific about what it is you are trying to do and what it is that is not working. If it's an error please give us the error message and number. It's not the behaviour you are expecting please describe what it does. If it's that you simply don't understand please say what you don't understand.
    I go on like this because the code you have posted is somewhat confusing. The Oracle object-oriented implementation is not quite complete so that makes it hard for people who know OO but don't know Oracle. Whereas most of us who know Oracle aren't expert in OO. Also, I think you should be slightly more inventive in your names: there's so many things called ADRESS it's easy to get them tangled up.
    Anyway, here's my guess at what I think your problem is....
    SQL> CREATE OR REPLACE TYPE adress_t AS OBJECT(
      2  line1 VARCHAR2(50)
      3  ,line2 VARCHAR2(50)
      4  ,postcode VARCHAR2(8));
      5  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE TYPE adress_nt AS TABLE OF adress_t;
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE work_t AS OBJECT(
      2   name VARCHAR2(30),
      3   adresses adress_nt)
      4  NOT FINAL;
      5  /
    Type created.
    SQL> CREATE TABLE work_tbl OF work_t
      2     NESTED TABLE adresses STORE AS adress_ntab
      3  /
    Table created.
    SQL> CREATE OR REPLACE TYPE specialty_t AS OBJECT(
      2  description VARCHAR2(50));
      3  /
    Type created.
    SQL> CREATE OR REPLACE TYPE specialty_nt AS TABLE OF specialty_t;
      2  /
    Type created.
    SQL>
    SQL> ALTER TYPE work_t ADD ATTRIBUTE specialities specialty_nt CASCADE
      2  /
    Type altered.
    SQL> DESC work_tbl
    Name                                      Null?    Type
    NAME                                               VARCHAR2(30)
    ADRESSES                                           ADRESS_NT
    SPECIALITIES                                       SPECIALTY_NT
    SQL> Cheers, APC

  • Returning a nested table in a constructor function

    Hi there is it possible to return a nested table in a Constructor Function or do I need to create a package?
    I have this package spec it gives me an error
    create or replace type
    INTERFACE.PDE_BKRF_NTB
    as table of
    PDE_BKRF_TYP,
    -- Define a constructor for REF_TYP_CD and REF_KEY to return a list.
    constructor function
    PDE_BKRF_TYP
    (P_REF_TYP_CD varchar2
    ,P_REF_KEY number
    ,P_EXTR_DT date)
    return SELF as result
    /

    No, a NESTED TABLE type can't have a constructor I think.
    Check the documentation:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_8001.htm#i2121881
    It distinguishes between object type, varray type and nested table type. Only object types can have constructors.
    As a workaround you could create another object type that has an attribute of your nested table type:
    Note: untested code
    create or replace type
    INTERFACE.PDE_BKRF_NTB
    as table of
    PDE_BKRF_TYP;
    create or replace type INTERFACE.PDE_BKRF_NTB_2
    as object (
    a INTERFACE.PDE_BKRF_NTB,
    constructor function
    PDE_BKRF_NTB_2
    (P_REF_TYP_CD varchar2
    ,P_REF_KEY number
    ,P_EXTR_DT date)
    return SELF as result)
    create or replace type body INTERFACE.PDE_BKRF_NTB_2
    as
    constructor function
    PDE_BKRF_NTB_2
    (P_REF_TYP_CD varchar2
    ,P_REF_KEY number
    ,P_EXTR_DT date)
    return SELF as result as
    /Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Nested table in a subtype

    Hi,
    A question: Is it possible to have a nested table on a subtype?
    If yes : How to declare the storage table for the nested table.
    I will be really grateful for any help here.
    Nina

    Is it what you need ?
    SQL> create or replace type nt_type is table of number;
      2  /
    Type created.
    SQL> create or replace type nt_obj is object (id number, ntt nt_type);
      2  /
    Type created.
    SQL> create table t (id number, ntobj nt_obj)
      2  nested table ntobj.ntt store as nest_tab;
    Table created.Rgds.

  • How to insert into a table with a nested table which refer to another table

    Hello everybody,
    As the title of this thread might not be very understandable, I'm going to explain it :
    In a context of a library, I have an object table about Book, and an object table about Subscriber.
    In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
    And finally, this nested table refers to the Book table.
    Here the code concerning the creation of theses tables :
    Book :
    create or replace type TBook as object
    number int,
    title varchar2(50)
    Loan :
    create or replace type TLoan as object
    book ref TBook,
    loaning_date date
    create or replace type NTLoan as table of TLoan;
    Subscriber :
    create or replace type TSubscriber as object
    sub_id int,
    name varchar2(25)
    loans NTLoan
    Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
    insert into OSubscriber values
    *(1, 'LEVEQUE', NTLoan(*
    select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
    Of course, there is an occurrence of book in the table OBook with the number attribute 1.
    Oracle returned me this error :
    SQL error : ORA-00936: missing expression
    00936. 00000 - "missing expression"
    Thank you for your help

    1) NUMBER is a reserved word - you can't use it as identifier:
    SQL> create or replace type TBook as object
      2  (
      3  number int,
      4  title varchar2(50)
      5  );
      6  /
    Warning: Type created with compilation errors.
    SQL> show err
    Errors for TYPE TBOOK:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    3/1      PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
    SQL> create table OSubscriber of TSubscriber
      2  nested table loans store as loans
      3  /
    Table created.
    SQL> create table OBook of TBook
      2  /
    Table created.
    SQL> insert
      2    into OBook
      3    values(
      4           1,
      5           'No Title'
      6          )
      7  /
    1 row created.
    SQL> commit
      2  /
    Commit complete.
    SQL> insert into OSubscriber
      2    values(
      3           1,
      4           'LEVEQUE',
      5           NTLoan(
      6                  (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
      7                 )
      8          )
      9  /
    1 row created.
    SQL> select  *
      2    from  OSubscriber
      3  /
        SUB_ID NAME
    LOANS(BOOK, LOANING_DATE)
             1 LEVEQUE
    NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
    SQL> SY.

  • Data pump import error with nested tables

    So the problem is somewhat long :)
    Actually the problems are two - why and how oracle are treating OO concept and why data pump doesn't work?
    So scenario for the 1st one:
    1) there is object type h1 and table of h1
    2) there is unrelated object type row_text and table of row_text
    3) there is object type h2 under h1 with attribute as table of row_text
    4) there is table tab1 with column b with data type as table of h1. Of course column b is stored as nested table.
    So how do you think - how many nested tables Oracle will create? The correct answer is 2. One explicitly defined and one hidden with system
    generated name for the type h2 which is under type h1. So the question is WHY? Why if I create an instance of supertype Oracle tries to adapt
    it for the subtype as well? Even more if I create another subtype h3 under h1 another hidden nested table appears.
    This was the first part.
    The second part is - if I do schema export and try to import it in another schema I got error saying that oracle failed to create storage table for
    nested table column b. So the second question is - if Oracle has created such a mess with hidden nested tables how to import/export to another
    schema?
    Ok and here is test case to demonstrate problems above:
    -- creating type h1 and table of it
    SQL> create or replace type h1 as object (a number)
      2  not final;
      3  /
    Type created.
    SQL> create or replace type tbl_h1 as table of h1;
      2  /
    Type created.
    -- creating type row_text and table of it
    SQL> create or replace type row_text as object (
      2    txt varchar2(100))
      3  not final;
      4  /
    Type created.
    SQL> create or replace type tbl_row_text as table of row_text;
      2  /
    Type created.
    -- creating type h2 as subtype of h1
    SQL> create or replace type h2 under h1 (some_texts tbl_row_text);
      2  /
    Type created.
    SQL> create table tab1 (a number, b tbl_h1)
      2  nested table b
      3  store as tab1_nested;
    Table created.
    -- so we have 2 nested tables now
    SQL> select table_name, parent_table_name, parent_table_column
      2  from user_nested_tables;
    TABLE_NAME                     PARENT_TABLE_NAME
    PARENT_TABLE_COLUMN
    SYSNTfsl/+pzu3+jgQAB/AQB27g==  TAB1_NESTED
    TREAT(SYS_NC_ROWINFO$ AS "GINTS"."H2")."SOME_TEXTS"
    TAB1_NESTED                    TAB1
    B
    -- another subtype of t1
    SQL> create or replace type h3 under h1 (some_texts tbl_row_text);
      2  /
    Type created.
    -- plus another nested table
    SQL> select table_name, parent_table_name, parent_table_column
      2  from user_nested_tables;
    TABLE_NAME                     PARENT_TABLE_NAME
    PARENT_TABLE_COLUMN
    SYSNTfsl/+pzu3+jgQAB/AQB27g==  TAB1_NESTED
    TREAT(SYS_NC_ROWINFO$ AS "GINTS"."H2")."SOME_TEXTS"
    SYSNTfsl/+pz03+jgQAB/AQB27g==  TAB1_NESTED
    TREAT(SYS_NC_ROWINFO$ AS "GINTS"."H3")."SOME_TEXTS"
    TAB1_NESTED                    TAB1
    B
    SQL> desc "SYSNTfsl/+pzu3+jgQAB/AQB27g=="
    Name                                      Null?    Type
    TXT                                                VARCHAR2(100)OK let it be and now I'm trying to export and import in another schema:
    [oracle@xxx]$ expdp gints/xxx@xxx directory=xxx dumpfile=gints.dmp logfile=gints.log
    Export: Release 11.2.0.1.0 - Production on Thu Feb 4 22:32:48 2010
    <irrelevant rows skipped>
    Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    . . exported "GINTS"."TAB1"                                  0 KB       0 rows
    . . exported "GINTS"."SYSNTfsl/+pz03+jgQAB/AQB27g=="         0 KB       0 rows
    . . exported "GINTS"."TAB1_NESTED"                           0 KB       0 rows
    . . exported "GINTS"."SYSNTfsl/+pzu3+jgQAB/AQB27g=="         0 KB       0 rows
    Master table "GINTS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
    ******************************************************************************And now import. In order to create types transformation of OIDs is applied and also remap_schema
    Although it fails to create the table.
    [oracle@xxx]$ impdp gints1/xxx@xxx directory=xxx dumpfile=gints.dmp logfile=gints_imp.log remap_schema=gints:gints1 transform=OID:n
    Import: Release 11.2.0.1.0 - Production on Thu Feb 4 22:41:48 2010
    Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
    Connected to: Oracle Database 11g Release 11.2.0.1.0 - Production
    Master table "GINTS1"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
    Starting "GINTS1"."SYS_IMPORT_FULL_01":  gints1/********@xxx directory=xxx dumpfile=gints.dmp logfile=gints_imp.log remap_schema=gints:gints1 transform=OID:n
    Processing object type SCHEMA_EXPORT/USER
    ORA-31684: Object type USER:"GINTS1" already exists
    Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
    Processing object type SCHEMA_EXPORT/ROLE_GRANT
    Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
    Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
    Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    ORA-39083: Object type TABLE:"GINTS1"."TAB1" failed to create with error:
    ORA-02320: failure in creating storage table for nested table column B
    ORA-00904: : invalid identifier
    Failing sql is:
    CREATE TABLE "GINTS1"."TAB1" ("A" NUMBER, "B" "GINTS1"."TBL_H1" ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    ORA-39083: Object type INDEX_STATISTICS failed to create with error:
    ORA-01403: no data found
    ORA-01403: no data found
    Failing sql is:
    DECLARE I_N VARCHAR2(60);   I_O VARCHAR2(60);   c DBMS_METADATA.T_VAR_COLL;   df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS'; BEGIN  DELETE FROM "SYS"."IMPDP_STATS";   c(1) :=   DBMS_METADATA.GET_STAT_COLNAME('GINTS1','TAB1_NESTED',NULL,'TREAT(SYS_NC_ROWINFO$ AS "GINTS"."H2")."SOME_TEXTS"',1);  DBMS_METADATA.GET_STAT_INDNAME('GINTS1','TAB1_NESTED',c,1,i_o,i_n);   INSERT INTO "
    ORA-39083: Object type INDEX_STATISTICS failed to create with error:
    ORA-01403: no data found
    ORA-01403: no data found
    Failing sql is:
    DECLARE I_N VARCHAR2(60);   I_O VARCHAR2(60);   c DBMS_METADATA.T_VAR_COLL;   df varchar2(21) := 'YYYY-MM-DD:HH24:MI:SS'; BEGIN  DELETE FROM "SYS"."IMPDP_STATS";   c(1) :=   DBMS_METADATA.GET_STAT_COLNAME('GINTS1','TAB1_NESTED',NULL,'TREAT(SYS_NC_ROWINFO$ AS "GINTS"."H3")."SOME_TEXTS"',1);  DBMS_METADATA.GET_STAT_INDNAME('GINTS1','TAB1_NESTED',c,1,i_o,i_n);   INSERT INTO "
    Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    Job "GINTS1"."SYS_IMPORT_FULL_01" completed with 4 error(s) at 22:41:52So any idea how to make export/import of such tables?
    TIA
    Gints

    Tom Kyte has said it repeatedly ... I will repeat it here for you.
    The fact that Oracle allows you to build object tables is not an indication that you should.
    Store your data relationally and build object_views on top of them.
    http://www.morganslibrary.org/reference/object_views.html
    If you model properly, and store properly, you don' have any issues.

  • Why on earth use nested tables?

    Hi
    I'm boning up on PL/SQL (again) in anticipation of getting a new job.
    I have many years of experience in various data-related roles, many of which used Oracle.
    On the issue of collections, I find myself asking, in the light of my experience, and not for the first time, why on earth would anyone want to do this:
    create or replace type TEST_TT as table of varchar2(10);
    create table TEST_TABLE ( X number
                             ,Y test_tt)
                             nested table Y store as Y_TABLE;                      I really, really, can't think why we would want to store data like this. It seems to me to be unnecessarily complex, hiding a one-to-many relationship inside TEST_TABLE, which should instead be modelled and implemented as a separate table.
    Furthermore, there are loads of tutorials on collections that tell us how to do the above (indeed I am reading Feuerstein at this very time) but nobody seems to say WHY we should do this.
    Can anybody help me here?
    Thanks.
    Jason

    >
    I'm boning up on PL/SQL (again) in anticipation of getting a new job.
    I have many years of experience in various data-related roles, many of which used Oracle.
    On the issue of collections, I find myself asking, in the light of my experience, and not for the first time, why on earth would anyone want to do this:
    I really, really, can't think why we would want to store data like this. It seems to me to be unnecessarily complex, hiding a one-to-many relationship inside TEST_TABLE, which should instead be modelled and implemented as a separate table.
    Furthermore, there are loads of tutorials on collections that tell us how to do the above (indeed I am reading Feuerstein at this very time) but nobody seems to say WHY we should do this.
    >
    For As you have surmised, just because you CAN do it doesn't mean you SHOULD do it. If you are only working with your standard relational data, such as the example you provide, it has many drawbacks and few, if any advantages.
    It is easier to understand why that capability exists from the viewpoint of the question: why SHOULDN'T you be able to store data like that?
    In one sense it is just another object-oriented feature. You can create object types and pass them around to procedure/functions or external processes (e.g. JDBC) so why shouldn't you be able to store that set of related data as an encapsulated object?
    Why do you need an object type that has a set of columns? You can just as easily put those columns into a table. But how do you manipulate a subset of the columns or rows of a table? How do you pass that data around as a controlled, coherant set of data? You can't.
    With an object type you can, though most often don't, implement encapsulated business rules that ensure that any instance of that type MUST implement. Need ADDRESS information that is required to include a street address, city, state and zip? Create an object type with the right constructor methods and you can ensure that those attributes CANNOT be null.
    Once you have functionality to create and manipulate objects why not be able to pass those objects around and stored them in a table? Doesn't mean you should always store them that way but why not be able to? There isn't any reason to limit that functionality simply because you don't think it is the best practice to use it all the time.
    So if you have a small dataset and want all of that data to 'travel' together nest it. There is no child table to create or foreign key to create.
    I put that functionality in the category of CAN DO but DON'T DO except in rare occasions and consider it a fallout of the move to object-oriented things in general. I like the fact that Oracle makes functionilty like that available when they have it.
    Like dynamic sql, materializeds views, bitmap indexes and much other functionality it is often more important to know when NOT to use it than it is to know when to use it.
    Relative to 'best practices' of why NOT to do that for your basic relational data see this part of the article that Justin referred you to:
    >
    Followup March 3, 2003 - 6am Central time zone:
    1) they are parent child tables in disguise but ones that add:
    a 16 byte raw with a unique constraint on the parent table. Most likely you ALREADY HAVE a primary
    key on the parent table and most likely it is smaller.
    a 16 byte raw that you need to index on the child (not auto-indexed, you need to know to do it).
    This is the foreign key and is hidden from you.
    The inability to put many types of constraints on the nested table..
    They are simple parent/child tables - except you lose the ability to access the child table
    directly.
    2) you are NOT storing anything in a "single row". Physically they are a parent child table pair,
    nothing more, nothing less
    If you have my book "Expert one on one Oracle" - I write about them in there, describe their
    implementation and talk about when I would use them.

  • How to cast RECORD of nested tables into OBJECT of nested tables

    Right, we have an existing massive pl/sql package where some of the processing is taking too long so they want to try multithreading it.
    The data in this package is stored in an array of records which contains nested tables, which themselves contain nested tables.
    So, we want to split this table into 10, and submit them to 10 dbms_jobs to run concurrently, write the modified arrays to the database so they can be picked up again by the original process.
    I'm stuck on converting the associative array of data (containing tables of records) into objects which can be stored in the DB.
    My database objects:
    CREATE OR REPLACE
    TYPE ktest_claims_rt IS OBJECT
         col1 varchar2(10)
        ,col2 varchar2(10));
    CREATE OR REPLACE
      TYPE ktest_claims_tt IS TABLE OF ktest_claims_rt;
    CREATE OR REPLACE
    TYPE ktest_driver_rt IS OBJECT
         col1      varchar2(10)
        ,col2      varchar2(10)
        ,claims_nt ktest_claims_tt);
    CREATE OR REPLACE
      TYPE ktest_driver_tt IS TABLE OF ktest_driver_rt;
    CREATE OR REPLACE
    TYPE ktest_policy_rt IS OBJECT
         col1       varchar2(10)
        ,col2       varchar2(10)
        ,driver_nt  ktest_driver_tt);
    CREATE OR REPLACE
      TYPE ktest_policy_tt IS TABLE OF ktest_policy_rt;
    CREATE TABLE ktest_job_table
      (job_no        NUMBER
      ,tab_type      VARCHAR2(3)
      ,policy_nt     ktest_policy_tt
      NESTED TABLE policy_nt STORE AS policy_nested_tab
        (NESTED TABLE driver_nt STORE AS driver_nested_tab
           (NESTED TABLE claims_nt STORE AS claims_nested_tab))
    / And my local package versions:
       TYPE claims_rt IS RECORD
         col1 varchar2(10)
        ,col2 varchar2(10));
       TYPE claims_tt IS TABLE OF claims_rt INDEX BY PLS_INTEGER;
       TYPE driver_rt IS RECORD
         col1       varchar2(10)
        ,col2       varchar2(10)
        ,claims_nt  claims_tt);
       TYPE driver_tt IS TABLE OF driver_rt INDEX BY VARCHAR2(20);
       TYPE policy_rt IS RECORD
            policy_no   policy.policy_no%TYPE
           ,driver_tab  driver_tt
           ,other_col   VARCHAR2(20));
       TYPE policy_tt IS TABLE OF policy_rt
            INDEX BY pls_integer;
       main_table  policy_tt;What I can't get through my pea sized brain is how to turn "main_table" into an array based on ktest_policy_tt.
    I got as far as:
       FUNCTION convert (p_table IN policy_tt) RETURN ktest_policy_tt
       IS
          db_vers  ktest_policy_tt := ktest_policy_tt();
          db_rec   ktest_policy_rt;
       BEGIN
          FOR i IN p_table.FIRST..p_table.LAST
          LOOP
             db_rec := ktest_policy_rt(p_table(i).policy_no
                                      ,p_table(i).other_col
                                      ,ktest_driver_tt(p_table(i).driver_tab(i).col1
                                                      ,p_table(i).driver_tab(i).col2
                                                      ,ktest_claims_tt(p_table(i).driver_tab(i).claims_nt(i).col1
                                                                      ,p_table(i).driver_tab(i).claims_nt(i).col1
             db_vers(i) := db_rec;
          END LOOP;
       END;but, apart from the fact that it only coverts the first row of each table, it doesn't compile:
    LINE/COL ERROR
    139/10   PL/SQL: Statement ignored
    143/52   PLS-00306: wrong number or types of arguments in call to
             'KTEST_CLAIMS_TT'
    143/52   PLS-00306: wrong number or types of arguments in call to
             'KTEST_CLAIMS_TT'I'd appreciate any help as this is getting urgent.
    Thanks!

    I would recommend writing your function in a more stepwise, explicit fashion rather than trying to write the conversion as basically one big constructor.
    Firstly, you will require nested loops in your pl/sql code for the different levels of nested tables. This is not a choice, you need to do this.
    Within each level of looping, explicitly create the object of the desired type before adding it to the table / record as need be.
    cheers,
    Anthony

  • NESTED Tables for Sub-types when creating table for Super-type

    If I create the following types, as an example:
    Person with subtypes: Employee and Customer
    Appointment
    CREATE OR REPLACE TYPE Person_OT AS OBJECT (
    person#                         NUMBER,
    personSurname                    VARCHAR2(50),
    personForenames               VARCHAR2(50),
    personDateOfBirth               DATE,
    personAddress                    Address_OT,
    ) NOT FINAL ;
    CREATE OR REPLACE TYPE Employee UNDER Person_OT (
    empSalary               NUMBER,
    empNoSales          NUMBER,
    makes               Appointment_List_OT
    ) FINAL ;
    CREATE OR REPLACE TYPE Appointment_OT AS OBJECT (
    some attributes
    CREATE OR REPLACE TYPE Appointment_List_OT AS TABLE OF REF Appointment_OT ;
    When creating the table to hold objects of Person type, how can the requisite nested table for representing 'makes' be declared? The below approach is not correct, however the table will not compile without naming the nested tables.
    CREATE TABLE Person_TBL OF Person_OT (
    Person#     PRIMARY KEY)
    NESTED TABLE makes STORE AS Appointment_List_NTBL;
    Advice very much appreciated!

    CREATE TABLE Person_TBL OF Person_OT(
    Person# PRIMARY KEY)
    NESTED TABLE TREAT(SYS_NC_ROWINFO$ AS EMPLOYEE).MAKES STORE AS Appointment_List_NTBL
    Table created.
    SQL> select * from user_nested_tables
      2  /
    TABLE_NAME                     TABLE_TYPE_OWNER
    TABLE_TYPE_NAME                PARENT_TABLE_NAME
    PARENT_TABLE_COLUMN
    STORAGE_SPEC                   RETURN_TYPE          ELEMENT_SUBSTITUTABLE
    APPOINTMENT_LIST_NTBL          SCOTT
    APPOINTMENT_LIST_OT            PERSON_TBL
    TREAT(SYS_NC_ROWINFO$ AS "SCOTT"."EMPLOYEE")."MAKES"
                           DEFAULT                VALUE                         N
    SQL>  SY.

  • UserDefined Type Question - Nested Table Attribute

    I have a question about some types I'm trying to create and whether or not it's even possible .....
    Here's the background ...
    I have the following type i created :
    create type asset_stat (
    stat_current varchar2(50),
    stat_change_date date,
    stat_change_user varchar2(30)
    All this type does is simply put a user and date/time stamp when constructed. I want to track status changes for historical tracking.
    Then I want to create a nested table type of the above type as follows:
    create type asset_stat_nt as table of asset_stat
    Then, I have another type i've created which will have the nested table type created above as an attribute.
    create type asset (
    asset_name varchar2(30),
    asset_type varchar2(3),
    asset_stat asset_stat_nt
    Now, the constructor for this asset type is defined like this: ( this is where i get lost)
    constructor function asset (
    asset_nm IN varchar2,
    asset_type_cd in varchar2,
    asset_stat_cd in varchar2 ) return self as result is
    begin
    self.asset_nm := asset_nm
    self.asset_type := asset_type_cd ;
    self.asset_stat := asset_stat_nt(asset_stat_cd);
    return;
    end;
    I just created a table of asset type and tried to do an insert and I'm getting an error related to the line where the nested type is being assigned. Is this possible? If so is my syntax completely off? I'm not quite sure how to set values for the nested type because i want to keep all records of change. Any help would be greatly appreciated.
    thanks

    the block of code shows that asset_stat_nt is the type assigned to asset_stat inside the type asset as shown below
    create type asset (
    asset_name varchar2(30),
    asset_type varchar2(3),
    asset_stat asset_stat_nt
    I guess for the following block of code, the line with the arrows should be given like shown below in bold letters
    constructor function asset (
    asset_nm IN varchar2,
    asset_type_cd in varchar2,
    asset_stat_cd in varchar2 ) return self as result is
    begin
    self.asset_nm := asset_nm
    self.asset_type := asset_type_cd ;
    self.asset_stat := asset_stat_nt(asset_stat_cd);return;
    end;
    [b][b]self.asset_stat := asset(asset_stat_nt(asset_stat_cd));
    I am not pretty sure.......try it anyway.....if it works....good to you

  • Please help with multiple insert query into nested table!!!!

    I am having a problem with inserting multiple references to objects into a nested table using the following query:
    INSERT INTO TABLE(SELECT Taken_by FROM courses WHERE course_number= 001)
    (SELECT REF(p) FROM persons p
    WHERE p.enroled_in = 'Computing for Business'
    The database says that p.enroled_in is an invalid identifier. I know why this is. This is because the field enroled_in is part of a subtype of person called student_type and the query above is not accounting for this properly. I would like to know the correct syntax to use so I can insert into the nested table wherever a student is enroled into the 'computing for business' course. My full schema is below:
    CREATE TYPE person_type;
    CREATE TYPE student_type;
    CREATE TYPE staff_type;
    CREATE TYPE course_type;
    CREATE TYPE module_type;
    CREATE TYPE address_type AS OBJECT
    Street VARCHAR2 (30),
    Town     VARCHAR2 (30),
    County VARCHAR2 (30),
    Postcode VARCHAR2 (9)
    CREATE TYPE person_type AS OBJECT
    Name VARCHAR2 (50),
    Address address_type,
    DOB     DATE
    ) NOT FINAL;
    CREATE TYPE staff_type UNDER person_type
    Staff_number NUMBER (2,0)
    ) FINAL;
    CREATE TYPE student_type UNDER person_type (
    Student_number NUMBER (2,0),
    Enroled_in VARCHAR2(50),
    MEMBER FUNCTION getAge RETURN NUMBER
    )NOT FINAL;
    CREATE OR REPLACE TYPE BODY student_type AS
    MEMBER FUNCTION getAge RETURN NUMBER AS
    BEGIN
    RETURN Trunc(Months_Between(Sysdate, DOB)/12);
    END getAge;
    END;
    CREATE TYPE module_type AS OBJECT
    Module_number VARCHAR2(6),
    Module_name VARCHAR2(50),
    Credit NUMBER(2,0),
    Taught_in VARCHAR2(50)
    CREATE TYPE students_tab AS TABLE OF REF person_type;
    CREATE TYPE modules_tab AS TABLE OF REF module_type;
    CREATE TYPE course_type AS OBJECT
    Course_number NUMBER (2,0),
    Course_name VARCHAR2(50),
    Dept_name VARCHAR2(50),
    Taken_by Students_tab,
    Contains Modules_tab
    CREATE TABLE modules OF module_type(
    constraint pk_modules primary key (Module_number)
    CREATE TABLE courses OF course_type(
    constraint pk_courses primary key (Course_number)
    NESTED TABLE Taken_by STORE AS students_nt,
    NESTED TABLE Contains STORE AS modules_nt;

    By the way I am using oracle 9i and trying to insert into the nested table data from a subtype (i.e student is a subtype of person)

  • PL/SQL insert nested table value into another nested table.

    Hi Guy
    I've created a table with nested table in and inserted some values. note: this is just an example the real table has more values inserted.
    REATE OR REPLACE TYPE tt_hours AS OBJECT(hours INTEGER, data NUMBER);
    CREATE OR REPLACE TYPE tt_day AS VARRAY(7) OF tt_hours;
    CREATE TABLE old_table
    DAY DATE,
    VALUE_hours tt_day
    INSERT INTO old_table
    (day, value_hours)
    VALUES
    (TO_DATE('01/06/2012 22:00:34'),
    tt_DAY(
    tt_hours(1,0.025727),
    tt_hours(2,0.012047),
    tt_hours(3,0.012857),
    tt_hours(4,0.012107),
    tt_hours(5,0.012849),
    tt_hours(6,0.01215),
    tt_hours(7,0.0129)))
    I've also created another table with same structure but with no value inserted.
    REATE OR REPLACE TYPE yy_hours AS OBJECT(thours INTEGER, tdata NUMBER);
    CREATE OR REPLACE TYPE yy_day AS VARRAY(7) OF yy_hours;
    CREATE TABLE new_table ( tDAY DATE, VALUE_thours yy_day )
    I run a select from statement which workout the average of data from old table by group.
    SELECT to_char(DAY, 'Day'), hours, AVG(data)
    FROM old_table n, TABLE(n.value_hours) v
    GROUP BY to_char(DAY, 'Day'), hours;
    How do I insert the result in new_table's ?

    I believe I said
    >
    You basically need to construct the INSERT statement just like you did manually for the first table.
    >
    and instead you used
    INSERT INTO new_table a (tday, t.hours, t.DATA) TABLE(a.value_thours) t This is what you did manually for the first table. Do you see TABLE (...) in here anywhere?
    INSERT INTO old_table
    (day, value_hours)
    VALUES
    (TO_DATE('01/06/2012 22:00:34'),
    tt_DAY(
    tt_hours(1,0.025727),
    tt_hours(2,0.012047),
    tt_hours(3,0.012857),
    tt_hours(4,0.012107),
    tt_hours(5,0.012849),
    tt_hours(6,0.01215),
    tt_hours(7,0.0129)))NO YOU DON'T - you used a tt_DAY constructor for the outer nested table and multiple tt_hours constructors for the inner nested table.
    You need to do the same thing in your INSERT query.

  • Collection -- Nested tables

    Hi,
    I am trying to use collections as nested tables from below mentioned procedure, but facing a problem of getting only last rows.
    Any help would be appreciated.
    +CREATE OR REPLACE PROCEDURE pr_collection
    AS
    TYPE type_num IS TABLE OF NUMBER;
    t_num type_num;
    TYPE type_char IS TABLE OF VARCHAR2 (20);
    t_char type_char;
    BEGIN
    FOR i IN (SELECT eid, nm
    FROM emp)
    LOOP
    t_num := type_num (i.eid);
    t_char := type_char (i.nm);
    DBMS_OUTPUT.put_line (i.eid || i.nm);
    END LOOP;
    DBMS_OUTPUT.put_line (t_num.COUNT);
    DBMS_OUTPUT.put_line (t_num.FIRST);
    DBMS_OUTPUT.put_line (t_num.LAST);
    FORALL J IN T_NUM.FIRST.. T_NUM.LAST
    INSERT INTO TEST
    VALUES (t_num (J), t_char (J));
    COMMIT;
    END;
    /+
    Output :
    1
    1
    1
    Thanks in Advance,
    Prashant

    Hi,
    It's normal, you get only the last element because of the following
    LOOP
        t_num := type_num (i.eid);
        t_char := type_char (i.nm);
    END LOOP;Each time you call the nested table constructor with the new element, so the previous elements are lost. The correct way of doing this is to call once the constructor before the LOOP and then call the EXTEND method inside the loop in order to make room available for each new element.
    Therefore, something like this:
    CREATE OR REPLACE PROCEDURE pr_collection AS
        TYPE type_num IS TABLE OF NUMBER;
        t_num type_num;
        t_num_idx PLS_INTEGER := 1;
        TYPE type_char IS TABLE OF VARCHAR2 (20);
        t_char type_char;
        t_char_idx PLS_INTEGER := 1;
    BEGIN
        t_char := type_char();
        t_num := type_num();
        FOR i IN (SELECT eid, nm FROM emp) LOOP
            t_num.EXTEND;
            t_num(t_num_idx) := i.eid;
            t_num_idx := t_num_idx + 1;
            t_char.EXTEND;
            t_char(t_char_idx) := i.nm;
            t_char_idx := t_char_idx + 1;
            DBMS_OUTPUT.put_line (i.eid || i.nm);
        END LOOP;
        DBMS_OUTPUT.put_line (t_num.COUNT);
        DBMS_OUTPUT.put_line (t_num.FIRST);
        DBMS_OUTPUT.put_line (t_num.LAST);
        FORALL J IN T_NUM.FIRST.. T_NUM.LAST
            INSERT INTO TEST VALUES (t_num (J), t_char (J));
        COMMIT;
    END;That being said, why do you add elements one by one, it is slow, why not using BULK COLLECT?
    Regards,
    Dariyoosh

  • Initializing Nested Table

    I declared a nested table based on a record type. How do I initialize it using a constructor ?
    For e.g. ,
    Declare
    Type Rec Is Record(num Number, chr Char(10)) ;
    Type Tab Is Table Of Rec ;
    Tab1 Tab := Tab??

    I want Tab1(1).num = 1 and Tab1(1).chr = 'A'..how can this be done through the constructor?
    If you want to do this with PL/SQL assignment then you don't want a table of RECORDs. That's for SELECT statements. Try this:
    CREATE OR REPLACE TYPE my_rec IS OBJECT (num number, chr VARCHAR2(1));
    DECLARE
      TYPE tab IS TABLE OF my_rec;
      tab1 tab;
    BEGIN
      tab1 := tab();
      tab1.extend;
      tab1(1)  := my_rec(1, 'A');
    END;
    /Cheers, APC

  • Problem in creation of Nested Table

    Hi Everyone,
    I have applied thisexample for creating nested tables but at the end I got the message of invalid datatype
    current_address full_mailing_address_type,
    ERROR at line 4:
    ORA-00902: invalid datatype
    http://www.praetoriate.com/oracle_tips_nested_tables.htm
    Please help me out.....
    Message was edited by:
    Dharmendra

    What is the output for
    select * from user_types
    ?

Maybe you are looking for

  • How to transfer an xml file to NW Portal Knowledge Management from XI?

    Hi all, Anybody knows how to transfer an xml file to NW Portal Knowledge Management from XI? What kind of adapter type I have to choose? And which procedures I have to do in KM Portal? Create a folder, what kind of folder and permissions? Suggestions

  • Open cursor for a nested table

    Hi, I want to open a cursor like: open c1 for select * from emp; BUT I what the cursor results to be populated with contents of a nested table or associative array.. How can this be done??? Thanks in advance, teo

  • Best way to upgrade to ff4 rc?

    Hi there, Just realised the way I upgraded may not have been optimal. I made a back-up of my original profile... Then I turfed the app bundle from /applications & dropped the new ff4 app bundle in it's place. I removed the old shortcut from the dock,

  • IMovie seems to be confused

    I am not an expert, having only made about six movies ever and all of those with iMovie 09. All of a sudden,iMovie seems confused. If I click the buttons to go to photos or iTunes, none of them work. Also in the top left of the program the Project Li

  • Image won't open in Elements 10 from "Photo/Edit In" in LR4

    I hope someone can help.  I recently got a new BIG MAC, and have been loading my software. The external editing preference to Elements 10 from Lightroom 4 will open Photoshop Elements, but will not open the image... I've reinstalled elements, reinsta