Oracle error ORA-22905: cannot access rows from a non-nested table item

后端 未结 5 920
忘了有多久
忘了有多久 2020-12-11 16:35

here\'s the stored procedure i wrote.In this proc \"p_subjectid\" is an array of numbers passed from the front end.

PROCEDURE getsubjects(p_subjectid subject         


        
5条回答
  •  天命终不由人
    2020-12-11 17:26

    Oracle has two execution scopes: SQL and PL/SQL. When you use a SELECT/INSERT/UPDATE (etc) statement you are working in the SQL scope and, in Oracle 11g and below, you cannot reference types that are defined in the PL/SQL scope. (Note: Oracle 12 changed this so you can reference PL/SQL types.)

    TYPE subjectid_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    

    Is an associative array and can only be defined in the PL/SQL scope so cannot be used in SQL statements.

    What you want is to define a collection (not an associative array) in the SQL scope using:

    CREATE TYPE subjectid_tab IS TABLE OF NUMBER;
    

    (Note: you do not need the INDEX BY clause for a collection.)

    Then you can do:

    OPEN p_subjects FOR
      SELECT *
      FROM   empsubject
      WHERE  subject_id MEMBER OF p_subjectid;
    

    or

    OPEN p_subjects FOR
      SELECT *
      FROM   empsubject
      WHERE  subject_id IN ( SELECT COLUMN_VALUE FROM TABLE( p_subjectid ) );
    

提交回复
热议问题