我有一个接收参数为where子句(即where col1 = 1
)的过程。我使用这个子句在一些表中使用EXECUTE IMMEDIATE语句搜索并将结果插入到嵌套表中,而不是显示。“ORA-01007:变量不在选择列表中”当没有行由EXECUTE IMMEDIATE返回时
如果找到任何数据,该过程将正常工作,但如果未找到数据,则会引发上述错误。
有人可以解释是什么原因导致这个错误吗?
下面是该过程:
create or replace procedure prc_checks(pi_where varchar2) as
cursor c_tables is
select object_name,
case object_name
when 'XP_IMPORT_MW' THEN 99999999
when 'XP_IMPORT_MW_ARCH' THEN 99999998
else TO_NUMBER(SUBSTR(object_name, -8, 8))
end to_order
from dba_objects
where object_type = 'TABLE'
and object_name IN ('XP_IMPORT_MW', 'XP_IMPORT_MW_ARCH')
or REGEXP_LIKE (object_name, 'XP_IMPORT_MW_ARCH_201(5|6|7)[0-9]{4}') order by 2 desc;
type t_result is table of xp_import_mw%rowtype;
v_result t_result;
v_sql varchar2(300);
BEGIN
for i in c_tables
loop
v_sql := 'select * from ' || i.object_name || ' ' || pi_where;
execute immediate v_sql bulk collect into v_result;
if v_result.count > 0
then
for j in v_result.first .. v_result.last
loop
dbms_output.put_line(v_result(j).art_nr);
end loop;
dbms_output.put_line('... the required information was found on table name ' || upper(i.object_name));
exit;
end if;
end loop;
END prc_checks;
向我们显示pi_where的值,并假设i.object_name中的任何表具有与xp_import_mv – Typo
相同的行类型。有一个给pi_where的例子:'where col1 = 1' –