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

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

1 个赞

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

1 个赞

可能有特殊字符需要转义

1 个赞

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

1 个赞

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

2 个赞

ob版本是多少

2 个赞

4.2.18;

1 个赞

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

1 个赞

有可能

1 个赞

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.

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

1 个赞

拼接出来的sql确实单独执行没问题,现在是没有找到在包中拼接的时候哪里有问题,单单从拼凑的结果来看是没问题。有没有什么办法能够快速知道拼接结果在解析转义有什么问题嘛

1 个赞

使用显示游标执行的sql.txt (57.2 KB)

上述是需要执行的sql;
应该实际场景调用这个sql,类似:
declare
v_sql clob;
begin
select c_clobstr into v_sql from tusp_log_testsql ; --c_clobstr即为上面的大段sql
EXECUTE IMMEDIATE v_sql; --在这一步就报错:
end;

报错信息:ErrorCode = 600, SQLState = 42000, Details = ORA-00600: internal error code, arguments: -5253, Query was empty at anonymous block , line : 6, col : 2

单独执行上面大段sql是成功的,说明显示游标并行插入应该是支持;

找到原因了,


这里注释去掉就好了,感谢