我使用Aqua Data Studio通过散布输出结果来调试存储过程.
我在包中有一个违反完整性约束的delete语句:
DELETE FROM x WHERE x.ID = an_x_with_children;
正如预期的那样,我的proc在这一行上失败了ORA-02292.我想看看an_x_with_children变量的值.所以我用这样的输出包装行:
dbms_output.put('Attempting to delete x: ' || an_x_with_children); DELETE FROM x WHERE x.ID = an_x_with_children; dbms_output.put(' Success');
并且期望在完整性约束违反错误消息之前将消息视为消息控制台中的最后一件事.但它不打印!
现在,如果我更改输出以使用put_line()过程,如下所示:
dbms_output.put_line('Attempting to delete x: ' || an_x_with_children); DELETE FROM x WHERE x.ID = an_x_with_children; dbms_output.put_line(' Success');
在proc错误出现之前,我立即看到“试图删除x:123”的消息.
dbms_output包的docs没有提到put和put_line过程在这方面表现不同.例如,它说
Output that you create using PUT or PUT_LINE is buffered.
因此,当proc错误时,我会期望两者都显示或不显示输出.
有人可以向我解释这种行为发生了什么吗?
解决方法
这是一个显示您所看到的行为的示例:
SQL> exec dbms_output.put_line('hello') hello PL/SQL procedure successfully completed. SQL> exec dbms_output.put('hello again') PL/SQL procedure successfully completed. SQL> exec dbms_output.put(' and again') PL/SQL procedure successfully completed. SQL> exec dbms_output.new_line hello again and again PL/SQL procedure successfully completed.
documentation说“SQL * Plus在发出SQL语句或匿名PL / SQL调用后调用GET_LINES”.
并且过程GET_LINES说“此过程从缓冲区中检索一行数组.”
有了PUT,你还没有完成你的生产线.所以它不打印.
NEW_LINE过程也提到了这一点:“此过程放置行结束标记.GET_LINE过程和GET_LINES过程返回”行“由”换行符“分隔.每次调用PUT_LINE过程或NEW_LINE过程都会生成一行这是由GET_LINE(S)返回的.“
问候,抢.