实施例:有一个表“ID_NAME”与一列“ID”,其具有2000个条目等1,2,3 .. 2000 我已经有一个查询从ID_NAME其中id如何存储ORACLE sql查询的结果集?
选择ID < 1001;
> Result : 1 2 3 4 . .1000
我的PL SQL块看起来是这样的,
SET SERVEROUTPUT ON;
declare
var1 number;
var2 number;
var3 number;
var4 number;
var5 number;
var6 number;
var7 number;
var8 number;
var9 number;
var10 number;
begin
with set1 as (select id from ID_NAME where id < 1001)
select count(*) into var1 from table1 where id in (select * from set1);
select count(*) into var2 from table2 where id in (select * from set1);
select count(*) into var3 from table3 where id in (select * from set1);
select count(*) into var4 from table4 where id in (select * from set1);
select count(*) into var5 from table5 where id in (select * from set1);
select count(*) into var6 from table6 where id in (select * from set1);
select count(*) into var7 from table7 where id in (select * from set1);
select count(*) into var8 from table8 where id in (select * from set1);
select count(*) into var9 from table9 where id in (select * from set1);
select count(*) into var10 from table10 where id in (select * from set1);
DBMS_OUTPUT.PUT_LINE('var1,var2,var3,var4,var5,var6,var7,var8,var9,var10');
DBMS_OUTPUT.PUT_LINE(var1||','||var2||','||var3||','||var4||','||var5||','||var6||','||var7||','||var8||','||var9||','||var10);
end;
,但我发现
PL/SQL:ORA-00942:表或视图不存在
在我的SQL开发人员。
我想用SET1从我下面的查询,这样我就不必在计数一次又一次地运行它(*)子查询
with set1 as (select id from ID_NAME where id < 1001)