执行包中的过程报错,单独拉出来sql执行正常

执行一个包中的一个过程报错:这个过程是一个拼凑sql的动作,然后执行这个拼凑的sql。执行包中的过程报错,说是执行sql中第7行有错误,但是打印出来的sql第7行没什么问题。讲拼凑的sql放到log表中单独执行这个拼凑的sql是成功的且结果也是对的,在包中调用这个过程就报错,为什么呢?下图1是执行包中的过程;图二是单独执行拼凑的sql

估计有特殊字符,导致语法错误。
这个动态的sql 文本能否去敏后完整放上来。

可能有特殊字符需要转义

拿不出来代码,是客户的电脑,不能外发;原因找到了,是之前for i in (select from xxx(46万的数据)) loop比较慢,逻辑比较复杂一晚上也跑不出来,我把这段逻辑改造成游标了,按照10000万次提交循环这个大表执行,效率变得很高,但是改过后放在包里就不行了;现象就是拼凑的sql可以执行,在包中不能执行;这个有什么解决方案吗

不是转义,原来的隐式游标改成显示游标批量循环就不行了;这个有没有什么解决方法 :sob:

1 个赞

ob版本是多少

1 个赞

4.2.18;

最好贴出文本,图片不方便

有可能

obclient [test]> declare
→ v_sql varchar2(1000);
→ begin
→ v_sql := ’
'> declare
'> type empcurtyp is ref cursor;
'> v_emp_cursor empcurtyp;
'> emp_record employees%rowtype;
'> v_stmt_str varchar2(200);
'> begin
'> – dynamic sql statement with placeholder:
'> v_stmt_str := ‘‘select * from employees where employee_id = :j’’;
'>
'> open v_emp_cursor for v_stmt_str using ‘‘1’’;
'>
'> loop
'> fetch v_emp_cursor into emp_record;
'> exit when v_emp_cursor%notfound; --无数据退出
'>
'> dbms_output.put_line(emp_record.first_name);
'> end loop;
'>
'> close v_emp_cursor;
‘> end’;

→ dbms_output.put_line(v_sql);

→ execute immediate v_sql;

→ end;
→ /
Query OK, 1 row affected (0.184 sec)

declare
type empcurtyp is ref cursor;
v_emp_cursor empcurtyp;
emp_record employees%rowtype;
v_stmt_str varchar2(200);
begin
– dynamic sql statement with placeholder:
v_stmt_str := ‘select * from employees where employee_id = :j’;

open v_emp_cursor for v_stmt_str using ‘1’;

loop
fetch v_emp_cursor into emp_record;
exit when v_emp_cursor%notfound; --无数据退出

dbms_output.put_line(emp_record.first_name);
end loop;

close v_emp_cursor;
end

Hello,KR.

要仔细核查拼装的代码,建议先去除中文注释,防止编辑器引入的不可见字符。