Dbms 9 & 10 (1) .P
Dbms 9 & 10 (1) .P
Theory:-
FUNCTION:
A function is a subprogram that computes a value.syntax
Create or replace function<function_name>[argument]
Return datatype is (local
declaration) begin
(executable statements)[Exception] (exception
handlers)End
PROCEDURE:
create [or replace] procedure procedurename
[parameter[in/out/in/in out] datatype [:=/default
expression] [(parameter)]is/as declaration begin
pl/sql codes [exception] end
Input:-
DELIMITER $$
create procedure temp_function()
begin select * from Customer;
END $$
DELIMITER ;
CALL temp_function();
Output:-
RESULT: Thus the functions and stored procedures are executed in SQL.
Problems:
1) procedure to find whether a given number is odd or even
2) procedure to display 1-10 using while
3) Procedure to display some numbers lesser than given number.
RESULT: The trigger procedure has been executed successfully for both before and after
sequences.
EXPERIMENT NO.10
THEORY:
A view is the tailored presentation of data contained in one or more table andcan also be said
as restricted view to the data‟s in the tables. A view is a “virtual table” or a “stored query”
which takes the output of a query and treats it as a table. The table upon which a view is
created is called as base table . A view is a logical table based on a table or another view. A
view contains no data of itsown but is like a window through which data from tables can be
viewed or changed. The tables on which a view is based are called base tables. The view is
stored as a
SELECT statement in the data dictionary .
Advantages of a view:
a. Additional level of table security.
b. Hides data complexity.
c. Simplifies the usage by combining multiple tables into a single table
Creating a view:
Syntax:
Create[or replace] view <view name>
AS
Sub query
[with check option] Create
or Replace a view:
Create or replace view
<view name>
AS
SUB QUERY
[with check option]
[with read only];
Dropping a view:
Drop view <view name>;
[Document title]
Applications :
Output:-
Output:
-
Result
Thus the view creation commands are executed successfully.
Part B. TRIGGER
AIM
Create a Trigger for EMP table it will update another table SALARY while inserting values
OBJECTIVES
To develop and execute a Trigger for Before and After update/Delete/Insert operations on
a table
THEORY:
PROCEDURE:
step 1: start
step 2: initialize the trigger with specific table id.
step 3:specify the operations (update, delete, insert) for which the trigger has tobe executed.
step 4: execute the trigger procedure for both before and after sequences
step 5:carryout the operation on the table to check for trigger execution.
step 6: stop
Trigger Syntax
CREAE[OR REPLACE] TRIGGER <Trigger_name>
[<ENABLE | DISABLE>]
<BEFORE | AFTER>
<INSERT | UPDATE | DELETE>
ON <Table_Name> [FOR
EACH ROW]
DECLARE
<Variable_name>;
BEGIN
<Trigger _code>;
END
1. Create a trigger to insert a values in customer section when update operation is carried out in customer
table whose cus_id < 10.
$$
RESULT:
The trigger procedure has been executed successfully for both before and after sequences