我正在创建一个像这样的程序
CREATE OR REPLACE PROCEDURE MY_PROC AS
CURSOR DLR_UPDT IS
SELECT B.MDN,A.AMNT
FROM
E_D A,E_D_A_D B
WHERE
A.U_ID=B.U_ID AND
A.P_F<>'Y';
BEGIN
FOR Y IN DLR_UPDT
LOOP
IF (Y.AMNT>0)
BEGIN
INSERT INTO S_T_D_O
(ID, MDN
)
VALUES (SEQ.NEXTVAL, Y.MDN,
);
END
END LOOP;
END;
但是我收到了这个错误
(S224)期待:
statement_terminator BEGIN CASE DEC LOET END IDENTIFIER IF LOOP
答案 0 :(得分:3)
您的程序中有几处语法错误:
这是一个固定版本:
CREATE OR REPLACE PROCEDURE MY_PROC AS
CURSOR DLR_UPDT IS
SELECT B.MDN,
A.AMNT
FROM E_D A,
E_D_A_D B
WHERE A.U_ID = B.U_ID
AND A.P_F <> 'Y';
BEGIN
FOR Y IN DLR_UPDT
LOOP
IF (Y.AMNT > 0) then
INSERT INTO S_T_D_O
(ID,
MDN)
VALUES
(SEQ.NEXTVAL,
Y.MDN);
END if;
END LOOP;
END;
虽然我建议完全摆脱循环并改为使用单个INSERT语句。
编辑:单一INSERT解决方案:
INSERT INTO S_T_D_O
(ID, MDN)
(SELECT SEQ.NEXTVAL,
B.MDN
FROM E_D A,
E_D_A_D B
WHERE A.U_ID = B.U_ID
AND A.P_F <> 'Y'
AND A.AMNT > 0); -- only insert rows with positive amount
答案 1 :(得分:0)
IF condition THEN
{...statements...}
END IF;
参考 - http://www.techonthenet.com/oracle/loops/if_then.php
所以在你的情况下,像
IF (Y.AMNT>0) THEN
INSERT INTO S_T_D_O (ID, MDN)
VALUES (SEQ.NEXTVAL, Y.MDN);
END IF;