oracle 如何在oracle存储过程中printf(用于调试)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9519510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:00:24  来源:igfitidea点击:

how to printf in oracle stored procedure (for debugging purposes)?

oraclestored-procedures

提问by Adrian

I'm trying to debug a stored procedure (Oracle). I want to print some variables.

我正在尝试调试存储过程 (Oracle)。我想打印一些变量。

I don't know what the command to print is (or where to find it). Can anyone tell me what it is?

我不知道要打印的命令是什么(或在哪里可以找到它)。谁能告诉我它是什么?

Thanks

谢谢

EDIT:

编辑:

This is my trigger:

这是我的触发器:

create or replace
procedure bns_saa_confs_update_state (
  theID in varchar2
)
AS
begin
  UPDATE BNS_SAA_CONFIRMATIONS SET SentToWssStatus='T' WHERE ID=theID;
  commit;
end;

I want to print theID

我想打印身

回答by Wolf

Use the dbms_output.put_line()function:

使用dbms_output.put_line()函数:

declare
    my_var varchar2(20);
begin
    my_var := 'Hello World';
    dbms_output.put_line(my_var);
end;
/

Make sure you have set serveroutput onif running from SQLPlus, or set output on if running from an IDE. Some developers will create a wrapper function to simplify debugging.

set serveroutput on如果从 SQLPlus 运行,请确保您有,或者如果从 IDE 运行,请设置输出。一些开发人员会创建一个包装函数来简化调试。

回答by Justin Cave

You probably want the DBMS_OUTPUTpackage, i.e.

你可能想要这个DBMS_OUTPUT包,即

DECLARE
  a INTEGER := 0;
BEGIN
  dbms_output.put_line( 'Starting value: ' || a );
  a := a + 1;
  dbms_output.put_line( 'Ending value: ' || a );
END;

Note that you generally need to enable DBMS_OUTPUTin your client application before the data will be displayed. In SQL*Plus, you'll need to

请注意,DBMS_OUTPUT在显示数据之前,您通常需要在客户端应用程序中启用。在 SQL*Plus 中,您需要

set serveroutput on;

before executing the stored procedure in order for data to be displayed after execution. Other GUI tools have different approaches to enabling DBMS_OUTPUT.

在执行存储过程之前,以便在执行后显示数据。其他 GUI 工具有不同的方法来启用DBMS_OUTPUT.