Link to home
Start Free TrialLog in
Avatar of mersis
mersis

asked on

Is there a print statement in DB2?

Is there any equivalent of DBMS_OUTPUT in Oracle or PRINT in SQL Server for DB2 or do I need to jump over my head again for this sort of thing?
ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mersis
mersis

ASKER

thats concise and pretty clear. Are there any ways round it? All I want is to be able to run a STORED PROC in COMMAND EDITOR and see those outputs as the STORED PROC is executed.
SOLUTION
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you could write a stored procedure that receive a string as a parameter and writes that string to a file, and invoke that stored procedure from your function, but you won't be able to receive any output to the command editor window
Avatar of mersis

ASKER

Ok, could you give me some code for either of the proposed solutions. In particular its important that I see all the messages untill the stored proc has crashed, not only few in the beginning that were flushed.
What I mean is that imagine you have 100 statements. After each statement there is DBMS_OUTPUT-like statement. Now when executing my stored proc an error occurs at the statement 50 and everything is rolled back. I would like to see all the 49 messages that were generated in the previous successfully run statements. How can I achieve this?

Pretty simple ....

First create the log table:

create table LogTable (
   theMessage varchar(1000)
)

Then in your program:
<do some stuff>
insert into LogTable values('after doing some stuff') with NC;
<do more stuff>
insert into LogTable values('after doing more stuff') with NC;
<do even more stuff>
insert into LogTable values('after doing even more stuff') with NC;

You get the picture. You could even build a customized string with variable values and use that in your insert to LogTable. (That's the way I usually do it.)

Notice that by using "with NC", the rollback won't affect the log-table.

HTH,
DaveSlash
Avatar of mersis

ASKER

daveslash, thanks very much, looks like a solution indeed. But I would rather prefer writing to a file if that is also possible?
Avatar of mersis

ASKER

daveslash, my DB2 (v9.1 for Windows) does not understand "WITH NC". It only knows of RR, RS, CS, UR. Which one do I need to be using so that rollback does not affect inserts into LogTable table?