0% found this document useful (0 votes)
4 views2 pages

RDBMS Lab Programs with Solutions

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 views2 pages

RDBMS Lab Programs with Solutions

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

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 ([Link] > 0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :[Link] - :[Link];
dbms_output.put_line('Old salary: ' || :[Link]);
dbms_output.put_line('New salary: ' || :[Link]);
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