Search code examples
plsqldb2db2-luw

DB2, PLSQL : My script doesn't work


I'm trying to run a PL/SQL script on my REDHAT VM

This is my script :

connect to WWW user XXX using VVV
DECLARE
   message  varchar2(20):= 'Hello, World!';
BEGIN
   dbms_output.put_line(message);
END;
/

And this is my command :

 db2 -td/ -vf test.sql

And this is my error:

SQL0104N An unexpected token "DECLARE" was found following "".
Expected tokens may include: "NEW". SQLSTATE=42601

I tried many things and the result is always the same. Can someone help me?


Solution

  • You define the statement terminator as /, but don't use any statement terminator with the connect to statement. Append a / and it should work.

    Also, please check that PL/SQL support is turned on. You need to set the DB2_COMPATIBILITY_VECTOR to enable syntax support for Oracle PL/SQL. See this section in the DB2 documentation for details.