You are on page 1of 5

1. Create a Table Bank which contains the following Details.

Account Number(Primary Key), Name, Address, & Amount.

SQL> set sqlprompt prathees-->


prathees-->create table bank(acno number(20) primary key,name varchar(20),address
varchar(20),amount number(10));

Table created.

prathees-->insert into bank values(12345,'prathees','north street',1000);

1 row created.

prathees-->ed;
Wrote file afiedt.buf

1* insert into bank values(23456,'hari','south street',2000)


prathees-->/

1 row created.

prathees-->ed
Wrote file afiedt.buf

1* insert into bank values(34567,'nachiar','west street',3000)


prathees-->/

1 row created.

prathees-->ed
Wrote file afiedt.buf

1* insert into bank values(45678,'ram','east street',5000)


prathees-->/

1 row created.

prathees-->select * from bank;

ACNO NAME ADDRESS AMOUNT


--------- -------------------- -------------------- ---------
12345 prathees north street 1000
23456 hari south street 2000
34567 nachiar west street 3000
45678 ram east street 5000

Write a PL/SQL cursor program to display all the record available in the bank.

declare
cursor drk is select * from bank;
tacno bank.acno%type;
tname bank.name%type;
taddress bank.address%type;
tamount bank.amount%type;
begin
open drk;
loop
fetch drk into tacno,tname,taddress,tamount;
exit when drk%notfound;
dbms_output.put_line('*******************');
dbms_output.put_line('account no:' ||tacno);
dbms_output.put_line('name:' ||tname);
dbms_output.put_line('address:' ||taddress);
dbms_output.put_line('amount:' ||tamount);
end loop;
close drk;
end;

*******************
account no:12345
name:prathees
address:north street
amount:1000
*******************
account no:23456
name:hari
address:south street
amount:2000
*******************
account no:34567
name:nachiar
address:west street
amount:3000
*******************
account no:45678
name:ram
address:east street
amount:5000

PL/SQL procedure successfully completed.

2. Create a Table Student which contains the following Details.


Register Number (Primary Key), Student Name, DBMS, SE, ORACLE,
Python & City Name.

prathees-->create table mark(regno varchar(10) primary key,name varchar(20),dbms


number(10),se number(10),oracle number(10),python number(10),city varchar(20));

Table created.

prathees-->insert into mark values('23spca056','prathees',60,70,80,78,'sattur');

1 row created.

prathees-->ed
Wrote file afiedt.buf
1* insert into mark values('23spca057','satheesh',65,70,87,89,'vnr')
prathees-->/

1 row created.

prathees--> ed
Wrote file afiedt.buf

1* insert into mark values('23spca051','ragul',80,80,98,90,'vnr')


prathees-->/

1 row created.

prathees-->ed
Wrote file afiedt.buf

1* insert into mark values('23spca034','prasana',69,70,69,80,'vnr')


prathees-->/

1 row created.

prathees-->ed
Wrote file afiedt.buf

1* insert into mark values('23spca035','sakthi',79,80,79,90,'madurai')


prathees-->/

1 row created.

prathees-->select * from mark;

REGNO NAME DBMS SE ORACLE PYTHON CITY


---------- -------------------- --------- --------- --------- ---------
--------------------
23spca056 prathees 60 70 80 78 sattur
23spca057 satheesh 65 70 87 89 vnr
23spca051 ragul 80 80 98 90 vnr
23spca034 prasana 69 70 69 80 vnr
23spca035 sakthi 79 80 79 90 madurai

prathees-->commit;

Commit complete.

Write a PL/SQL cursor program to perform following operations.


? Calculate total & average for each student

declare
cursor drk is select * from mark;
tregno mark.regno%type;
tname mark.name%type;
tdbms mark.dbms%type;
tse mark.se%type;
toracle mark.oracle%type;
tpython mark.python%type;
tcity mark.city%type;
tot number;
average float;
begin
open drk;
loop
fetch drk into tregno,tname,tdbms,tse,toracle,tpython,tcity;
exit when drk%notfound;
tot:=tdbms+tse+toracle+tpython;
average:=tot/4;
dbms_output.put_line('*******************');
dbms_output.put_line('reg no:' ||tregno);
dbms_output.put_line('name:' ||tname);
dbms_output.put_line('dbms:' ||tdbms);
dbms_output.put_line('software engineering:' ||tse);
dbms_output.put_line('oracle:' ||toracle);
dbms_output.put_line('python:' ||tpython);
dbms_output.put_line('city:' ||tcity);
dbms_output.put_line('total:' ||tot);
dbms_output.put_line('average:' ||average);
end loop;
close drk;
end;

*******************
reg no:23spca056
name:prathees
dbms:60
software engineering:70
oracle:80
python:78
city:sattur
total:288
average:72
*******************
reg no:23spca057
name:satheesh
dbms:65
software engineering:70
oracle:87
python:89
city:vnr
total:311
average:77.75
*******************
reg no:23spca051
name:ragul
dbms:80
software engineering:80
oracle:98
python:90
city:vnr
total:348
average:87
*******************
reg no:23spca034
name:prasana
dbms:69
software engineering:70
oracle:69
python:80
city:vnr
total:288
average:72
*******************
reg no:23spca035
name:sakthi
dbms:79
software engineering:80
oracle:79
python:90
city:madurai
total:328
average:82

PL/SQL procedure successfully completed.

You might also like