Home > Blockchain >  How to create anonymous block in DB2 call via GUI tool like DbVisualizer
How to create anonymous block in DB2 call via GUI tool like DbVisualizer

Time:05-05

Code :

SET SERVEROUTPUT ON;
declare count_t integer  : = 0;
   BEGIN
       CALL DBMS_OUTPUT.PUT_LINE ( 'Hello' );
       CALL DBMS_OUTPUT.PUT_LINE ( 'count_t-' || count_t );
   END;

Unable to execute in DB2. Error :

[Code: -104, SQL State: 42601]  An unexpected token "SERVEROUTPUT" was found following "SET ".  Expected tokens may include:  "SSA".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.28.11

And also

[Code: -104, SQL State: 42601]  An unexpected token "declare count_t integer" was found following "BEGIN-OF-STATEMENT".  Expected tokens may include:  "<select>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.28.11

CodePudding user response:

You must use different Statement Delimiter / Terminator to run compound statements.
Every client tool has its own methods of setting it.
Dbvisualizer:

Tools\Tool Properties\SQL Commander\Statement Delimiters:
SQL Statement Delimiter:  
  SQL Statement Delimiter 1: @  
  SQL Statement Delimiter 2: @  

Using the DBMS Output Tab:

Only in DbVisualizer DbVisualizer Pro edition.
This feature is only available in the DbVisualizer Pro edition.

BEGIN
  declare count_t integer default 0;      
  CALL DBMS_OUTPUT.PUT_LINE ( 'Hello' );
  CALL DBMS_OUTPUT.PUT_LINE ( 'count_t-' || count_t );
END
@
  • Related