IF SET 帮助Oracle转DB2
IF SET Help Oracle to DB2
我必须将所有过程从 Oracle 迁移到 DB2 数据库。我想知道,如何在 Oracle 工作时在 IF 中执行 SET 语法。
在 Oracle 中使用的变量是 ps_iPkCooperativa
并且正在接收 0。
甲骨文代码:
BEGIN
SELECT CCOOP
INTO ps_iPkCooperativa
FROM COOP
EXCEPTION
WHEN NO_DATA_FOUND
THEN ps_iPkCooperativa := 0;
END;
我如何在 DB2 中执行此操作?
您可以对 db2 进行这样的转换:
BEGIN ATOMIC
DECLARE ps_iPkCooperativa INT;
SELECT CCOOP
INTO ps_iPkCooperativa
FROM COOP;
SIGNAL SQLSTATE '02000' -- means no_data_found
SET MESSAGE_TEXT='No Data Found ';
SET ps_iPkCooperativa = 0;
END@
其中
The ATOMIC compound statement, as the name suggests, can be thought of
as a singular whole—if any unhandled error conditions arise within it,
all statements which have been executed up to that point are
considered to have failed as well and are therefore rolled back.
ATOMIC compound statements cannot be nested inside other ATOMIC
compound statements.
In addition, you cannot use SAVEPOINTs or issue explicit COMMITs or
ROLLBACKs from within an ATOMIC compound statement.
NOTE
COMMIT, ROLLBACK, SAVEPOINTS and nested ATOMIC compound statements are
not allowed within an ATOMIC compound statement.
我必须将所有过程从 Oracle 迁移到 DB2 数据库。我想知道,如何在 Oracle 工作时在 IF 中执行 SET 语法。
在 Oracle 中使用的变量是 ps_iPkCooperativa
并且正在接收 0。
甲骨文代码:
BEGIN
SELECT CCOOP
INTO ps_iPkCooperativa
FROM COOP
EXCEPTION
WHEN NO_DATA_FOUND
THEN ps_iPkCooperativa := 0;
END;
我如何在 DB2 中执行此操作?
您可以对 db2 进行这样的转换:
BEGIN ATOMIC
DECLARE ps_iPkCooperativa INT;
SELECT CCOOP
INTO ps_iPkCooperativa
FROM COOP;
SIGNAL SQLSTATE '02000' -- means no_data_found
SET MESSAGE_TEXT='No Data Found ';
SET ps_iPkCooperativa = 0;
END@
其中
The ATOMIC compound statement, as the name suggests, can be thought of as a singular whole—if any unhandled error conditions arise within it, all statements which have been executed up to that point are considered to have failed as well and are therefore rolled back. ATOMIC compound statements cannot be nested inside other ATOMIC compound statements.
In addition, you cannot use SAVEPOINTs or issue explicit COMMITs or ROLLBACKs from within an ATOMIC compound statement.
NOTE
COMMIT, ROLLBACK, SAVEPOINTS and nested ATOMIC compound statements are not allowed within an ATOMIC compound statement.