table_line += "".join([
"<tr><td>Line_number",
str(x + 1),
"</td> <td>",
"</td> <td>".join([content_in_dictionnary[key][x] for key in content_in_dictionnary]),
"</td> <td></tr>"]), #<-- here
Fnumber是Flight_table中的PK和Schedule_table中的FK。
我希望在Schedule_table中更改PRICE时触发触发器 另外,要打印(Fnumber,ARRIVAL_APCODE,DEPARTURE_TIME,ARRIVAL_APCODE)的消息。
我写了这段代码,它没有用。
I have 2 tables one is Schedule_table :
SID NOT NULL NUMBER(38)
FNUMBER VARCHAR2(20)
DEPARTURE_TIME TIMESTAMP(6) WITH TIME ZONE
ARRIVAL_TIME TIMESTAMP(6) WITH TIME ZONE
PRICE NUMBER
The second table is Flight_table
FNUMBER NOT NULL VARCHAR2(20)
DEPARTURE_APCODE CHAR(3)
ARRIVAL_APCODE CHAR(3)
答案 0 :(得分:0)
您指的是Flight
表 - DEPARTURE_APCODE
和DEPARTURE_TIME
的列直接在触发器中,这是不可能的。您需要使用选择
获取这些值。
CREATE OR REPLACE TRIGGER schedule_trigger AFTER
UPDATE ON schedule
FOR EACH ROW
WHEN ( new.price <> old.price )
DECLARE
v_departure_apcode flight.departure_apcode%TYPE;
v_arrival_apcode flight.arrival_apcode%TYPE;
BEGIN
SELECT
departure_apcode,
arrival_apcode
INTO
v_departure_apcode,v_arrival_apcode
FROM
flight
WHERE
fnumber =:new.fnumber;
dbms_output.put_line('The flight number '
||:new.fnumber
|| v_departure_apcode
|| v_arrival_apcode
|| ' has changed to '
||:new.price
|| ' From '
||:old.price);
END;
/
并且注意在触发器中使用DBMS_OUTPUT.PUT_LINE()
是没有用的,因为SQL开发人员有时不会显示您的输出。最好创建一个日志表,并在trigger
。
您可能需要使用commit语句来显示输出。
SET SERVEROUTPUT ON;
UPDATE Schedule SET PRICE = 2502.00 where fnumber = 'F2004' ;
commit;
Commit complete.
The flight number F2004AB CD has changed to 2502 From 2501