0% found this document useful (0 votes)
4 views

RDBMS Lab Program

RDBMS
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)
4 views

RDBMS Lab Program

RDBMS
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/ 2

7 a)

Create table customers(id,name,age,address,salary)


/* trigger code*/

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;
/
Trigger Created
b)Perform the DMl Operation
/*Insert Values to the table using Insert Command*/
Output:
Old Salary:
New salary:
Salary Difference:
/*Update using update statement*/
Output:
Old Salary:
New salary:
Salary Difference:
8) Recursive Function
DECLARE
num number;
factorial number;

FUNCTION calculateFact(x number)


RETURN number
IS
f number;
BEGIN
IF x = 0 THEN
f := 1;
ELSE
f := x * calculateFact(x-1);
END IF;
RETURN f;
END;

BEGIN
num:= 6;
factorial := calculateFact(num);
DBMS_OUTPUT.PUT_LINE(' Factorial '|| num || ' is ' || factorial);
END;

You might also like