This seems like it should be very easy…anyway, it is in MS SQL Server
In a DB2 stored procedure, how can I just get the value of a variable? Say I have the following stored procedure:
CREATE PROCEDURE etl.TestABC(
)
LANGUAGE SQL
BEGIN
declare Stmt varchar(2048);
set Stmt = 'this is a test';
-- print Stmt;
-- select Stmt;
return 0;
END @
I’d like to print out the value of Stmt after I set it. Print doesn’t work, select doesn’t work. Somebody said I have to insert it to a table first, and then get it after I run the stored procedure. Is this really necessary?
Thanks,
Sylvia
EDIT: I should have made clearer that I want to see the value of Stmt each time after I set it, and I may need to set it multiple times within the same stored procedure.
If you want to see the values while you’re developing / testing your stored procedure, then you should use IBM Data Studio and debug your stored procedure. This provides normal debugger functionality, so you can see the value of variables as your procedure executes.
If, however, you just want to execute your stored procedure and see a history of values, I suggest creating a global temporary table, and inserting a row into it in your code:
Then, at points in your stored procedure, add:
After you execute your stored procedure, you can query the table
session.StmtHistoryand see the values you’re looking for.Also, DB2 9.7 added Oracle compatibility, so if you are using this version you may actually be able to use DBMS_OUTPUT.PUT_LINE and DBMS_OUTPUT.GET_LINES to accomplish this, if you prefer.