1

是否可以从批量集合中进行选择?

这些方面的东西:

DECLARE
  CURSOR customer_cur IS
    SELECT CustomerId,
          CustomerName
    FROM   Customers
    WHERE  CustomerAreaCode = '576';

  TYPE customer_table IS TABLE OF customer_cur%ROWTYPE;
  my_customers  customer_table; 
BEGIN

  OPEN customer_cur;

  FETCH customer_cur
  BULK COLLECT INTO my_customers;

  -- This is what I would like to do
  SELECT CustomerName
    FROM my_customers
   WHERE CustomerId IN (1, 2, 3); 

END;

我似乎无法从the my_customers表中进行选择。

4

2 回答 2

3

是的你可以。声明自己的架构级别类型,如下所示:

create or replace rec_customer_cur
as
object (
    customerid       integer, -- change to the actual type of customers.customerid
    customername     varchar2(100) -- change to the actual type of customers.customername
);
/

create or replace type customer_table
as
table of rec_customer_cur;
/

然后,在您的 PLSQL 代码中,您可以声明

CURSOR customer_cur IS
SELECT new rec_customer_cur(CustomerId, CustomerName)
FROM   Customers
WHERE  CustomerAreaCode = '576';

...然后使用...

SELECT CustomerName
INTO whatever
FROM table(my_customers)
WHERE CustomerId IN (1, 2, 3); 

这是因为模式级别的类型可以在 SQL 上下文中使用。

于 2014-10-31T17:15:42.620 回答
0

如果您还想显示由返回的数据集select,则只需使用 aREF CURSOR作为OUT参数。

SELECT ...FROM TABLE一个SQL语句,它需要一个STATIC TABLE NAME, 作为一个database object. 它会引发错误,因为集合名称实际上不是作为对象的数据库表。

要返回数据集,请SYS_REFCURSOR用作OUT参数。

open cur as select....

于 2014-10-31T16:21:11.133 回答