求助存储过程中硬解析问题
create or replace procedure proc1
as
v_cou pls_integer;
begin
for i in 1..10000
loop
execute immediate 'insert into tb_test values(:n)' using i;
execute immediate 'select count(1) into v_cou from equipstate where state>0 and lineid = :n ' using i;
insert into tb_test values(v_cou);
end loop;
end;
以上是测试的存储过程,select count(1) into v_cou from equipstate where state>0 and lineid =:n
在原来的存储过程中该语句每秒执行数次,硬解析值非常高,目前想改为软解析,找了一些资料,引用了现在的写法execute immediate 'select count(1) into v_cou from equipstate where state>0 and lineid = :n ' using i;
编译通过但是执行时语法错误,MS不能这样写,向各位大神求助,这里应该如何改写为硬解析,其实就是很简单的一个查询赋值给v_cou ,先谢了
存储
------解决方案--------------------你这完全不需要动态sql的啊,照样不需要硬解析的。。。
create or replace procedure proc1 as
v_cou pls_integer;
begin
for i in 1 .. 10000 loop
insert into tb_test values (i);
select count(1)
into v_cou
from equipstate
where state > 0
and lineid = i;
insert into tb_test values (v_cou);
end loop;
end;