0% found this document useful (0 votes)
7 views6 pages

Dbms 9 & 10 (1) .P

The document outlines experiments on PL/SQL functions, stored procedures, views, and triggers in SQL. It provides syntax and examples for creating and executing procedures and views, as well as implementing triggers for table operations. The results indicate successful execution of all commands and procedures discussed in the experiments.

Uploaded by

pratiknew03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

Dbms 9 & 10 (1) .P

The document outlines experiments on PL/SQL functions, stored procedures, views, and triggers in SQL. It provides syntax and examples for creating and executing procedures and views, as well as implementing triggers for table operations. The results indicate successful execution of all commands and procedures discussed in the experiments.

Uploaded by

pratiknew03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT NO.

AIM: To write PL/SQL(Functions)and to understand stored procedures in SQL.

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

AIM: Implementation of Views and Triggers.

OBJECTIVES: To implement views

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 :

1. Create a view of students who are in the ABC BANK


create view Branch_name as select * from branch where br_name="ABC BANK"; select
* from Branch_name;

Output:-

2. Replace a view of Students from course Computer to Mechanical.

CREATE or Replace view Branch_name as select * from branch where br_add =


"AIROLI";
select * from Branch _name;

3.Drop the created view

DROP VIEW Branch_name;

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.

->delimeter $$ create trigger


upd_customer after update on customer
for each row begin if new.cus_id < 10
then insert into customer
values(new.cus_id); end if; end;

$$

2.Drop the created trigger Drop trigger upd_customer;

RESULT:

The trigger procedure has been executed successfully for both before and after sequences

You might also like