Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 507
Adrian Avatar asked Mar 01 '12 16:03

Adrian


People also ask

Can we debug stored procedure in Oracle?

In Oracle, you can debug the following program units (PL/SQL programs): anonymous blocks, packages, procedures, functions, and triggers.

How can you generate debugging output from PL SQL?

Use the DBMS_OUTPUT package. Another possible method is to use the SHOW ERROR command.

How do I print a statement in PL SQL?

execute immediate q'[select destination from temp_1 where cond1 =(:var1) and cond2 = (:var2) into dest]' using sd(i),sid1(i); return dest; -- or printline dbms_output. put_line(dest);


1 Answers

Use the dbms_output.put_line() function:

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

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

like image 135
Wolf Avatar answered Sep 28 '22 08:09

Wolf