所以我在PAYMENT表上有一个名为Status的列。它有另一个名为Reservation_ID的表的外键。预订表还有一个状态列,只有在支付表的状态栏中有值时才会更新。因此,如果我的支付表中的状态字段具有值“已确认”,则该特定Reservation_ID的值应该变为1.否则为22.这就是我触发的方式:
reactor.ipc.netty
因此触发器基本上被编译但是当我尝试在Payment Table中插入值时,我收到以下错误:
CREATE OR REPLACE TRIGGER stats BEFORE INSERT OR DELETE OR UPDATE ON PAYMENT FOR EACH ROW
DECLARE
V_STATUS VARCHAR2(20);
BEGIN
SELECT Status INTO V_STATUS FROM PAYMENT INNER JOIN RESERVATION ON PAYMENT.Reservation_ID=RESERVATION.Reservation_ID WHERE PAYMENT.Reservation_ID=:NEW.Reservation_ID;
IF INSERTING AND V_STATUS='CONFIRMED' THEN
UPDATE RESERVATION SET status=1 WHERE Reservation_ID=:new.Reservation_ID;
ELSIF UPDATING AND V_STATUS='CONFIRMED' THEN
UPDATE RESERVATION SET status=1 WHERE Reservation_ID=:new.Reservation_ID;
ELSE
UPDATE RESERVATION SET status=22 WHERE Reservation_ID=:new.Reservation_ID;
END IF;
END;
为两个表创建规则:
Error report -
ORA-01403: no data found
ORA-06512: at "ME.STATS", line 4
ORA-04088: error during execution of trigger 'ME.STATS'
答案 0 :(得分:0)
第一:
CREATE TABLE RESERVATION(
Status NUMBER(10));
SELECT Status INTO V_STATUS
IF INSERTING AND V_STATUS='CONFIRMED'
您能否解释一下您希望NUMBER如何匹配字符串?
下一步(来自http://www.dba-oracle.com/sf_ora_01403_no_data_found.htm)
SELECT INTO子句是标准SQL查询,它提取行或集 数据库中的列,并将检索到的数据放入变量中 已经预定义的。
如果SELECT INTO语句至少没有返回e行, 抛出ORA-01403。
所以这个:
SELECT
Status INTO V_STATUS
FROM PAYMENT p
INNER JOIN RESERVATION r
ON p.Reservation_ID = r.Reservation_ID
WHERE p.Reservation_ID = :NEW.Reservation_ID;
可能根本不输出任何行......
答案 1 :(得分:0)
同意@Blag,以下声明给出了no data found exception
。
通常,如果您想知道错误指向的确切行号,可以通过DBA_SOURCE
或ALL_SOURCES
引用该对象。
SELECT
Status INTO V_STATUS
FROM PAYMENT p
INNER JOIN RESERVATION r
ON p.Reservation_ID = r.Reservation_ID
WHERE p.Reservation_ID = :NEW.Reservation_ID;