0% found this document useful (0 votes)
2 views4 pages

PL SQL1

The document contains assignments related to PL/SQL, including writing code to calculate factorials, manage bus records with remarks based on seat counts, and updating employee salaries. It also covers the use of cursors in PL/SQL, detailing implicit and explicit types, and includes a section on triggers for database security, specifically for tracking changes in a client master table. The document provides code examples for each assignment and explains the structure and functionality of PL/SQL blocks.

Uploaded by

SOURAV
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)
2 views4 pages

PL SQL1

The document contains assignments related to PL/SQL, including writing code to calculate factorials, manage bus records with remarks based on seat counts, and updating employee salaries. It also covers the use of cursors in PL/SQL, detailing implicit and explicit types, and includes a section on triggers for database security, specifically for tracking changes in a client master table. The document provides code examples for each assignment and explains the structure and functionality of PL/SQL blocks.

Uploaded by

SOURAV
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/ 4

Assignment:01 (PL/SQL)

2.1) Write a PL/SÌL block which will accept a value from the user and it will
insert the factorial result into a table called Result.

PL/SQL Code:
declare
i number(5);
fnum number(5);
result number(10);=1;

begin
i-l;
fnum:= &fnum;
while(i<=fnum);
result:=result*i;

i:=it1;
end loop;
insert into fact values(fnum, result);
dbms output.put line("fact=" |result);
end;

upper bound values


Q.2) Write aPL/SQL code that will accept lower bound and
FACTORIAL.
and find the their factorial and store the result in table

PL/SQL Code:
declare
nnumber(10);
i number(10):=1;
sm number(20):=0;
begin
n:=&n;
while(i<=n)
loop
sm:=smti;
i:=it1;
end loop;
dbms_output.put_line('sum=" sm);
end;
3) Create abus table with the
Bus id number, no of seats number,
following
attributes
remarks varchar.
Insert first five records for bus id and no of
scats.
Writeea PL/SOL block to put the remarks in the following
1) If no_ of seats<50, remarks fairly smal. way
2) If no of seats<100, remarks little bigger.
3) If no of seats>100, remarks-lots of sets.

Ans.:
>create table BUS values(BUS ID number(2), seats number(5),Remarks varchar(15);
i)
>insert into BUS(BUS _ID,seats)
ii) values(1,40);
>insert into BUS(BUS D,seats) values(2.60):
>insert into BUS(BUS D,seats) values(3,70):
>insert into BUS(BUS_D,seats) values(4,110);
PL/SQL code:
declare
mbus id BUS054.BUS IDotype; .
mseats BUSO54.seats%type:
mremarks BUS054.remarks%type;
begin
mbus id :=&mbus id:;
select seats into mseats from BUS054 where BUS ID=mbus id:
if mseats<50 then
mremarks:= 'Fairly Small';
mremarks ='Little Bigger';
elsif mseats<100 then
else
mremarks:='Lots of seats';
end if;
update BUSO54 set Remarks=mremarks where BUS ID=mbus id;
Exception
when no data found then
dbms_output.put line(mbus_id ||'is not present in the
table');
end;

Assignment :02 ( CURSOR)


it processes the data for execution of
Cursor is the internal working area of oracle engine where
transaction.
Cursor is of two types:
1. Implicit cursor (Cursor is created by engine itself)
2. Explicit cursor (Cursor is created by user)
o CursorSystem Variables)
Four attributesof
For implicit and explicit status of cursor
Yo1sopen, %found. %notfound, %rowcount

true when cursor is


I. %isopen return
2. %found’ return true if data 1s Opened successfully, like
fetch sSuccessfully, otherwise
select itfname
returnsform
false. emp where
deptno=10;
true if data
3.%notfound return from database is
4.%rowcount’return number of
not fetched
rows to be executed in atransaction.

Q.1) AHRD Manager decided to raise the salary of employee by 15%. Write a
PL/SQL block which accept employee number and update
the the record
table. Display the appropriate message on nonexistence of salary in Employee
in the
employee table.
PL/SQL code:
Declare
Employee no number(4);
Begin
Employee no;=&employee_no;
Update employee set sal-sal+sal*.15 where empno-employee no;
if sq2% not found then raise no data found:
end if;
Exception
When no data found then
Dbms_output.put_line(»employee number is not found' ):
End;
Assignment::03 (Trigger)
[Making security of Database)
A trigger is a database object which resides in database that fires or execute implicitly when an
event Occurs.
A trigger has three components:
1) The trigger statement
2) Trigger restriction
3) Trigger action
The event for which trigger fires is defined in the trigger statement and it's restriction.
Trigger is of two types:
1. Before trigger (Before event occurs).
2. After trigger (After event or commit occurs).
Two categories of trigger:
1. Row trigger (For each row trigger 1s fired)
2. Statement trigger (It is independent of number of rows. Only one time trigger is fired
and it is independent of no of rows).
Q.1: Create tables client_master and audit master and write a before trigger for
updation, deletion and insertion for each row on client_master, i.e. the system must
keep track of the records that are being inserted, deleted or uploaded on
client master. The original record detail and date of operation along with user jd
are stored in audit master table and then the insertion, updation and deletion is
allowed to go througlh.
Ans. 1
client master
>create table client master(client no varchar2(5) primary key, name varchar2(10).
balance due number(10,2);
Singert in to client master(client no,name.balance due) values('c11'.Abhishek,7000.20)
Sinsert in to client_master(client no,name,balance due) values('c12,Komal,8000);
binsert in to client_master(client no,name,balance due) values('c13", 'Raju', 10000);

Audit master
>create table audit master(client no varchar2(5),name varchar2(10), balance due

number(10,2), operation varchar2(10), op_date date):


PL/SQL for creating a trigger tri054 before update, delete or insert on client master054 for each row
PL/SQL code
Create or replace trigger lol before UPDATE OR INSERT OR DELETE on client_master for
each row
Declare
mcl no varchar2(5);
mname varchar2(10);
mop varchar2(10);
mbalance number(10,2);
begin
IF INSERTING THEN
mcl no:=:new.client no;
mname:=:new.name;
mbalance:=:new.bala due, mop:=NSERT";
ELSIF UPDATING THEN
mcl no:=:old.client no;
mname:=:old.name:mbalance:=:old.bala due; mop:= "UPDATE;
ELSIF DELETING THEN
mbalance:=:old.bala due: mon .
mcl no:=:old.client no; mname:=F:old.name;

'DELETE;
END IF;
insert into audit master903 values(mcl no,mname,mbalance,mop,sysdate);
end;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy