100% found this document useful (1 vote)
219 views8 pages

DBMS Lab-9 - 20208098

1. This document contains PL/SQL code assignments submitted by a student named Puja Kumar. 2. The assignments include programs to print "Hello World", invert a number, find the greatest of three numbers, calculate area of a circle, find factorial of a number, and calculate months between two dates. 3. The final assignment involves creating a table to store account information, inserting sample data, and deducting Rs. 100 from accounts with balances less than Rs. 1000.
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
100% found this document useful (1 vote)
219 views8 pages

DBMS Lab-9 - 20208098

1. This document contains PL/SQL code assignments submitted by a student named Puja Kumar. 2. The assignments include programs to print "Hello World", invert a number, find the greatest of three numbers, calculate area of a circle, find factorial of a number, and calculate months between two dates. 3. The final assignment involves creating a table to store account information, inserting sample data, and deducting Rs. 100 from accounts with balances less than Rs. 1000.
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/ 8

NAME : PUJA KUMARI REG NO.

: 20208098
BRANCH : IT (B)

DATABASE MANAGEMENT SYSTEM


ASSIGNMENT - 9
1. Write a PL/SQL program to print “HELLO WORLD”.

Code:- begin
dbms_output.put_line('HELLO WORLD'); end;

2. Write a PL/SQL code for inverting a number. (Example: 1234 – 4321)

Code:- declare
num
varchar2(5):='1234'; len
number(2); revnum
varchar2(5); begin len :=
length(num); for i in
reverse 1.. len
loop
revnum := revnum || substr(num,i,1);
end loop;
dbms_output.put_line('given number ='|| num);
dbms_output.put_line('reverse number ='|| revnum);
end;
4. Write a PL/SQL code to find the greatest number among three with Anonymous blocks.

Code:- declare
a number:=30;
b number:=17;
c number:=50;
begin
dbms_output.put_line('a='||a||' b='||b||' c='||c);
if a>b AND a>c
then
dbms_output.put_line('a is greatest');
else
if b>a AND b>c
then
dbms_output.put_line('b is greatest');
else
dbms_output.put_line('c is greatest');
end if; end if; end;

5. Write a PL/SQL code to calculate the area of a circle where radius takes values from 3 to 7.
Store the calculated area in Table AREA. The schema of table is given below: AREA (Radius, Area)
Code:-
create table Area
(
radius float NOT NULL, area
float NOT NULL
);
DECLARE
r float:=5; ar
float;
pi constant number:= 3.14; BEGIN
ar:=pi*r*r;
insert into Area (radius,area) values (r,ar);
dbms_output.put_line(ar);
END;

select * from Area;

6. Write a PL/SQL program to accept a number and find the factorial of the number.

Code:-
DECLARE
a integer:=5;
b integer:=1;
BEGIN
IF a=0
THEN
dbms_output.put_line(b);
ELSIF a<0

THEN
dbms_output.put_line('Not Possible');
ELSE
while a>1 loop
b:=b*a; a:=a-1; end
loop;
dbms_output.put_line(b);
END IF;
END;

7. Write a PL/SQL program to display the months between two dates of a year

Code:-
SELECT MONTHS_BETWEEN (TO_DATE('02-02-2015','MM-DD-YYYY'), TO_DATE('02-06-2014','MM-DD-YYYY')
)
"Months" FROM DUAL

Q8) Create an Account_Master table & insert the tuples as given the question. Write a PL/SQL code that
will accept an account number from user. If the balance of account is less than minimum balance (i.e
1000) deducts Rs 100 from balance.
The schema of table is given below:
Acc_Master (acct_no, acct_holder_name , Balance);
Create table Account_Master(acct_no number(5) primary key,
acct_holder_name varchar2(10),balancenumber(10)); Tuples to be inserted are:
insert into Account_Master values(1,'John',1000);
insert into Account_Master values(2,'Denis',100); insert
into Account_Master values(3,'Albert',1100); insert into
Account_Master values(4,'Charles',700); insert into
Account_Master values(5,'Darwin',1700);

Code:-
create table Account_Master(acct_no integer primary key,acct_holder_name varchar2(10),balance integer);
insert into Account_Master values(1,'John',1000); insert into Account_Master values(2,'Denis',100); insert
into Account_Master values(3,'Albert',1100); insert into Account_Master values(4,'Charles',700); insert
into Account_Master values(5,'Darwin',1700); BEGIN
update Account_Master set balance=balance-100 where balance<1000;
END;

select * from Account_Master

You might also like