如何通过DbVisualizer等GUI工具在DB2调用中创建匿名块

mklgxw1f  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(257)

编码:

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;

无法在DB2中执行。错误:

[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

而且还

[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
pwuypxnk

pwuypxnk1#

您必须使用不同的语句分隔符/终止符来运行复合语句。
每个客户端工具都有自己的设置方法。
数据库可视化工具:

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

Using the DBMS Output Tab

仅适用于DbVisualizer DbVisualizer专业版。

此功能仅在DbVisualizer Pro版中可用。

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

相关问题