Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any print statement in db2 just like oracle

Is there( db2 database) 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?

please provide some code also.

like image 784
raj Avatar asked Oct 21 '25 14:10

raj


1 Answers

IBM's DB2 version 9.7 or later actually comes with a DBMS_OUTPUT module which appears to be able to do the same thing as Oracle's version. From the DB2 documentation, DBMS_OUTPUT can be called from within a stored procedure, e.g.

SET SERVEROUTPUT ON@

CREATE PROCEDURE proc1()
BEGIN
    CALL DBMS_OUTPUT.PUT( 'H' );
    CALL DBMS_OUTPUT.PUT( 'e' );
    CALL DBMS_OUTPUT.PUT( 'l' );
    CALL DBMS_OUTPUT.PUT( 'l' );
    CALL DBMS_OUTPUT.PUT( 'o' );
    CALL DBMS_OUTPUT.PUT( '.' );
    CALL DBMS_OUTPUT.NEW_LINE;
  END@
CALL proc1@  

This would output Hello. to the console.

Note that you also need to make sure that the output from DBMS_OUTPUT is being redirected to the standard output:

The procedures in this module allow you to work with the message buffer. Use the command line processor (CLP) command SET SERVEROUTPUT ON to redirect the output to standard output.

like image 137
Tim Biegeleisen Avatar answered Oct 23 '25 05:10

Tim Biegeleisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!