ORA-01427 during casting of nested table table column

Hello

Now select all the elements in a nested table column, on several lines. The following query gives me an ora-01427 einreihig subquery returns more than one line.

SELECT * FROM TABLE (SELECT nt_col FROM tab);

Is it possible to achieve this easily?

Best regards, Jan

Jan Leers wrote:
Hello

Now select all the elements in a nested table column, on several lines. The following query gives me an ora-01427 einreihig subquery returns more than one line.

SELECT * FROM TABLE (SELECT nt_col FROM tab);

Is the name of the column in the nested table nt_col in the table tab? If so, all you need is:

SELECT column_value FROM tab,TABLE(nt_col)
/
SQL> desc ref_tbl
 Name                                                                     Null?    Type
 ------------------------------------------------------------------------ -------- ------------------------------
 I                                                                                 NUMBER
 R                                                                                 OBJ_REF_TBL_TYPE

SQL> select * from ref_tbl
  2  /

         I
----------
R
-----------------------------------------------------------------------------------------------------------------
         1
OBJ_REF_TBL_TYPE(0000220208A51D704FB8804FFCA39802FC5148A4FDB7ED17723522492CB81A875DB4E4B1C6)

         2
OBJ_REF_TBL_TYPE(0000220208A51D704FB8804FFCA39802FC5148A4FDB7ED17723522492CB81A875DB4E4B1C6)

SQL> select column_value from ref_tbl,table(r)
  2  /

COLUMN_VALUE
-----------------------------------------------------------------------------------------------------------------
0000220208A51D704FB8804FFCA39802FC5148A4FDB7ED17723522492CB81A875DB4E4B1C6
0000220208A51D704FB8804FFCA39802FC5148A4FDB7ED17723522492CB81A875DB4E4B1C6

SQL> 

SY.

Tags: Database

Similar Questions

  • How can I change my nested table column?

    Hi all

    For example.

    Create Table MyTab
    (
    Number of Srno,
    SName varchar2 (100),
    Addr varchar2 (100)
    );

    This is my original table, but now I want to change my address of column in a nested table that having several columns in it.


    create or replace type AddrTyp as an object
    (
    LINE1 varchar2 (50).
    Line2 varchar2 (50).
    VARCHAR2 (50) line 3.
    4 varchar2 (50).
    line5 varchar2 (50).
    postadd varchar2 (10)
    );


    CREATE OR REPLACE
    TYPE DelAddr IS TABLE of the AddrTyp;


    It comes up ok but now I want to change my addr nested table column.

    as...


    ALTER table MyTab
    change the waterfall (DelAddr Addr);

    but it did not work.

    any idea?

    Indirectly!

    SQL> alter table MyTab add addr2 DelAddr NESTED TABLE addr2 STORE AS addr2_ntab;
    
    Table altered.
    
    SQL> alter table MyTab drop column addr;
    
    Table altered.
    SQL> alter table MyTab rename column addr2 to addr;
    
    Table altered.
    
    SQL> desc MyTab
     Name                                      Null?    Type
     ----------------------------------------- -------- -----------------
     SRNO                                               NUMBER
     SNAME                                              VARCHAR2(100)
     ADDR                                               DELADDR
    
    SQL>  
    
  • ORA-01427 during the attempt to INSERT SQL job

    Hello

    I have non-logiques problem.

    I use Oracle 10 g.
    I have a query that contains some subqueries, this is pretty normal query as similar milion:

    SELECT a.field1,
    (SELECT b.field2 FROM tab2 b WHERE b.key = a.key) Field2
    OF tab1 a

    Query works fine, amount of the returns expected Recordset, but while I'm saving it somehow it returns me an error:
    ORA - 01427:single - line subquery returns multiple rows

    It would be normal that I have by running a SELECT statement. But SOME major work - error occurs when I try to save the results somehow - INSERT, CREATE TABLE AS or save it to file.

    Help, please.
    Thank you.

    nodeX wrote:

    Query works fine, amount of the returns expected Recordset, but while I'm saving it somehow it returns me an error:
    ORA - 01427:single - line subquery returns multiple rows

    No it's not. Most likely you use SQL * Developer, Toad, SQL * Navigator or another GUI tool that retrieves the screen by screen lines. So when you run this select your tool retrieves and displays just the first screen and it happens so that for the first lines of the scalar subquery in your select screen returns just one line. However, when you issue INSERT SELECT all lines are read, and at least one of them, results in a scalar subquery returns more than one line. Do a complete test of your question, SELECT, SELECT your tool try and extract all lines (in most of the tools it's > button) or post your query in SQL * more. In all cases:

    SELECT a.field1,
    (SELECT b.field2 FROM tab2 b WHERE b.key = a.key) field2
    FROM tab1 a
    

    means the key of the column in the table tab2 is logically unique for any value of tab1.key.

    SY.

  • ERROR "ora-01422" during insertion in the table?

    Hello

    I have created the dynamic action of PL/SQL to insert data but founded by page_item

    
    
     declare 
    x_found_pages number;
    x_auth_id number;
    x_user_id number;
     begin
     x_user_id := :P41_USR_ID; -- this is my page_item _____ successful run When change it to number value .. !
    
    
    
    
          select count(V_APP_PAGES.PAGE_ID) into x_found_pages
          from V_AUTH_DTL V_AUTH_DTL,V_APP_PAGES V_APP_PAGES 
          where V_AUTH_DTL.PAGE_ID!=V_APP_PAGES.PAGE_ID
          and  V_AUTH_DTL.USR_ID = x_user_id;
       
          select T_AUTH.ID into x_auth_id 
          from T_AUTH_DTL T_AUTH_DTL,T_AUTH T_AUTH 
          where T_AUTH_DTL.AUTH_ID=T_AUTH.ID
          and T_AUTH.USR_ID = x_user_id;
    
    
    -- Checking...? 
      if x_found_pages > 0 then
    
            for i in (select V_APP_PAGES.PAGE_ID
               from V_AUTH_DTL V_AUTH_DTL,V_APP_PAGES V_APP_PAGES 
               where V_AUTH_DTL.PAGE_ID!=V_APP_PAGES.PAGE_ID
               and  V_AUTH_DTL.USR_ID = x_user_id)
        
      loop
      insert into T_AUTH_DTL (AUTH_ID,PAGE_ID) values (x_auth_id,i.PAGE_ID);
      end loop;
    
        end if;
    
     end;
    
    
    
    

    Please help me to avoid the ERROR "ora-01422" when running code in the dynamic action...

    Thank you...

    AMR Abdeen wrote:

    I have created the dynamic action of PL/SQL to insert data but founded by page_item

    1. declare
    2. number of x_found_pages;
    3. number of x_auth_id;
    4. number of x_user_id;
    5. Start
    6. x_user_id: =: P41_USR_ID; -It is my page_item _ successfully performed when change to value the number...!
    7. SELECT count (V_APP_PAGES. Page_id) in x_found_pages
    8. of V_AUTH_DTL V_AUTH_DTL, V_APP_PAGES V_APP_PAGES
    9. where V_AUTH_DTL. PAGE_ID! = V_APP_PAGES. PAGE_ID
    10. and V_AUTH_DTL. USR_ID = x_user_id;
    11. Select T_AUTH.ID from x_auth_id
    12. of T_AUTH_DTL T_AUTH_DTL, T_AUTH T_AUTH
    13. where T_AUTH_DTL. AUTH_ID = T_AUTH.ID
    14. and T_AUTH. USR_ID = x_user_id;
    15. -Checking...?
    16. If x_found_pages > 0 then
    17. I'm in (select V_APP_PAGES. PAGE_ID
    18. of V_AUTH_DTL V_AUTH_DTL, V_APP_PAGES V_APP_PAGES
    19. where V_AUTH_DTL. PAGE_ID! = V_APP_PAGES. PAGE_ID
    20. and V_AUTH_DTL. USR_ID = x_user_id)
    21. loop
    22. insert into T_AUTH_DTL (AUTH_ID, PAGE_ID) values (x_auth_id, i.PAGE_ID);
    23. end loop;
    24. end if;
    25. end;

    Please help me to avoid the ERROR "ora-01422" when running code in the dynamic action...

    The error is explicit:

    ORA-01422: exact fetch returns more than number of lines

    Cause: The exact extraction specified number is less than the rows returned.

    Action: Rewrite the query or change the number of rows requested

    This would imply the query in line 16 as County dissociated in the previous one will always return only one row.

    Run

    select T_AUTH.ID into x_auth_id
    from T_AUTH_DTL T_AUTH_DTL,T_AUTH T_AUTH
    where T_AUTH_DTL.AUTH_ID=T_AUTH.ID
    and T_AUTH.USR_ID = :x_user_id
    

    in the workshop of SQL by using the P41_USR_ID value in the variable link to find out how many rows it returns.

    It is likely that the entire block can be replaced by a single INSERT statement. If you provide instructions CREATE TABLE, INSERT statements to create sample data and a clear definition of the requirements that we try to do.

    What is the point of the inclusion of tables aliases that are exactly the same as the names of the tables?

  • ORA-00904 when you select a nested table column

    Hello

    I use a table with the following description:

    SQL > desc muenzen
    Name Null? Typ
    ------------------------------- -------- ----------------------------

    1 MUENZ_ID NOT NULL NUMBER
    2 MUENZ_TEXT NOT NULL VARCHAR2 (200 CHAR)
    3 MUENZ_BESCHREIBUNG CLOB
    MUENZ_BILD 4 MUENZ_BILDER_TAB
    MUENZ_BILDER ist NO FINAL
    5 4 NUMMER NUMBER
    6 4 BILD BLOB

    METHOD
    ------
    MEMBER FUNCTION BILD_SUCHEN RETURNS THE BLOB
    Argument name Typ/output Defaultwert?
    ------------------------------ ----------------------- ------ --------
    NUMMER NUMBER IN
    BILD BLOB IN
    7 MUENZ_ERSTELLER NOT NULL VARCHAR2 (30 CHAR)
    8 MUENZ_ERSTELL_DATUM NOT NULL DATE
    9 MUENZ_AENDERER VARCHAR2 (30 CHAR)
    DATE OF MUENZ_AEND_DATUM 10

    I use the folling SELECT statement: select muenz_id, muenz_text, MUENZE. MUENZ_BILDER_TAB (MUENZE. MUENZ_BILDER. Nummer) of muenzen; and got the error:

    ORA-00904: "MUENZE. "" "" MUENZ_BILDER '. "" NUMMER": ungultiger Bezeichner

    00904, 00000 - '% s: invalid identifier '.

    * Cause:

    * Action:

    What ist the right identifier?

    Please help me

    Concerning

    Siegwin

    Hello siegwin.port

    I corrected the tablenames.

  • Error ORA-01843 during the update of table

    I have the following query, which gives a month error invalid ORA-01843

    Update tpsir_response set response_date = to_date (' 04/02/2014 ',' dd/mm/yyyy') where product_line = 'PRODUCT' and to_date(vl_creation_date,'dd/mm/yyyy') < 13 May 2008 ' and responder is NULL;

    In the tpsir_response table

    response_date is a kind of date

    vl_creation_date is of type char (10)

    someone at - it an idea what I did wrong

    Hello

    Try to change on May 13, 2008 ' to to_date ('2008-05-13', ' dd/mm/yyyy')

    Or

    Check this box

    Select * from nls_session_parameters where parameter = "NLS_DATE_FORMAT;

    and together

    ALTER session set nls_date_format = "dd/mm/yyyy";

    Good luck...

  • Helps the nested Table

    Hi all

    I have a task to insert data in a nested table. First, I'll explain the scenario.

    I have 2 table (of patients) and (tumors) that contain medical data on patients with cancer.
    CREATE TABLE "DSS2_MINING"."PATIENTS" 
       (     "PATIENT_ID" VARCHAR2(10 BYTE) NOT NULL ENABLE, 
         "REGISTRY_ID" NUMBER(10,0), 
         "RACE" VARCHAR2(2 BYTE), 
         "SEX" VARCHAR2(1 BYTE), 
         "BIRTHDATE_YEAR" NUMBER(4,0), 
         "NUMBER_OF_PRIMARIES" NUMBER(1,0), 
         "VITAL_STATUS_RECORD" VARCHAR2(1 BYTE), 
         "CAUSE_OF_DEATH" VARCHAR2(5 BYTE), 
         "SURVIVAL_TIME" VARCHAR2(4 BYTE), 
         "SURVIVAL_TIME_FINAL" NUMBER, 
         "SURVIVAL_VARIABLE" VARCHAR2(1 BYTE), 
          CONSTRAINT "PATIENTS_PK" PRIMARY KEY ("PATIENT_ID");
    
    
    
    CREATE TABLE "DSS2_MINING"."TUMORS" 
       (     "TUMOR_ID" NUMBER NOT NULL ENABLE, 
         "PATIENT_ID" VARCHAR2(10 BYTE),   -- FK
         "SEER_RECORD_NUMBER" NUMBER,       -- This column contain a sequance number of the records for each patients
         "MARITAL_STATUS" VARCHAR2(1 BYTE), 
         "AGE" NUMBER, 
         "DATE_OF_DIAGNOSIS" DATE, 
         "HISTOLOGY_GROUP" VARCHAR2(2 BYTE), 
         "BEHAVIOR" VARCHAR2(1 BYTE), 
         "GRADE" VARCHAR2(1 BYTE), 
         "DERIVED_AJCC_STAGE_GROUP" VARCHAR2(2 BYTE), 
         "STAGE_OF_CANCER" VARCHAR2(2 BYTE), 
         "RADIATION" VARCHAR2(1 BYTE), 
         "CS_SCHEMA" VARCHAR2(2 BYTE), 
         "FIRST_PRIMARY_IND" VARCHAR2(1 BYTE), 
         "TUMOR_SIZE" NUMBER(4,1), 
         "TUMOR_EXTENSION" VARCHAR2(2 BYTE), 
         "LYMPH_NODES" VARCHAR2(1 BYTE), 
         "NODES_POSITIVE" NUMBER, 
         "ESTROGEN" VARCHAR2(3 BYTE), 
         "PROGESTERONE" VARCHAR2(3 BYTE), 
         "SURGERY" VARCHAR2(2 BYTE), 
          CONSTRAINT "TUMORS_PK" PRIMARY KEY ("TUMOR_ID");
    The table (of patients) contain the basic information about patients. The table (tumors) contain information about the tumors. each record in the table (the patients) may have one or more records in the table (tumors) using the column (patient_id). I want to transfer data from (of patients) and (tumors) tables to a new table (cancer_patients) that contains a nested table column. so I did the following code
    create or replace type tumor_object AS
    object(
    tumor_id VARCHAR2(1),   
    marital_status VARCHAR2(1),   
    age NUMBER(3),   
    date_of_diagnosis DATE,  
    cs_schema VARCHAR2(2),   
    histology_group VARCHAR2(2),   
    behavior VARCHAR2(1),   
    grade VARCHAR2(1),   
    first_primary_ind VARCHAR2(1),   
    tumor_size NUMBER(4,   1),   
    tumor_extension VARCHAR2(2),   
    lymph_nodes VARCHAR2(1),   
    nodes_positive NUMBER(4),   
    surgery VARCHAR2(2),
    radiation VARCHAR2(1)
    );
    
    
    create or replace type tumor_table as table of tumor_object;
    
    
      CREATE TABLE "DSS2_MINING"."CANCER_PATIENTS" 
       (     "PATIENT_ID" VARCHAR2(10 BYTE) NOT NULL ENABLE, 
         "RACE" VARCHAR2(2 BYTE), 
         "SEX" VARCHAR2(1 BYTE), 
         "NUMBER_OF_PRIMARIES" NUMBER(1,0), 
         "TUMORS" "DSS2_MINING"."TUMOR_TABLE" , 
         "VITAL_STATUS_RECORD" VARCHAR2(1 BYTE), 
         "CAUSE_OF_DEATH" VARCHAR2(5 BYTE), 
         "SURVIVAL_TIME_FINAL" NUMBER, 
         "SURVIVAL_VARIABLE" VARCHAR2(1 BYTE), 
          CONSTRAINT "CANCER_PATIENTS_PK" PRIMARY KEY ("PATIENT_ID")
       NESTED TABLE "TUMORS" STORE AS "TUMORS_STOR_TABLE"
     
    So my problem on the transfer and inserts data, I tried to use the associative array to keep the rows in the table of tumors, but it didn't work. I think that the main problem is that each record in the patient table have multiple records in the table of tumors.

    I hope that if anyone can help in this case or I you know any reference on similar cases

    Thank you
    A.L

    Published by: user9003901 on November 26, 2010 02:48

    Something like:

    INSERT
      INTO CANCER_PATIENTS
      SELECT  PATIENT_ID,
              RACE,
              SEX,
              NUMBER_OF_PRIMARIES,
              (
               SELECT  CAST(
                            COLLECT(
                                    TUMOR_OBJECT(
                                                 TUMOR_ID,
                                                 MARITAL_STATUS,
                                                 AGE,
                                                 DATE_OF_DIAGNOSIS,
                                                 CS_SCHEMA,
                                                 HISTOLOGY_GROUP,
                                                 BEHAVIOR,
                                                 GRADE,
                                                 FIRST_PRIMARY_IND,
                                                 TUMOR_SIZE,
                                                 TUMOR_EXTENSION,
                                                 LYMPH_NODES,
                                                 NODES_POSITIVE,
                                                 SURGERY ,
                                                 RADIATION
                                                )
                                   )
                            AS TUMOR_TABLE
                           )
                 FROM  "TUMORS" T
                 WHERE T.PATIENT_ID = P.PATIENT_ID
              ),
              VITAL_STATUS_RECORD,
              CAUSE_OF_DEATH,
              SURVIVAL_TIME_FINAL,
              SURVIVAL_VARIABLE
        FROM  PATIENTS P
    /
    

    SY.
    P.S. This site has censorship. It replaces the word S E X with *, change it if during the test.

  • Assistance in creation of objects Table nested in a column

    Hi all

    In our project requirement, we are supposed to create a table1 consisting of such object1 of the column and Object1 has a nested object (object2) as one of the column.

    We are able to create the table (table-name is op_sam) for object1

    create or replace type testobj1 as an object (number of c1, c2 number);
    create or replace type t_testobj in the testobj1 table;

    create table op_sam (obj_id varchar2 (100), workobj t_testobj)
    store workobj table nested as nested_tab back as a value;

    We strive to store op_sam as an object in an another table prepop

    We have created the object for the op_sam

    create or replace type op_sam_obj as an object (obj_id varchar2 (100), workobj t_testobj);
    create or replace type t_op_sam_obj in the op_sam_obj table;



    We gave the following script to create the table with the column as t_op_sam_obj

    create table prepop (ob_id varchar2 (20), t_op_sam_obj object2)
    nested table object2 store like nested_tab1 back as a value;


    ORA-22913: must specify the name of the table for the nested table column or attribute · nested tables ·

    could you please suggest me to fix this?

    Hello

    Each object of type table needs a nested table.
    Subject: object2 has a nested table object: workobj
    Then, who also has a nested table clause.

    CREATE
         TABLE prepop
         (
              ob_id VARCHAR2(20)
         , object2 t_op_sam_obj
         )
         nested TABLE object2 store AS nested_tab1
         (
              nested TABLE workobj store AS nested_tab2
         )
            return as value
    ;
    

    This will create 3 tables:
    nested_tab2 as an embedded table
    nested_tab1 as an embedded table
    prepop

    Kind regards

    Peter

  • casting with NVARCHAR2 table collection

    Hello world

    I have defined some SQL types at the schema level and use them in the stored procedure, in particular, I need to some casting of this type to the table collection.
    However, it seems to be a problem if the SQL type contains fields of type NVARCHAR2. Example is quite simple:

    Select min (INNER_CODE) in the TABLE test_quality (CAST (highest_quality_table AS highest_quality_table_type));

    In the case of the concerned type (highest_quality_table_type) contains NVARCHAR2, I get ORA-12714 (invalid national character the specified value).
    However, if the type does not NVARCHAR2 (for example numbers only) - contain it compiles successfully.

    Any advice would be appreciated.

    You might knock Bug 6029647 ORA-12714 access to typed function TABLE() column:

    This problem is fixed in:
    Patch 7 10.2.0.3 on Windows platforms
    10.2.0.4 (Server Patch Set)
    11.1.0.7 (Server Patch Set)
    11.2 (next version)

  • Nested table

    When you create a table nested within a table, can I please have a description of what the STORE AS medium of instruction?

    Here is an example:

    NESTED TABLE, STORE LineItemList_ntab AS PoLine_ntab

    I have had a look in the documentation, but cannot find the answer to this question.

    Published by: 996403 on May 7, 2013 22:50

    Sound the segment of nested table name, 11 g, you can also have SECUREFICHIERS as for example you can thus encrypt, oracle doc said The Oracle database server stores data for the nested table offline from the lines of the parent table, using a table of store that is associated with the nested table column. The parent row contains a value to set unique identifier associated with a nested table instance. See http://docs.oracle.com/cd/B28359_01/server.111/b28318/schema.htm#CHDFDBGH

    Published by: Karan on May 8, 2013 11:38

  • How the nested table that is stored in the database?

    How the nested table that is stored in the database?
    The nested table column is stored with the table main or separate in the database?

    A nested table is a table that is stored in the structure of another table. It is used to support the columns that contain multivalued attributes.

    If you want to use the same type in multiple places, create them on a global scale and these will be discussed under 'Types'.

  • Columns of the nested Table and ADF BC 11.1.2

    I think coming to a new conception of the application, including a redesign of the database. In this application, there are users who cannot change tables of production directly, but their amendments must be approved (and possibly modified) before applying them to production tables. The production tables are part of an existing system and are fairly well standardized, with a main table and several paintings of detail.

    So for the new design, I want to have a table intermediate, mirrored in the main table, where the user's changes are stored until they are approved and applied to the production tables. The intermediate table contains some additional columns for the user "add, change or delete", who supported the change, the date modified is requested. After you apply the change, the intermediate folder must be copied in a historic change and deleted from the staging table. In this way, the intermediate table is never a lot of data in it.

    Here's the question:
    I need to treat the tables in detail. I could have staged versions of each table in detail, but I thought it might be easier to manage if detail tables have been included in table nested table columns main staging area. Most of the detail tables contain only a few rows with rank of master. But ADF BC 11.1.2 can treat the nested table columns? Is it easy to use in an application?

    Hello

    and ADF Faces does support nested tables? lol so even if ADF BC would be, where would you go with this approach? Polymorphic views would be an option (think hard)?

    Frank

  • Trigger on the nested table - possible without sight?

    I have a table my_table that has a nested table column, DOC. I need a trigger that fires whenever a row in the nested table is deleted.

    I had initially hoped that a status UPDATE on my_table trigger would do the trick, but it doesn't. Then I created a trigger on the nested table.

    I can make it work if I create a table view and then make the trigger through this:

    "INSTEAD OF DELETE
    ON the TABLE IMBRIQUEE my_view DOC
    '

    and then to do the removal through the view:

    deletion OF TABLE
    (Doc SELECT FROM my_view where rowid = 1111);

    HOWEVER, I need this to work when the delete statement is directly through the table itself and not through the view. The delete statement is generated by an application that I can't control. I can only make changes to the database.

    deletion OF TABLE
    (Doc SELECT FROM my_table where rowid = 1111);

    Create the trigger on the nested table.

    create or replace type result_obj as object(subject varchar2(100), mark integer)
    /
    create or replace type result_tbl as table of result_obj
    /
    create table student(sno integer, sname varchar2(100), result result_tbl) nested table result store as result_tbl_tbl
    /
    insert into student values(10, 'Karthick', result_tbl(result_obj('English',85),result_obj('Hindi',70)))
    /
    insert into student values(20, 'Vimal', result_tbl(result_obj('English',75),result_obj('Hindi',90)))
    /
    select s.sno, s.sname,r.subject, r.mark
      from student s,
           table(s.result) r
    /
    create or replace trigger Result_Trigger before delete on result_tbl_tbl for each row
    begin
        raise_application_error(-20001,'You cannot delete this subject');
    end;
    /
    delete
      from
     table(select s.result
             from student s
            where s.sno = 10)
     where subject = 'Hindi'
    /
    
  • ORA-22907: invalid CAST to a type that is not a nested table or VARRAY. Typed collection function

    Hello

    I tried to create a function that might return the type that is created on the outside.

    So I wrote script below. until the function created it compiled successfully, but after that, when the data querying, we encountered error,

    "ORA-22907: invalid CAST to a type that is not a nested table or VARRAY.

    SQL> create table emp
      2  (
      3    ename        varchar2(200 byte),
      4    mgr          number,
      5    employee_id  number
      6  );
    
    
    Table created.
    
    
    SQL> insert into emp (ename, mgr, employee_id)
      2       values ('king', 12, 1);
    
    
    1 row created.
    
    
    SQL> insert into emp (ename, mgr, employee_id)
      2       values ('clark', 12, 2);
    
    
    1 row created.
    
    
    SQL> commit;
    
    
    Commit complete.
    
    
    SQL> create or replace type t_emp as object (ename varchar2 (200), mgr number, employee_id number);
      2  /
    
    
    Type created.
    
    
    SQL> create or replace function f_emp return  t_emp
      2   is
      3  type rc_emp is ref cursor;
      4  r_emp rc_emp;
      5  v_emp t_emp;
      6  begin
      7   open r_emp for select * from emp where rownum=1;
      8   fetch r_emp into v_emp;
      9  close r_emp;
     10  return v_emp;
     11  exception
     12      when others then
     13      dbms_output.put_line(dbms_utility.format_error_stack);
     14      dbms_output.put_line(dbms_utility.format_call_stack);
     15      dbms_output.put_line(dbms_utility.format_error_backtrace);
     16      raise_application_error(-20001,sqlerrm);
     17  end;
     18  /
    
    
    Function created.
    
    
    SQL> show errors;
    No errors.
    SQL> select * from f_emp;
    select * from f_emp
                  *
    ERROR at line 1:
    ORA-04044: procedure, function, package, or type is not allowed here
    
    
    
    
    SQL> select * from table(cast (f_emp as t_emp));
    select * from table(cast (f_emp as t_emp))
                              *
    ERROR at line 1:
    ORA-22907: invalid CAST to a type that is not a nested table or VARRAY
    
    
    
    
    SQL>
    

    Like this:

    ...

    CREATE or REPLACE TYPE t_emp_array IS TABLE OF THE t_emp;

    /

    FUNCTION to CREATE or REPLACE f_emp RETURN t_emp_array

    is

    type rc_emp is ref cursor;

    r_emp rc_emp;

    v_emp_array t_emp_array: = t_emp_array();

    BEGIN

    R_emp OPEN for SELECT t_emp(ename,mgr,employee_id) FROM emp WHERE ROWNUM = 1;

    collect the fetch r_emp in bulk in v_emp_array;

    CLOSE R_emp;

    Return v_emp_array;

    exception

    while others then

    dbms_output.put_line (dbms_utility.format_error_stack);

    dbms_output.put_line (dbms_utility.format_call_stack);

    dbms_output.put_line (dbms_utility.format_error_backtrace);

    raise_application_error (-20001, SQLERRM);

    end;

    /

    SELECT *.

    table (f_emp ());

    a table function works with a table (nested table or varray)

    HTH

  • ORA-21700: object does not exist or is marked for deletion - nested table

    Hi, please see my procedure. It comes to delete records in a table whose primary keys will be given in comma separated format.

    but he triggers the following error

    ORA-21700: object does not exist or is marked for deletion
    ORA-06512: at the 'scott '. PKG_COUNTRY', line 4598
    ORA-06512: at line 10
    Pr_Del_Regional_DtlORA-21700: object does not exist or is marked for deletion
    Process is complete.
    Disconnection from the database tfo_user-watson.


    / * In format on 12/05/2011 14:47 (trainer more v4.8.7) * /.



    Varchar_table. ARRAY TYPE IS VARCHAR2 (5); -in the scope of package


    PROCEDURE Pr_Del_Regional_Dtl)
    pi_v_country_id IN VARCHAR2, seperateed comma for deletion
    po_results ON sys_refcursor
    )
    IS
    l_varchar_table varchar_table: = varchar_table ();
    BEGIN
    pr_split_varchar_values (pi_v_country_id, l_varchar_table); -divides: separation by a comma to the nested table.

    DELETE FROM regional_setup
    WHERE country_id IN (SELECT *)
    TABLE (l_varchar_table)); -removed
    EXCEPTION
    WHILE OTHERS
    THEN
    DBMS_OUTPUT. Put_line ("Pr_Del_Regional_Dtl" |) SQLERRM);
    LIFT;
    END Pr_Del_Regional_Dtl;

    split-
    PROCEDURE pr_split_varchar_values)
    pi_v_values IN VARCHAR2,
    op_varchar_table ON varchar_table
    )
    IS
    l_v_value VARCHAR2 (3000);
    l_value VARCHAR2 (10);
    I PLS_INTEGER: = 0;
    BEGIN
    op_varchar_table: = varchar_table ();
    l_v_value: = pi_v_values;

    IN all, LENGTH (l_v_value) > 0
    LOOP
    i: = i + 1;

    IF INSTR (l_v_value, ",") > 0
    THEN
    op_varchar_table. EXTEND;
    op_varchar_table (i): =.
    LTRIM (RTRIM (SUBSTR (l_v_value, 0, INSTR (l_v_value, ",") - 1)));
    ON THE OTHER
    op_varchar_table. EXTEND;
    op_varchar_table (i): = LTRIM (RTRIM (l_v_value));
    l_v_value: = ";
    END IF;

    l_v_value: =.
    SUBSTR (l_v_value, INSTR (l_v_value, ",") + 1,
    LENGTH (l_v_value));
    END LOOP;
    END pr_split_varchar_values;

    Thanks in advance
    TYPE varchar_table IS TABLE OF VARCHAR2(5); -- in package scope
    

    Have you declared in package or database? Remember, local collection cannot be used in the SQL statement.

Maybe you are looking for