Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Step 1) Create A Table Called Customers & Execute The Following

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Step 1) Create a table called customers & execute the following.

create table customers (


id number(10),
name varchar2(30),
age number(10),
address varchar2(50),
salary number(10));

step 2) Insert at least four rows into the employee table.


1. insert into customers (id, name, age, address, salary)

values(101,'Kumar',45, 'Bengalure',20000);
2. insert into customers (id, name, age, address, salary)

values(102,'Rohan',42, 'Tumkuru', 10000);


3. insert into customers (id, name, age, address, salary)

values(103,'Kumar',38, 'Belagavi', 9000);


4. insert into customers (id, name, age, address, salary)

values(104,'Chandu',35, 'Tiptur ', 9000);

step 3) create trigger.


CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW WHEN (NEW.ID > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
END;

Step 4) to check whether trigger works during INSERT statement.


5. insert into customers (id, name, age, address, salary)

values(105,'Keerthi',36, 'Mangaluru',9000);

Step 5) to check whether trigger works during UPDATE statement.


update customers SET salary=10000 where id=105;

Step 6) to check whether trigger works during DELETE statement.


delete from customers where id=105;

You might also like