我使用 Aqua Data Studio 通过分散输出语句来调试存储过程。
我在包中有一个删除语句,它违反了完整性约束:
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 出错之前立即看到消息“Attempting to delete x: 123”。
docs为
dbms_output
包不提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) 返回。”
问候,
抢。
关于oracle - dbms_output.put() 的缓冲方式是否与 dbms_output.put_line() 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12532211/