Oracle嵌套表和列名

时间:2009-12-07 18:03:33

标签: oracle plsql oracle10g

我想在Oracle 10g中执行以下操作(这是一个用来显示概念而不是真实代码的人为例子)

    create table orders (order_id NUMBER);
    insert into table orders values (1);
    insert into table orders values (2);
    insert into table orders values (3);


TYPE NUMBER_ARRAY_T is TABLE of NUMBER;

PROCEDURE VALIDATE_ORDER_IDS(i_orders IN NUMBER_ARRAY_T, o_output OUT SYS_REFCURSOR)    
IS    
BEGIN
    OPEN o_output FOR
        select ??? from TABLE(i_orders) where ??? NOT IN (select order_id from orders);
END VALIDATE_ORDER_IDS;

将使用包含(1,2)的数组调用存储过程,因此我们期望得到3回复

所以,问题是,无论如何都要指定一个列名,其中???当使用嵌套表作为表时,上面的select语句会起作用吗?

1 个答案:

答案 0 :(得分:4)

您要查找的关键字是column_value。根据您的设置:

SQL> CREATE OR REPLACE TYPE NUMBER_ARRAY_T is TABLE of NUMBER;
  2  /

Type created
SQL> CREATE OR REPLACE PROCEDURE validate_order_ids(i_orders IN number_array_t,
  2                                                 o_output OUT SYS_REFCURSOR)
  3  IS BEGIN
  4      OPEN o_output FOR
  5          SELECT COLUMN_VALUE
  6            FROM TABLE(i_orders)
  7           WHERE COLUMN_VALUE NOT IN (SELECT order_id FROM orders);
  8  END validate_order_ids;
  9  /

Procedure created

要调用该程序,您只需:

SQL> VARIABLE x REFCURSOR
SQL> exec validate_order_ids(number_array_t(1,5), :x);

ProcÚdure PL/SQL terminÚe avec succÞs.

SQL> print x

COLUMN_VALUE
------------
           5