0% found this document useful (0 votes)
60 views4 pages

SQL Trigger Examples and Errors

The document shows SQL commands for creating triggers on tables to log insert, update and delete operations. It also contains examples of executing DML statements on tables and errors encountered.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views4 pages

SQL Trigger Examples and Errors

The document shows SQL commands for creating triggers on tables to log insert, update and delete operations. It also contains examples of executing DML statements on tables and errors encountered.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL> CREATE OR REPLACE TRIGGER VIJAY

2 AFTER UPDATE OR INSERT OR DELETE ON EMP

3 FOR EACH ROW

4 BEGIN

5 IF UPDATING THEN

6 DBMS_OUTPUT.PUT_LINE('TABLE IS UPDATED');

7 ELSIF INSERTING THEN

8 DBMS_OUTPUT.PUT_LINE('TABLE IS INSERTED');

9 ELSIF DELETING THEN

10 DBMS_OUTPUT.PUT_LINE('TABLE IS DELETED');

11 END IF;

12 END;

13 /

Trigger created.

SQL> update emp set income =900 where empname='kumar';

update emp set income =900 where empname='kumar'

ERROR at line 1:

ORA-00904: "EMPNAME": invalid identifier

SQL>> insert into emp values ( 4,'Chandru',700,250,80);

SP2-0734: unknown command beginning "> insert i..." - rest of line ignored.

SQL> select * emp;

select * emp

ERROR at line 1:

ORA-00923: FROM keyword not found where expected


SQL> select * from emp;

E_NAME E_NO DEPT D_NO DOJ

-------------------- ---------- -------------------- ---------- ---------

Kavi 124 ECE 89 25-JUN-01

Vijay 345 CSE 21 22-JUN-01

Raj 98 IT 22 22-AUG-01

Giri 100 CSE 67 22-SEP-01

SQL>> insert into emp values ( 'Chandru',700,250,'27-nov-01');

SP2-0734: unknown command beginning "> insert i..." - rest of line ignored.

SQL>> insert into emp values (Chandru,700,250,'27-nov-01');

SP2-0734: unknown command beginning "> insert i..." - rest of line ignored.

SQL> DELETE FROM EMP WHERE E_NO = 124;

TABLE IS DELETED

1 row deleted.

SQL> CREATE OR REPLACE TRIGGER VASANTH

2 BEFORE UPDATE OR INSERT OR DELETE ON EMPLOYEE

3 FOR EACH ROW

4 BEGIN

5 IF UPDATING THEN

6 DBMS_OUTPUT.PUT_LINE('TABLE IS UPDATED');

7 ELSIF INSERTING THEN

8 DBMS_OUTPUT.PUT_LINE('TABLE IS INSERTED');

9 ELSIF DELETING THEN

10 DBMS_OUTPUT.PUT_LINE('TABLE IS DELETED');

11 END IF;

12 END;
13 /

Trigger created.

SQL> select * from emp;

E_NAME E_NO DEPT D_NO DOJ

-------------------- ---------- -------------------- ---------- ---------

Vijay 345 CSE 21 22-JUN-01

Raj 98 IT 22 22-AUG-01

Giri 100 CSE 67 22-SEP-01

SQL> insert into emp values(Dhanush,5,CSE,21,'27-nov-01');

insert into emp values(Dhanush,5,CSE,21,'27-nov-01')

ERROR at line 1:

ORA-00984: column not allowed here

SQL> insert into emp values(Dhanush,5,'CSE',21,'27-nov-01');

insert into emp values(Dhanush,5,'CSE',21,'27-nov-01')

ERROR at line 1:

ORA-00984: column not allowed here

SQL> UPDATE EMP SET EMPID = 5 WHERE e_name = 'Vijay';

UPDATE EMP SET EMPID = 5 WHERE e_name = 'Vijay'

ERROR at line 1:

ORA-00904: "EMPID": invalid identifier


SQL> UPDATE EMP SET e_no = 5 WHERE e_name = 'Vijay';

TABLE IS UPDATED

1 row updated.

You might also like