ORA-22905 - when querying a table type with a select statement

后端 未结 2 953
粉色の甜心
粉色の甜心 2020-12-01 12:51
 DECLARE
 TYPE record_AB IS RECORD
   (
      AA              VARCHAR2 (16 BYTE),
      BB    VARCHAR2 (16 BYTE)
   );

  TYPE type_tab_AB IS TABLE OF record_AB
             


        
2条回答
  •  [愿得一人]
    2020-12-01 13:42

    You cannot query a type created inside a pl/sql block. You need to create it at sql prompt and then you can query it. See exmaple below :

    scott@ORA92> CREATE OR REPLACE TYPE emp_type AS OBJECT
      2    (id   NUMBER,
      3     name VARCHAR2(20));
      4  /
    
    Type created.
    
    scott@ORA92> CREATE OR REPLACE TYPE emp_tab AS TABLE OF emp_type;
      2  /
    
    Type created.
    
    scott@ORA92> VARIABLE g_ref REFCURSOR
    scott@ORA92> DECLARE
      2    employees emp_tab := emp_tab();
      3  BEGIN
      4    employees.EXTEND(2);
      5    employees(1) := emp_type (1, 'name1');
      6    employees(2) := emp_type (2, 'name2');
      7    OPEN :g_ref FOR
      8    SELECT * FROM TABLE (CAST (employees AS emp_tab));
      9  END;
     10  /
    

提交回复
热议问题