RDBMS SOLUTION
ASSIGNMENT 6
SET B Q.3 SOLUTION
Write a trigger which will fire before insert or update on Bill having total less than or equal to 10 Rs. (Raise user defined exception and give appropriate message)
Source code:
/*Set b Q 3 solution */
create or replace trigger t7 before insert or update on menu for each row
declare
t6 exception;
begin
if(:new.price<=10) then
raise t6;
end if;
exception
when t6 then
dbms_output.put_line('Price should be greater than 10');
end;
/* Explaination:
- "Create or replace trigger t6" - this line indicates that a new trigger named "t6" should be created or replaced if it already exists.
- "before insert or update on menu for each row" - this line specifies that the trigger should execute before any row is inserted or updated in the "menu" table.
- ":new" - refers to the values being inserted or updated in the current row.
- "if(:new.price<=10) then" - this line checks if the value of "price" in the current row is less than or equal to 10. If it is, then the "t6" exception is raised.
- "raise t6;" - this line raises the "t6" exception if the "if" condition is true.
- "Exception when t6 then" - this line specifies that if the "t6" exception is raised, the following code block should be executed.
- "dbms_output.put_line('Price should be greater than 10');" - this line prints a message to the console indicating that the value of "price" is not valid.
*/
0 Comments