0

有没有办法将查询存储在对象中,以便您可以在游标中使用它或作为更大查询的子查询?这一切都没有使用立即执行?

假设你想要这个:

set serveroutput on;
DECLARE
  CNT NUMBER; 
  v1 varchar2(4000);
  SQL_QUERY view := SELECT table_name FROM USER_TABLES;
  CURSOR C1 IS 
    SQL_QUERY;
BEGIN
  OPEN C1;
    FETCH C1 INTO V1;
    dbms_output.put_line('name of the first table: '||v1);
  CLOSE C1;
  SELECT COUNT(*) INTO CNT FROM SQL_QUERY;
  dbms_output.put_line('Count: '|| cnt);
end;

可能吗?

4

1 回答 1

0

“将查询存储在对象中”

这是视图的定义。

create view foo as select table_name from user_tables;

然后

DECLARE
  CNT NUMBER; 
  v1 varchar2(4000);
  CURSOR C1 IS 
    select * from foo;
BEGIN
  OPEN C1;
    FETCH C1 INTO V1;
    dbms_output.put_line('name of the first table: '||v1);
  CLOSE C1;
  SELECT COUNT(*) INTO CNT FROM (select null from foo);
  dbms_output.put_line('Count: '|| cnt);
end;

这不是你想要的吗?

于 2013-01-22T13:37:41.590 回答