CREATE TABLE myStudent (
student_id NUMBER(5) NOT NULL,
department CHAR(3) NOT NULL,
course NUMBER(3) NOT NULL,
grade CHAR(1)
);
CREATE OR REPLACE TRIGGER LogRSInserts
BEFORE INSERT ON myStudent
FOR EACH ROW
DECLARE
v_Status INTEGER;
BEGIN
DBMS_PIPE.PACK_MESSAGE('I');
DBMS_PIPE.PACK_MESSAGE(user);
DBMS_PIPE.PACK_MESSAGE(sysdate);
DBMS_PIPE.PACK_MESSAGE(:new.student_ID);
DBMS_PIPE.PACK_MESSAGE(:new.department);
DBMS_PIPE.PACK_MESSAGE(:new.course);
DBMS_PIPE.PACK_MESSAGE(:new.grade);
v_Status := DBMS_PIPE.SEND_MESSAGE('RSInserts');
IF v_Status != 0 THEN
RAISE_APPLICATION_ERROR(-20010, 'LogRSInserts trigger ' || 'couldn''t send the message, status = ' || v_Status);
END IF;
END LogRSInserts;
/
INSERT INTO myStudent (student_id, department, course, grade)
VALUES (10000, 'CS', 102, 'A');
INSERT INTO myStudent (student_id, department, course, grade)
VALUES (10002, 'CS', 102, 'B');
INSERT INTO myStudent (student_id, department, course, grade)
VALUES (10003, 'CS', 102, 'C');
INSERT INTO myStudent (student_id, department, course, grade)
VALUES (10000, 'HIS', 101, 'A');
INSERT INTO myStudent (student_id, department, course, grade)
VALUES (10001, 'HIS', 101, 'B');
drop table myStudent;
--
|