我创建了下表
创建表选项卡(id NUMBER,val VARCHAR2(50),last_date DATE,PRIMARY KEY(id,val))
我正在使用以下 PL/SQL 块来创建触发器
create or replace TRIGGER TRIG AFTER INSERT OR UPDATE OR DELETE ON tab
FOR EACH ROW
DECLARE
l_enqueue_options DBMS_AQ.enqueue_options_t;
l_message_properties DBMS_AQ.message_properties_t;
l_txn_event_msg tab_PAYLOAD;
l_message_handle RAW(16);
ERR_MSG VARCHAR2(600);
primaryKey VARCHAR2(4000);
opnCode VARCHAR2(10);
BEGIN
IF INSERTING THEN
opnCode := 'INSERT';
primaryKey := :new.id;
ELSIF UPDATING THEN
opnCode := 'UPDATE';
primaryKey := :new.id;
ELSIF DELETING THEN
opnCode := 'DELETE';
primaryKey := :old.id;
END IF;
l_txn_event_msg := tab_PAYLOAD(
primaryKey, opnCode, sysdate,:new.id,'DUMMY'
);
DBMS_AQ.enqueue(
queue_name => 'tab_Q',
enqueue_options => l_enqueue_options,
message_properties => l_message_properties,
payload => l_txn_event_msg,
msgid => l_message_handle
);
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
WHEN OTHERS THEN
ERR_MSG := sqlerrm || ' Error while executing trigger TRIG_UB.';
DBMS_OUTPUT.PUT_LINE('Some exception occured in tab ==>' || ERR_MSG);
END;
现在上面的触发器正确吗?我想在触发器中使用复合主键,例如 primaryKey := :new.id|||||old.id; 如果我错了,请纠正我?