【发布时间】:2016-08-03 11:28:43
【问题描述】:
示例:有一个表“ID_NAME”,其中有一列“ID”,其中包含 2000 个条目,例如 1,2,3.. 2000。 我有一个问题
从 ID_NAME 中选择 id,其中 id
> 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,这样我就不必在 count(*) 子查询中一次又一次地运行它
with set1 as (select id from ID_NAME where id < 1001)
【问题讨论】: