oracle 报错pls 00405,oracle - 检查是否存在PLS-00405:在此上下文中不允许子查询 - 堆栈内存溢出...

使用正确的语法,将如下所示:

create or replace procedure daily_rpt

( v_start in date

, v_end in date )

as

begin

for r in (

select ao_out_no, 0 as exists_check

from tablea

)

loop

select count(*) into exists_check

from tablea

where out_no = r.ao_out_no

and rownum = 1;

if r.exists_check > 0 then

--DO NOTHING

else

insert into tableb (out_no) values (r.ao_out_no);

end if;

end loop;

end;

但是,查询所有行然后对每行进行一次额外的查找来确定是否要使用它是低效率的,因为SQL可以为您做这种事情。 因此版本2可能类似于:

create or replace procedure daily_rpt

( v_start in date

, v_end in date )

as

begin

for r in (

select ao_out_no

from tablea

where not exists

( select count(*)

from tablea

where out_no = r.ao_out_no

and rownum = 1 )

)

loop

insert into tableb (out_no) values (r.ao_out_no);

end loop;

end;

在这一点上,您可以将整个循环替换为insert ... where not exists (...)语句。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值