我对 Oracle 中的存储过程有疑问。以下是存储过程和表的现状:
create table STORES
(
ID number,
NAME varchar2(100),
CITY varchar2(100),
EXPIRES DATE
)
insert into stores values(1, 'Store 1', 'City 1', sysdate);
insert into stores values(2, 'Store 2', 'City 1', sysdate);
insert into stores values(3, 'Store 3', 'City 2', sysdate);
create table CLOSED
(
ID number,
NAME varchar2(100),
CITY varchar2(100)
)
create or replace PROCEDURE
pr_TestProc(subQuery IN VARCHAR2)
IS
begin
insert into CLOSED (ID, NAME, CITY)
select ID, NAME, CITY
from STORES
where ID in (1, 2, 3);
end;
我想做的是用作为参数传入的 subQuery 替换“in”值。因此,如果我运行以下程序:
execute pr_TestProc('select ID from STORES where EXPIRES <= sysdate');
传入的查询应该作为在过程中运行的子查询来执行。就像是:
insert into CLOSED (ID, NAME, CITY) select ID, NAME, CITY
from STORES
where ID in (execute(subQuery));
显然这是行不通的,但是实现这一目标的最佳方法是什么,或者甚至有可能吗?
谢谢,布赖恩