通过putty在DB2中执行时,plsql语句出错

idfiyjo8  于 2023-06-22  发布在  DB2
关注(0)|答案(1)|浏览(215)

我创建了下面的DB2 plsql脚本,并尝试通过putty运行.sql文件。但我得到以下错误;

BEGIN
DECLARE abc  VARCHAR2(15)
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "END-OF-STATEMENT" was found following "abc  
VARCHAR2(15)".  Expected tokens may include:  "<psm_semicolon>".  LINE 
NUMBER=2.  SQLSTATE=42601

DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL0104N  An unexpected token "IN" was found following "FOR abc  ".  
Expected tokens may include:  "JOIN".  SQLSTATE=42601

下面是我写的示例plsql语句。

BEGIN
DECLARE abc VARCHAR2(15);
  FOR abc IN (SELECT empid  FROM employee where mark=2 order by 1) LOOP
    Insert into salary
      (id,
       name,mark)
      SELECT id,
             name,
             3
        FROM salary A
       WHERE id=abc.empid and mark=2; 
         
  END LOOP;
  COMMIT;
  END;
/
wmtdaxz3

wmtdaxz31#

只要将DECLARE关键字放在BEGIN之前,或者将BEGIN放在DECLARE之后,如果这是您想要做的。由于声明节后缺少BEGIN关键字而发生错误。你的代码可能看起来像这样:

DECLARE 
  abc VARCHAR2(15);
BEGIN
  FOR abc IN (SELECT empid  FROM employee where mark=2 order by 1) 
  LOOP
    Insert into salary
      (
       id,
       name,
       mark
      )
      SELECT id,
             name,
             3
      FROM salary A
      WHERE id=abc.empid 
            and mark=2; 
         
  END LOOP;
  COMMIT;
  END;

相关问题