Oracle 触发器 exact fetch returns more than requested number of rows
createorreplaceTRIGGERtrBEFOREINSERTONREALESTATEFOREACHROWDECLAREvBUDGETNUMBER(20);vC...
create or replace
TRIGGER tr
BEFORE INSERT ON REALESTATE
FOR EACH ROW
DECLARE
vBUDGET NUMBER(20);
vCAPITAL NUMBER(20);
BEGIN
SELECT SUM(BUDGET) into vBUDGET
FROM REALESTATE
WHERE DEVELOPERNAME=:new.DEVELOPERNAME;
SELECT CAPITAL INTO vCAPITAL
FROM DEVELOPERS
WHERE DEVELOPERNAME=:new.DEVELOPERNAME;
IF (vBUDGET+:new.BUDGET)>vCAPITAL THEN
RAISE_APPLICATION_ERROR (-20006,'BUDGET is too large');
END IF;
END tr;
我的理念是:在REALESTATE中插入一行如果在REALESTATE中DEVELOPERNAME相同的BUDGET总和大于DEVELOPERNAME在对应DEVELOPERS表中的CAPITAL值时弹出错误
以上是我的trigger代码,在我向REALESTATE表格插入一行的时候显示上述错误,请大侠指引~
好的...在select into语句当中加入distinct,就ok了...擦自己解决了 展开
TRIGGER tr
BEFORE INSERT ON REALESTATE
FOR EACH ROW
DECLARE
vBUDGET NUMBER(20);
vCAPITAL NUMBER(20);
BEGIN
SELECT SUM(BUDGET) into vBUDGET
FROM REALESTATE
WHERE DEVELOPERNAME=:new.DEVELOPERNAME;
SELECT CAPITAL INTO vCAPITAL
FROM DEVELOPERS
WHERE DEVELOPERNAME=:new.DEVELOPERNAME;
IF (vBUDGET+:new.BUDGET)>vCAPITAL THEN
RAISE_APPLICATION_ERROR (-20006,'BUDGET is too large');
END IF;
END tr;
我的理念是:在REALESTATE中插入一行如果在REALESTATE中DEVELOPERNAME相同的BUDGET总和大于DEVELOPERNAME在对应DEVELOPERS表中的CAPITAL值时弹出错误
以上是我的trigger代码,在我向REALESTATE表格插入一行的时候显示上述错误,请大侠指引~
好的...在select into语句当中加入distinct,就ok了...擦自己解决了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询