在 DB2 中创建过程
Create a procedure in DB2
我在 .sql 文件中使用 DB2 创建了一个简单的过程,并使用 Shell (Unix) 执行脚本。我收到一个错误:SQLSTATE 42601.
DB20000I The SQL command completed successfully.
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789
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 "IN'
where EMPNO=7789". Expected tokens may include: "<psm_semicolon>". LINE
NUMBER=3. SQLSTATE=42601
有程序:
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789;
END
/
如果这包含在文件中,您需要更改批处理终止符。由于 SP 行以 ;
结尾,批处理以 /
结尾,您需要在命令行中指定它。
例如
db2 -td/ -f <your file>.sql
I like to use # since it does not mess with unix shells like /
will. Here replace your last character with #
in the file and use -td#
我在创建过程前加了'--#SET TERMINATOR /',问题解决了。
--#SET TERMINATOR /
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789;
END
/
我在 .sql 文件中使用 DB2 创建了一个简单的过程,并使用 Shell (Unix) 执行脚本。我收到一个错误:SQLSTATE 42601.
DB20000I The SQL command completed successfully.
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789
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 "IN'
where EMPNO=7789". Expected tokens may include: "<psm_semicolon>". LINE
NUMBER=3. SQLSTATE=42601
有程序:
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789;
END
/
如果这包含在文件中,您需要更改批处理终止符。由于 SP 行以 ;
结尾,批处理以 /
结尾,您需要在命令行中指定它。
例如
db2 -td/ -f <your file>.sql
I like to use # since it does not mess with unix shells like
/
will. Here replace your last character with#
in the file and use-td#
我在创建过程前加了'--#SET TERMINATOR /',问题解决了。
--#SET TERMINATOR /
CREATE OR REPLACE PROCEDURE PROC_SAMPLE1()
BEGIN
update EMP set ENAME='ALLAIN' where EMPNO=7789;
END
/