Professional Documents
Culture Documents
COLLEGE
Arakkonam 631 003.
Department of Computer
Science
Practical Record
Name
:. Reg.No:...
Course :. Year: .
Subject : ..
Department of Computer
Science
Practical Record
Register No._________________
This
is
to
certify
the
Bonafide
Record
of
work
done
by___________________________________________
B.SC (C.S). I / II / III year (semester I / II / III / IV / V / VI) in the Computer Laboratory of
Arakkonam Arts and Science College, during the academic year 2016 2017.
Submitted
for
the
Practical
Examination
held
on
RDBMS LAB
INDEX
S.NO
DATE
PROGRAMS
Sub queries.
Procedures
Functions
Cursors
10
Triggers
PAGE
NO
SIGNATURE
EX.NO : 1
AIM
: Table creation and simple queries
DATE :
TABLE CREATION:
SQL> create table client(no number(5) primary key, name varchar2(9),address varchar2(10),city
varchar(10), state varchar(10),pincode number(6),remarks varchar(8),bal_due number(5));
Table created.
SQL> desc client;
Name
Null?
Type
NAME
VARCHAR2(9)
ADDRESS
VARCHAR2(10)
CITY
VARCHAR2(10)
STATE
VARCHAR2(10)
PINCODE
NUMBER(6)
REMARKS
VARCHAR2(8)
BAL_DUE
NUMBER(5)
INSERTION:
SQL> insert into client values(1,'lokesh','anna nagar','chennai','tamilnadu',623000,'good',6000);
1 row created.
SQL> insert into client values(2,'raja','kk nagar','chennai','tamilnadu',631000,'good',2500);
1 row created.
SQL> insert into client values(3,'subash','adyar','delhi','tamilnadu',34100,'good',4000);
1 row created.
NO
NAME ADDRESS
CITY
STATE
_______________________________________________________________________
1
lokesh
anna nagar
chennai tamilnadu
623000
good
6000
raja
kk nagar
chennai
tamilnadu
631000
good
2500
subash
adyar
delhi
tamilnadu
634100
good
4000
kumar
porur
delhi
tamilnadu
631209
good
7900
lokesh
good
6000
57
raja
kk nagar
good
2500
723
kumar
porur
delhi
good
7900
55
tamilnadu 631209
EX.NO : 2
AIM
: Constraints (Primary key, foreign key, Not Null, Referential integrity).
DATE :
PRIMARY KEY
SQL> create table prim(no number,name varchar2(10),dept varchar(10),primary key(no));
Table created.
SQL> insert into prim values (101,lokesh,Hr);
1 row created.
SQL> insert into prim values (102,'raja','operator');
1 row created.
SQL> insert into prim values (102,'subash','clerk');
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C003022) violated
SQL> select *from pri7;
NO NAME
DEPT
-------------------------------101
lokesh
102
raja
Hr
operator
FOREIGN KEY
SQL> create table foreign(no number(5),name varchar(10),dept varchar(10),foreign key(no)
references pri);
Table created.
SQL> insert into foreign values(101,'naresh','clerk');
1 row created.
SQL> insert into foreign values(102,'ajith','operater');
1 row created.
SQL> insert into foreign values(103,'sai','hr');
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.SYS_C003023) violated - parent key not
SQL> select *from foreign;
NO NAME DEPT
-----------------------------101
naresh
hr
102
ajith
operater
NAME
DEPT
-------------------------------101
vijayakumar clerk
102
null
1 row created.
maths
EX.NO : 3
AIM
: Joins (left,right and equi joins)
DATE :
SQL> /
Enter value for sno: 15
Enter value for sname: keerthana
Enter value for sage: 19
old 1: insert into std6 values(&sno,'&sname',&sage)
new 1: insert into std6 values(15,'keerthana',19)
1 row created.
SNAME
SAGE
-----
----------
----------
10
Ajith
40
11
dass
40
12
Tamilselvan
21
13
yamuna
17
15
keerthana
19
1 row created.
SQL> /
Enter value for eno: 12
Enter value for ename: Divya
Enter value for ejob: electric
old
SQL> /
Enter value for eno: 13
Enter value for ename: Nandhini
Enter value for ejob: safty
old 1: insert into em5 values(&eno,'&ename','&ejob')
new 1: insert into em5 values(13,'Nandhini','safety')
1 row created.
SQL> /
Enter value for eno: 14
Enter value for ename: vasanth
Enter value for ejob: manager
old 1: insert into em5 values(&eno,'&ename','&ejob')
new 1: insert into em5 values(14,'vasanth','manager')
1 row created.
SQL> select * from em5;
ENO
ENAME
EJOB
----------
------------
----------
10
Abinaya
clerk
11
Sona
IAS
12
Divya
electric
13
Nandhini
electric
14
vasanth
manager
SNAME
SAGE
----------
----------
----------
10 Abinaya
clerk
Ajith
40
11 Sona
IAS
dass
40
12
Divya
electric
Tamilselvan
21
13
Nandhini
electric
yamuna
17
14
vasanth
manager
----
----------
EJOB
EJOB
SNAME
SAGE
----------
----------
----------
----------
10
Abinaya
clerk
Ajith
40
11
Sona
IAS
dass
40
12
Divya
electric
Tamilselvan
21
13
Nandhini
electric
yamuna
17
keerthana
19
----------
----------
EJOB
SNAME
SAGE
----------
----------
----------
10
Abinaya
clerk
Ajith
40
11
Sona
IAS
dass
40
12
Divya
electric
Tamilselvan
21
13
Nandhini
electric
yamuna
17
14
vasanth
manager
keerthana
19
6 rows selected.
EQUI JOIN
SQL> select eno, ename, ejob, sname, sage from std6 s,em5 e where s.sno=e.eno;
ENO
ENAME
---------- ------------
EJOB
SNAME
---------- ------------
SAGE
----------
10
Abinaya
clerk
Ajith
40
11
Sona
IAS
dass
40
12
Divya
electric
Tamilselvan
21
13
Nandhini
electric
EX.NO : 4
AIM
: Sub queries
DATE :
GROUP FUNCTION
SQL> create table class(id number,name varchar(20),m1 number,m2 number,total number);
Table created.
SQL> insert into class values(&id,'&name',&m1,&m2,&total);
Enter value for id: 1001
Enter value for name: vivek
Enter value for m1: 60
Enter value for m2: 50
Enter value for total: 110
old 1: insert into class values(&id,'&name',&m1,&m2,&total)
new 1: insert into class values(1001,'vivek',60,50,110)
1 row created.
SQL> /
Enter value for id: 1002
Enter value for name: narendhar
Enter value for m1: 80
Enter value for m2: 60
Enter value for total: 140
old 1: insert into class values(&id,'&name',&m1,&m2,&total)
new 1: insert into class values(1002,'narendhar',80,60,140)
1 row created.
SQL> /
Enter value for id: 1003
Enter value for name: sasi
Enter value for m1: 80
Enter value for m2: 90
Enter value for total: 170
old 1: insert into class values(&id,'&name',&m1,&m2,&total)
NAME
---------- ----------
M1
M2
---------
----------
TOTAL
----------
1001
vivek
60
50
110
1002
narendhar
80
60
140
1003
sasi
80
90
170
GROUPING BY CLAUSE
SQL> select name,max(total)from class group by name;
NAME
----------
MAX (TOTAL)
-----------------
narendhar
140
sasi
170
vivek
110
STDDEV (M2)
--------------------
narendhar
sasi
vivek
VARIANCE (M2)
----------
------------------------
narendhar
sasi
vivek
SQL> select name,max(total)from class group by name having name not in('sasi');
NAME
MAX (TOTAL)
-------------- ------------------narendhar
140
vivek
110
EX.NO : 5
AIM
: Built-in functions (Date & time, mathematical functions)
DATE :
MATHEMATICAL FUNCTIONS:
SQL> select sin(60) from dual;
SIN(60)
----------.30481062
SQL> select cos(30) from dual;
COS(30)
---------.15425145
SQL> select tan(270) from dual
TAN(270)
----------.17883906
SQL> select exp(15) from dual;
EXP(15)
---------3269017.37
SQL> select power(5,5) from dual;
POWER(5,5)
---------3125
SQL> select abs(-75) from dual;
ABS(-75)
---------75
SQL> select ceil(25.9) from dual;
CEIL(25.9)
---------26
SQL> /
Enter value for sno: 102
Enter value for name: naresh
Enter value for dob: 13_jun_97
Enter value for doj: 12_mar_14
old 1: insert into s35 values(&sno,'&name','&dob','&doj')
new 1: insert into s35 values(102,'naresh','13_jun_97','12_mar_14')
1 row created.
SQL> /
Enter value for sno: 103
Enter value for name: vani
Enter value for dob: 09_jun_97
Enter value for doj: 13_jun_19
old 1: insert into s35 values(&sno,'&name','&dob','&doj')
new 1: insert into s35 values(103,'vani','09_jun_95','13_jun_19')
1 row created.
DOB
DOJ
--------------------------------------------------------------101 subash
27-JUL-97 09-JAN-12
102 naresh
13-JUN-97 12-MAR-14
103 vani
09-JUN-97 13-JUN-19
SQL> commit;
Commit complete.
ADD_MONTH
LAST_DAY(
ROUND(DOB
ROUND(DOB
-------- ------------------------27-JUL-97
01-JAN-97
13-JUN-97
01-JAN-97
09-JUN-97
01-JAN-97
ROUND(DOB
EX.NO : 6
AIM
: Procedures.
DATE :
Create a table stock to contain the item code, item name, current stock,
date of last purchase. Write a stored procedure to seek for an item
using item code and delete it, if the date of last purchase is before
one year from the current date. If not, update the current stock.
Queries
SQL>create table stock(itemcode number(10) primary key,itemname
varchar2(10),current_stock number(8,2),lastpurchase_date date);
Table created.
SQL> insert into stock
values(&itemcode,'&itemname',¤t_stock,'&date');
Enter value for itemcode: 1
Enter value for itemname: mobile
Enter value for current_stock: 50
Enter value for date: 15_jan_10
old
1: insert into stock
values(&itemcode,'&itemname',¤t_stock,'&date')
new
1: insert into stock values(1,'mobile',50,'15_jan_10')
1 row created.
SQL> /
Enter value for itemcode: 2
Enter value for itemname: headset
Enter value for current_stock: 20
Enter value for date: 20_mar_09
old
1: insert into stock
values(&itemcode,'&itemname',¤t_stock,'&date')
new
1: insert into stock values(2,'headset',20 ,'20_mar_09')
1 row created.
SQL> /
Enter value for itemcode: 3
Enter value for itemname: mobile
Enter value for current_stock: 90
Enter value for date: 20_may_10
old
1: insert into stock
values(&itemcode,'&itemname',¤t_stock,'&date')
new
1: insert into stock values(3,'mobile',90,'20_may_10')
1 row created.
SQL> /
Enter value for itemcode: 4
Enter value for itemname: battery
1 row created.
SQL> select * from stock;
ITEMCODE
ITEMNAME
CURRENT_STOCK
LASTPURCH
-----------------------------------------------------------------------1
mobile
50
15-JAN-10
2
headset
20
20-MAR-09
3
mobile
90
20-MAY-10
4
battery
45
20-MAR-10
SQL> create or replace procedure chkpro(itemid in varchar2,newpurchase
in varchar2)as
2 begin
3 delete from stock where itemcode=itemid and
4 months_between(sysdate,lastpurchase_date)>=12;
5 update stock set current_stock=current_stock+newpurchase where
itemcode=itemid;
6 end;
7 /
Procedure
SQL>
2
3
4
5
created.
begin
chkpro(1,50);
chkpro(2,30);
end;
/
EX.NO : 7
AIM
: Functions.
DATE :
create a table to contain phone no, user name, address of the phone
user. Write a function to search for a address using phone numbers.
Queries
SQL>create table phonebook1(phone_no number(6) primary key,username
varchar2(30),doorno varchar2(10),street varchar2(10),place
varchar2(10),pincode number(7));
Table created.
SQL> desc phonebook1;
Name
Null?
Type
------------------------------------------PHONE_NO
NOT NULL
NUMBER(6)
USERNAME
VARCHAR2(30)
DOORNO
VARCHAR2(10)
STREET
VARCHAR2(10)
PLACE
VARCHAR2(10)
PINCODE
NUMBER(7)
SQL>
2
3
4
5
Function created.
SQL> insert into phonebook1
values(&phone_no,'&username','&doorno','&street','&place',&pincode);
Enter value for phone_no: 1234
Enter value for username: lokesh
Enter value for doorno: 101
Enter value for street: main
Enter value for place: trt
Enter value for pincode: 631209
old
1: insert into phonebook1
values(&phone_no,'&username','&doorno','&street','&place',&pincode)
new
1: insert into phonebook1
values(1234,'lokesh','101','main','trt',631209)
1 row created.
SQL> /
Enter value for phone_no: 5678
Enter value for username: subash
Enter value for doorno: 102
Enter value for street: big
Enter value for place: ajj
Enter value for pincode: 631258
old
1: insert into phonebook1
values(&phone_no,'&username','&doorno','&street','&place',&pincode)
new
1: insert into phonebook1
values(5678,'subash','102','big','ajj',631258)
1 row created.
SQL> select * from phonebook1;
PHONE_NO
USERNAME
DOORNO
STREET
PLACE
PINCODE
-------------------------------------------------------------1234
lokesh
101
main
trt
631209
5678
subash
102
big
ajj
631001
EX.NO : 8
AIM
: Functions with exception handling capability
DATE :
Create a table to store the details of the Aluminus in an institution. Write a PL/SQL block to
change address of a particualr alumni. Write proper exceptions and appropriate error messages.
SQL> CREATE TABLE ALUMNI(ALUMID NUMBER(7)PRIMARY KEY,ALUMNAME
CHAR(20),ADDR CHAR(15),DEGREE CHAR(5),COMPLETED_YR NUMBER(4));
Table created.
SQL> DESC ALUMNI
Name
Null?
------------------------------- -------ALUMID
NOT NULL
ALUMNAME
ADDR
DEGREE
COMPLETED_YR
Type
-------NUMBER(7)
CHAR(20)
CHAR(15)
CHAR(5)
NUMBER(4)
for
for
for
for
for
alumid: 1002
alumname: LOKESH
addr: ARNI
degree: BSC
compleyr: 2007
old
1: INSERT INTO ALUMNI
VALUES(&ALUMID,'&ALUMNAME','&ADDR','&DEGREE',&COMPLEYR)
new
1: INSERT INTO ALUMNI VALUES(1002,'LOKESH','ARNI','BSC',2007)
1 row created.
SQL> /
Enter value
Enter value
Enter value
Enter value
Enter value
for
for
for
for
for
alumid: 1003
alumname: KAYAL
addr: POLUR
degree: BSC
compleyr: 2007
old
1: INSERT INTO ALUMNI
VALUES(&ALUMID,'&ALUMNAME','&ADDR','&DEGREE',&COMPLEYR)
new
1: INSERT INTO ALUMNI VALUES(1003,'KAYAL','POLUR','BSC',2007)
1 row created.
SQL> /
Enter value for alumid: 1005
Enter value for alumname: HARIJOTHI
Enter value for addr:
Enter value for degree: BA
Enter value for compleyr: 2008
old
1: INSERT INTO ALUMNI
VALUES(&ALUMID,'&ALUMNAME','&ADDR','&DEGREE',&COMPLEYR)
new
1: INSERT INTO ALUMNI VALUES(1005,'HARIJOTHI','','BA',2008)
1 row created.
SQL> /
Enter value for alumid: 1006
Enter value for alumname:HEMAVATHY
Enter value for addr: VELAM
Enter value for degree: BA
Enter value for compleyr: 2008
old
1: INSERT INTO ALUMNI
VALUES(&ALUMID,'&ALUMNAME','&ADDR','&DEGREE',&COMPLEYR)
new
1: INSERT INTO ALUMNI VALUES(1006,'HEMAVATHY','VELAM','BA',2008)
1 row created.
SQL> SELECT * FROM ALUMNI;
ALUMID ALUMNAME
ADDR
DEGRE
COMPLETED_YR
-------------------------------------------------------1001 HARIPRASATH
VELLORE
BSC
2004
1002
1003
1005
1006
LOKESH
KAYAL
HARIJOTHI
HEMAVATHY
ARNI
POLUR
VELAM
BSC
BSC
BA
BA
2007
2007
2008
2008
SQL> ed excep
declare
a alumni.alumid%type:=&alumid;
b alumni.alumname%type;
c alumni.addr%type;
d alumni.degree%type;
e alumni.completed_yr%type;
degree_null exception;
begin
select alumid,alumname,addr,degree,completed_yr into a,b,c,d,e
from alumni where alumid=a;
if d is null then raise degree_null;
else
dbms_output.put_line('THE RETRIEVED ROW IS........');
dbms_output.put_line('ALUMID ALUMNAME ADDR
DEGREE YEAR');
dbms_output.put_line('=====================================');
dbms_output.put_line(a||'
'||b||'
'||c||'
'||d||'
'||e);
dbms_output.put_line('====================================');
end if;
c:='&addrforupdate';
update alumni set addr=c where alumid=a;
select alumid,alumname,addr,degree,completed_yr into a,b,c,d,e
from alumni where alumid=a;
dbms_output.put_line('Now the new address of same rec is......');
dbms_output.put_line(a||'
'||b||'
'||c||'
'||d||'
'||e);
exception
when degree_null then
dbms_output.put_line('invalid degree in this REC.... PL INSERT
DEGREE...');
when no_data_found then
dbms_output.put_line('alumni ID= ' ||A||' IS NOT PRESENT...');
end;
/
to 1 characters
alumid: 1002
a alumni.alumid%type:=&alumid;
a alumni.alumid%type:=1002;
addrforupdate: arni
c:='&addrforupdate';
c:='arni';
EX.NO : 9
AIM
: Cursors
DATE :
SQL> create table cur(sno number,m1 number,m2 number,m3 number,m4 number,m5
number,total number,avrg real,res varchar(5));
Table created.
SQL> insert into cur(sno,m1,m2,m3,m4,m5) values(&sno,&m1,&m2,&m3,&m4,&m5);
Enter value for sno: 1
Enter value for m1: 45
Enter value for m2: 65
Enter value for m3: 43
Enter value for m4: 46
Enter value for m5: 78
old 1: insert into cur(sno,m1,m2,m3,m4,m5) values(&sno,&m1,&m2,&m3,&m4,&m5)
new 1: insert into cur(sno,m1,m2,m3,m4,m5) values(1,45,65,43,46,78)
1 row created.
SQL> /
Enter value for sno: 2
Enter value for m1: 45
Enter value for m2: 34
Enter value for m3: 56
Enter value for m4: 76
Enter value for m5: 56
SQL> /
Enter value for sno: 3
Enter value for m1: 34
Enter value for m2: 45
Enter value for m3: 56
Enter value for m4: 76
Enter value for m5: 67
old 1: insert into cur(sno,m1,m2,m3,m4,m5) values(&sno,&m1,&m2,&m3,&m4,&m5)
new 1: insert into cur(sno,m1,m2,m3,m4,m5) values(3,34,45,56,76,67)
1 row created.
SQL> /
Enter value for sno: 4
Enter value for m1: 23
Enter value for m2: 34
Enter value for m3: 45
Enter value for m4: 56
Enter value for m5: 67
old 1: insert into cur(sno,m1,m2,m3,m4,m5) values(&sno,&m1,&m2,&m3,&m4,&m5)
new 1: insert into cur(sno,m1,m2,m3,m4,m5) values(4,23,34,45,56,67)
1 row created.
SQL> /
Enter value for sno: 5
EXPLICIT
SQL> declare
2 cursor c2 is select sno, m1, m2, m3, m4, m5 from cur;
3 no number;
4 x1 number;
5 x2 number;
6 x3 number;
7 x4 number;
8 x5 number;
9 tot number;
10 avr real;
11 begin
12 open c2;
13 loop
14 fetch c2 into no,x1,x2,x3,x4,x5;
15 tot:=(x1+x2+x3+x4+x5);
16 avr:=(tot/5);
17 update cur set total=tot,avrg=avr where sno=no;
18 if (x1>=50 and x2>=50 and x3>=50 and x4>=50 and x5>=50) then
19 update cur set res='p' where sno=no;
20 else
21 update cur set res='f' where sno=no;
22 end if;
23 exit when c2%notfound;
24 end loop;
25 close c2;
26 end;
27 /
PL/SQL procedure successfully completed.
M2
45
65
43
46
78
277
55.4
45
34
56
76
56
267
53.4
34
45
56
76
67
277
55.6
23
34
45
56
67
225
45
67
45
56
98
78
344
68.8
------------------------------------------------------------------------------
IMPLICIT
SQL> declare
2 no cur.sno%type;
3 begin
4 no:=&no;
5 delete from cur where sno=no;
6 if sql%notfound then
7 dbms_output.put_line('values not founded');
8 else
9 dbms_output.put_line('values founded');
10 end if;
11 end;
12 /
Enter value for no: 4
old 4: no:=&no;
new 4: no:=4;
PL/SQL procedure successfully completed.
EX.NO :10
AIM
: Triggers
DATE :
votername varchar(15),
wardno number(5),
dob date,
addr varchar(25));
Table created.
SQL> insert into vot1 values(&voterid,'&votername',&wardno,'&dob','&addr');
Enter value for voterid: 118
Enter value for votername: Raja
Enter value for wardno: 11
Enter value for dob: 04_jun_1996
Enter value for addr: kk nagar
old 1: insert into vot1 values(&voterid,'&votername',&wardno,'&dob','&addr')
new 1: insert into vot1 values(118,'raja',11,'04_jun_1996','kk nagar')
1 row created.
SQL> /
SQL> /
Enter value for voterid: 197
Enter value for votername: subash
Enter value for wardno: 19
Enter value for dob: 10_oct_1981
Enter value for addr: new apt
old 1: insert into vot1 values(&voterid,'&votername',&wardno,'&dob','&addr')
new 1: insert into vot1 values(197,'balu',19,'10_oct_1981','new apt')
1 row created.
SQL> /
Enter value for voterid: 202
Enter value for votername: dass
Enter value for wardno: 20
Enter value for dob: 28_oct_1983
Enter value for addr: gandhi nagar
old 1: insert into vot1 values(&voterid,'&votername',&wardno,'&dob','&addr')
new 1: insert into vot1 values(202,'rajesh',20,'28_oct_1983','gandhi nagar')
1 row created.
SQL> select * from vot1;
ADDR
-------------------------------------------------------------------------------------118
raja
11
04-JUN-96
kk nagar
235
naresh
23
02-MAY-78
akm
197
subash
19
10-OCT-81
new apt
202
dass
20
28-OCT-83
gandhi nagar
description varchar(15));
Table created.
SQL> insert into vot2 values(&voterid,'&description');
Enter value for voterid: 118
Enter value for description: same
old 1: insert into vot2 values(&voterid,'&description')
new 1: insert into vot2 values(118,'same')
1 row created.
SQL> /
Enter value for voterid: 235
Enter value for description: same
old 1: insert into vot2 values(&voterid,'&description')
new 1: insert into vot2 values(235,'same')
1 row created.
SQL> /
Enter value for voterid: 197
Enter value for description: same
old 1: insert into vot2 values(&voterid,'&description')
new 1: insert into vot2 values(197,'same')
1 row created.
SQL> /
Enter value for voterid: 202
Enter value for description: same
old 1: insert into vot2 values(&voterid,'&description')
new 1: insert into vot2 values(202,'same')
1 row created.
same
235
same
197
same
202
same
WARDNO
DOB
ADDR
raja
11
20-JAN-82
kk nagar
197
subash
19
10-OCT-81
new apt
202
naresh
20
28-OCT-83
gandhi nagar
DESCRIPTION
---------------
118
same
235
shifted
197
same
202
same