Upload
durgasnstech
View
49
Download
0
Tags:
Embed Size (px)
Citation preview
SNS COLLEGE OF TECHNOLOGY
COIMBATORE-35
DBMS LAB LABORATORY MANUAL
SNSCT/TLE/61
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ISO 9001- 2000
SNS COLLEGE OF TECHNOLOGY
COIMBATORE-35
DBMS LAB LABORATORY MANUAL
SNSCT/TLE/61
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
ISO 9001- 2000
PREPARED BY: APPROVED BY:
SIGNATURE: SIGNATURE:
DATE: DATE:
CONTENTS
DS/CONT ISSUE NO - REVISION DATE -
EFFECTIVE DATE - ISSUE DATE -
S.NO DOCUMENTS DOCUMENT
REF
REVISION
1 2 3 4 5 6 7 8 9 PAGE
1 Content DS/CONT
2 Distribution
List
DS/DIST
3 Responsibilitie
s
DS/RES
4 Organization DS/ORG
5 Instruction to
the students
DS/INS
6 Format for the
Intent Slip
DS/IND
7 Syllabus DS/SYL
8 List of
Experiments
DS/LIST
9 Lab
Experiments
DS/EXP
SL.NO DESIGNATION
TYPE ELECTRONIC/ HARDCOPY
ACKNOWLEDGED
1 MANAGEMENT
REPRESENTATIVEELECTRONIC &HARD COPY
2
PRINCIPAL
ELECTRONIC &HARD COPY
3
HEAD OF THE DEPARTMENT
ELECTRONIC &HARD COPY
4 ISO CO-ORDELECTRONIC &HARD COPY
DISTRIBUTION LISTDBMS/DIST ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
RESPONSIBILITIES
DS/RES ISSUE NO - REVISION DATE -
EFFECTIVE DATE - ISSUE DATE -
HEAD OF THE DEPARTMENT:
HOD is in consultation with faculty decides the equipments
necessary to the lab at the end of the every semester and necessary steps
are taken to HOD to procure them. Steps are also taken to replace the
equipments which are beyond repair.
LAB-IN-CHARGE:
The whole class is divided into two batches according to the class
strength and will go to their respective labs according to the timetable.
Each student is allotted with an individual system.
The lab in-charge is assisted by a additional faculty in the practical
class.
If the student enters the lab, attendance is taken and a record for the
previous experiment is collected.
The knowledge of the student about the experiment /programs/logics
(whichever is applicable) is checked through viva and they are allowed
to do practical after correcting the observation note books.
The performance of the student is monitored during the lab sessions.
After completing the experiments ,students must show their programs
and results to their respective faculty and get it verified.
Completion of all experiments ,model examination is conducted similar
to University Examination.
LAB ASSISTANT:
Every day morning lab assistant physically verifies the equipments. If
any fault is found with them, they will take note of and try to rectify
them.
Laboratories are kept neat and clean with the help of sweepers and
cleaners.
The faults will be attended by the concern Faculty/System
administrator/Lab in-charge.
Condition which requires the attention of authorized service personnel
will be informed the HOD.
All the system is overhauled after the practical examination of every
semester.
Nothing down the damages / breakages and deficiencies on completion
of the lab classes.
ORGANIZATION CHART
DS/ORG ISSUE NO - REVISION DATE -
EFFECTIVE DATE - ISSUE DATE -
PROCEDURE
The Organization is formulated to ensure effective communication
with all concerned. The flow of communication is from the lab-n-charge to lab
assistants and students.
INSTRUCTION TO THE STUDENTS
DS/INS ISSUE NO - REVISION DATE -
EFFECTIVE DATE - ISSUE DATE -
Students should not wear foot wares inside the laboratory.
Students should enter his/her name,system number and in time while
entering into the laboratory.
Students should submit his/her observation note before they start
working in the system.
Completion of programs/experiments,verification of the program should
be obtained from the concern staff-in-charge.
Students should arrange the chair and the system in the proper manner
and they should enter the leaving time in the lab register.
DBMS/INDFORMAT FOR INDENT SLIP
ISSUE NO. :REVISION NO :ISSUE DATE :EFFECTIVE DATE :
S.NO
Date
StudentName
Class SystemNo
In time
Student sign
StaffSign
Out time
StudentsSign
StaffSign
Remarks
EX.NO LIST OF PROGRAMS
1. Data Definition, Table Creation, Constraints.
2. Insert, Select Commands, Update & Delete Commands.
3. Nested Queries & Join Queries
4. Views
5. High level programming language extensions (Control structures, Procedures and
functions).
6. Front end tools
7. Forms
8. Triggers
9. Menu Design
10. Reports.
11. Database Design and implementation (Mini Project).
LIST OF EXPERIMENTSDBMS/LIST ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
DDL COMMANDS
Create Table Alter Table Drop Table
TO CREATE TABLE
SQL> create table depart(dno number(10),dname varchar2(10),primary key(dno));
Table created.
SQL> desc depart;
Name Null? Type ----------------------------------------- -------- ---------------------------------------------------------------- DNO NOT NULL NUMBER(10) DNAME VARCHAR2(10)
SQL> create table emp(eno number(10),ename varchar2(10),dno number(10),sal number(10),jobid varchar2(10),mgrid varchar2(10),foreign key(dno) references depart(dno));
Table created
SQL> desc emp;
Name Null? Type ----------------------------------------- -------- ----------------------------------------------------------------- ENO NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10)JOBID VARCHAR2(10)MGRID VARCHAR2(10)
LAB EXPERIMENTSDBMS/EXP-01 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
TO ALTER TABLE
ADD: SQL> alter table emp add(primary key(eno),addr varchar2(10));
Table altered.
SQL> desc emp;
Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID VARCHAR2(10) MGRID VARCHAR2(10) ADDR VARCHAR2(10)
SQL> alter table emp add(phno number(5));
Table altered.
SQL> desc emp;
Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO NUMBER(5)
MODIFY SQL> alter table emp modify(jobid char);
Table altered.
SQL> desc emp;
Name Null? Type ----------------------------------------- -------- ----------------------------
ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO VARCHAR2(10)
SQL> alter table emp modify(jobid char(20));
Table altered.
SQL> desc emp;
Name Null? Type----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20) MGRID VARCHAR2(10) ADDR VARCHAR2(10) PHNO VARCHAR2(10)
SQL> alter table emp modify(jobid char(5));
alter table emp modify(jobid char(5)) *ERROR at line 1:
ORA-01441: cannot decrease column length because some value is too big
DROP:
SQL> alter table emp drop(phno);
Table altered.
SQL> desc emp;
Name Null? Type ----------------------------------------- -------- ---------------------------- ENO NOT NULL NUMBER(10) ENAME VARCHAR2(10) DNO NUMBER(10) SAL NUMBER(10) JOBID CHAR(20)
MGRID VARCHAR2(10) ADDR VARCHAR2(10)
SQL> alter table emp drop(addr);
Table altered.
SQL> desc emp;
Name Null? Type----------------------------------------- -------- ----------------------------ENO NOT NULL NUMBER(10)ENAME VARCHAR2(10)DNO NUMBER(10)SAL NUMBER(10)JOBID CHAR(20)MGRID VARCHAR2(10)
TO DROP THE TABLE
SQL> drop table emp;
Table dropped.
SQL> desc emp;
ERROR:
ORA-04044: object emp does not exist.
Insert, Select Commands, Update & Delete Commands.
Insert Update Delete
INSERT:
SQL > Create Table Cust(cname varchar2(15),cid number(5),caddr char(10),caccno number(5),cacctype varchar2(10),cbalance float,Primary key(cid),unique(cname),unique(caccno),check(cbalance>=1000));
SQL> desc cust;
Name Null? Type ----------------------------------------- -------- ---------------------------- CNAME VARCHAR2(15) CID NOT NULL NUMBER(5) CADDR CHAR(10) CACCNO NUMBER(5) CACCTYPE VARCHAR2(10) CBALANCE FLOAT(126)
SQL> insert into cust values('Anitha',01,'Chennai',1001,'savings',15000);
1 row created.
SQL> insert into cust values('Shriram',02,'Pondy',1002,'savings',25000);
1 row created.
SQL> insert into cust values('Chamundi',03,'Salem',1003,'fd',36200);
1 row created.
LAB EXPERIMENTSDBMS/EXP-02 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: SubhaEnter value for cid: 04Enter value for caddr: SalemEnter value for caccno: 1009Enter value for cacctype: 5000Enter value for cbalance: 5000Old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)New 1: insert into cust values('Subha',04,'Salem',1009,'RD',5000)
1 row created.SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: MadhanEnter value for cid: 4Enter value for caddr: SalemEnter value for caccno: 1004Enter value for cacctype: checkingsEnter value for cbalance: 5000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Madhan',4,'Salem',1004,'checkings',5000)
1 row created.
SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: SubhaEnter value for cid: 5Enter value for caddr: TrichyEnter value for caccno: 1005Enter value for cacctype: checkingsEnter value for cbalance: 10000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Subha',5,'Trichy',1005,'checkings',10000)
1 row created.
SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: JayashreeEnter value for cid: 6Enter value for caddr: PondyEnter value for caccno: 1006Enter value for cacctype: fdEnter value for cbalance: 15000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Jayashree',6,'Pondy',1006,'fd',15000)
1 row created.
SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance);Enter value for cname: Sridharan
Enter value for cid: 7Enter value for caddr: KanchiEnter value for caccno: 1007Enter value for cacctype: fdEnter value for cbalance: 22000old 1: insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance)new 1: insert into cust values('Sridharan',7,'Kanchi',1007,'fd',22000)
1 row created.
SELECT:
SQL> select * from cust;
CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- -----------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1003 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000
7 rows selected.
UPDATE:
SQL>update cust set caccno=1111 where cname='Chamundi';
1 row updated
SQL> select * from cust;
CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- --------------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1111 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000
7 rows selected.DELETE:
SQL>delete from cust where cacctype='fd';
3 row deleted
SQL> select * from cust;
CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- -------------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000
4 rows selected.
NESTED QUERIES & JOIN QUERIES
Nested Queries:
Between…and In Not in Like Relational Operators Logical Operators
SQL> select * from cust;
CNAME CID CADDR CACCNO CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- ---------------------------------Anusha 1 Chennai 1001 savings 15000Shriram 2 Pondy 1002 savings 25000Chamundi 3 Salem 1003 fd 36200Madhan 4 Salem 1004 checkings 5000Subha 5 Trichy 1005 checkings 10000Jayashree 6 Pondy 1006 fd 15000Sridharan 7 Kanchi 1007 fd 22000
7 rows selected.
SQL> select cname,caddr from cust where cbalance between 1000 and 10000;
CNAME CADDR--------------- ----------Madhan SalemSubha Trichy
SQL> select cname,cid,cacctype from cust where cacctype in ('savings','checkings','fd');
CNAME CID CACCTYPE--------------- ---------- ----------Anusha 1 savingsShriram 2 savingsChamundi 3 fdMadhan 4 checkings
LAB EXPERIMENTSDBMS/EXP-03 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
Subha 5 checkingsJayashree 6 fdSridharan 7 fd
7 rows selected.
SQL> select cname,cid,cacctype from cust where cacctype not in ('savings','checkings');
CNAME CID CACCTYPE--------------- ---------- ----------Chamundi 3 fdJayashree 6 fdSridharan 7 fd
SQL> select cname,cbalance from cust where cname like '_a%an';
CNAME CBALANCE--------------- ----------Madhan 5000
SQL> select cname,cbalance from cust where cbalance>=15000;
CNAME CBALANCE--------------- ----------Anusha 15000Shriram 25000Chamundi 36200Jayashree 15000Sridharan 22000
5 rows selected.
SQL> select cname,cacctype,cbalance from cust where cbalance>20000 and cacctype=’fd’;;
CNAME CACCTYPE CBALANCE--------------- ---------- ---------- ---------- ---------- ----------Chamundi fd 36200Sridharan fd 22000
2 rows selected.
JOIN OPERATIONS:
SQL>create table locn (lid number(5),city varchar(10),area varchar(5),primary key(lid));
Table created;
SQL>desc locn; Name Null? Type ----------------------------------------- -------- --------------------------- LID NOT NULL NUMBER(5) CITY VARCHAR2(10) AREA VARCHAR2(5)
SQL>create table dep (dno number(5),dname varchar(10),lid number(5),primary key(dno),foreign key(lid) references locn(lid));
Table created;
SQL>desc dep; Name Null? Type ----------------------------------------- -------- -------------------- DNO NOT NULL NUMBER(5) DNAME VARCHAR2(10) LID NUMBER(5)
SQL>create table emp (eid number(5),ename varchar(10),dno number(5),esal number(10),jobid number(5),mgrid varchar(5),primary key(eid),foreign key(dno) references dep(dno));
Table created;
SQL>desc emp;
Name Null? Type ----------------------------------------- -------- ---------------------------- EID NOT NULL NUMBER(5) ENAME VARCHAR2(10) DNO NUMBER(5) ESAL NUMBER(10) JOBID VARCHAR2(5) MGRID NUMBER(3)
SQL>create table grade(gno number(5),ls number(8),hs number(8));
Table created;
SQL>desc grade; Name Null? Type ----------------------------------------- -------- ------------------
GNO NOT NULL NUMBER(5) LS NUMBER(8) HS NUMBER(8)SQL>insert into locn values(&lid,'&city','&area');enter lid:1enter city:chennaienter area:aaaold 1: insert into locn values(&lid,'&city','&area')new 1: insert into locn values(1,'chennai','aaa')1 row createdSQL>insert into dep values(&dno,'&dname',&lid);enter dno:1enter dname:adminenter lid:2old 1: insert into dep values(&dno,'&dname',&lid)new 1: insert into dep values(1,'admin',2)1 row createdSQL>insert into emp values(&eid,'&ename',&dno,&esal, &jobid,&mgr id);enter eid:3enter ename:zzzenter dno:3enter esal :3500enter jobid:2enter mgr id:2old 1: insert into emp values(&eid,'&ename',&dno,&esal,&jobid,&mgrid)new 1: insert into emp values(1,'zzz',3500,2,2)1 row created
SQL>insert into grade values(&gno,&ls,&hs);enter gno:1enter ls:1000enter hs:2000old 1: insert into grade values(&gno,&ls,&hs)new 1: insert into grade values(1,1000,2000)
1 row created
SQL> select * from dep;
DNO DNAME LID---------- ---------- ---------------------- 1 admin 2 2 finance 3 3 hr 1 4 market 3 5 sales 1
SQL> select * from locn;
LID CITY AREA---------- ---------- ----------------------- 1 chennai aaa 2 bombay bbb 3 calcutta ccc
SQL> select * from grade;
GNO LS HS---------- ---------- ---------- 1 1000 2000 2 2001 3000 3 3001 4000 4 4001 5000
SQL> select * from emp;
EID ENAME DNO ESAL JOBID MGRID------- ---------- ---------- ---------- ----- ---------- 5 bbc 4700 2 1 xxx 1 4000 1 2 yyy 2 2000 2 1 3 zzz 3 3500 2 2 4 abc 2 4500
EQUI-JOIN~~~~~~~~~SQL>select e.ename,d.dname from emp e,dep d where e.dno=d.dno;
ENAME DNAME---------- ----------xxx adminyyy financezzz hrabc finance
NON-EQUIJOIN~~~~~~~~~~~~SQL> select e.ename,e.esal,g.gno from emp e,grade g where e.esal between g.ls and g.hs;ENAME ESAL GNO---------- ---------- ----------bbc 4700 4
xxx 4000 3yyy 2000 1zzz 3500 3abc 4500 4
LEFTOUT-JOIN~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno(+)=d.dno;
ENAME DNAME---------- ----------------xxx adminyyy financeabc financezzz hr market sales
RIGHTOUTER-JOIN~~~~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno=d.dno(+);
ENAME DNAME---------- ---------------bbcxxx adminyyy financezzz hrabc finance
FULLOUTER-JOIN~~~~~~~~~~~~~~SQL>select e.ename,d,dname from emp e,dep d where e.dno(+)=(+)d.dno;
ENAME DNAME-------- ---------------bbc xxx adminyyy financezzz hrabc finance market
sales
SELFJOIN----TO DISPLAY ENAME & THEIR MANAGER NAMES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.ename from emp e,emp m where e.mgrid=m.eid;
ENAME ENAME---------- ----------bbc yyyyyy xxxzzz yyy
SELFJOIN----TO DISPLAY MANAGER'S SALARY FOR EVERY EMPLOYEE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.esal from emp e,emp m where e.mgrid=m.eid;
ENAME ESAL---------- ----------------bbc 2000yyy 4000zzz 2000
NESTED QUERIES & JOIN QUERIES
Nested Queries:
Between…and In Not in Like Relational Operators Logical Operators
SQL> select * from cust;SQL> select cname,caddr from cust where cbalance between 1000 and 10000;SQL> select cname,cid,cacctype from cust where cacctype in ('savings','checkings','fd');SQL> select cname,cid,cacctype from cust where cacctype not in ('savings','checkings');SQL> select cname,cbalance from cust where cname like '_a%an';SQL> select cname,cbalance from cust where cbalance>=15000;SQL> select cname,cacctype,cbalance from cust where cbalance>20000 and cacctype=’fd’;
JOIN OPERATIONS:
SQL>create table locn (lid number(5),city varchar(10),area varchar(5),primary key(lid));SQL>desc locn;SQL>create table dep (dno number(5),dname varchar(10),lid number(5),primary key(dno),foreign key(lid) references locn(lid));SQL>desc dep;SQL>create table emp (eid number(5),ename varchar(10),dno number(5),esal number(10),jobid number(5),mgrid varchar(5),primary key(eid),foreign key(dno) references dep(dno));SQL>desc emp;SQL>create table grade(gno number(5),ls number(8),hs number(8));SQL>desc grade;SQL>insert into locn values(&lid,'&city','&area');SQL>insert into dep values(&dno,'&dname',&lid);SQL>insert into emp values(&eid,'&ename',&dno,&esal, &jobid,&mgr id);SQL>insert into grade values(&gno,&ls,&hs);SQL> select * from dep;SQL> select * from locn;SQL> select * from grade;SQL> select * from emp;
EQUI-JOIN~~~~~~~~~
SQL>select e.ename,d.dname from emp e,dep d where e.dno=d.dno;
NON-EQUIJOIN~~~~~~~~~~~~SQL> select e.ename,e.esal,g.gno from emp e,grade g where e.esal between g.ls and g.hs;
LEFTOUT-JOIN~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno(+)=d.dno;
RIGHTOUTER-JOIN~~~~~~~~~~~~~~~SQL> select e.ename,d.dname from emp e,dep d where e.dno=d.dno(+);
FULLOUTER-JOIN~~~~~~~~~~~~~~SQL>select e.ename,d,dname from emp e,dep d where e.dno(+)=(+)d.dno;
SELFJOIN----TO DISPLAY ENAME & THEIR MANAGER NAMES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.ename from emp e,emp m where e.mgrid=m.eid;
SELFJOIN----TO DISPLAY MANAGER'S SALARY FOR EVERY EMPLOYEE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SQL> select e.ename,m.esal from emp e,emp m where e.mgrid=m.eid;
Views
AIM:To implement the View using SQL.
SYNTAX:Create table smp(name varchar(2),regno number,dept varchar(4));
Create view viewn(select * from smp);
OUTPUT:SQL>View is Created.
RESULT:Thus the implementation of view in SQL is performed and output is verified.
LAB EXPERIMENTSDBMS/EXP-04 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
PROCEDURES
AIM: To implement procedures using PL/SQL.
SQL> create table stud(rno number(2),mark1 number(3),mark2 number(3),total number(3),primary key(rno));
Table created.
SQL> desc stud; Name Null? Type ----------------------------------------- -------- ---------------------------- RNO NOT NULL NUMBER(2) MARK1 NUMBER(3) MARK2 NUMBER(3) TOTAL NUMBER(3)
SQL> select * from stud;
RNO MARK1 MARK2 TOTAL---------- ---------- ---------- ---------- 1 80 85 0 2 75 84 0 3 65 80 0 4 90 85 0
SQL> create or replace procedure studd(rnum number) is 2 m1 number; 3 m2 number; 4 total number; 5 begin 6 select mark1,mark2 into m1,m2 from stud where rno=rnum; 7 if m1<m2 then 8 update stud set total=m1+m2 where rno=rnum; 9 end if; 10 end; 11 /
LAB EXPERIMENTSDBMS/EXP-05 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
Procedure created.
SQL> exec studd(1);
PL/SQL procedure successfully completed.
RESULT:
Thus the above PL/SQL procedure successfully completed.
CONTROL STRUCTURESAIM: To implement control structures using PL/SQL.
PROGRAM:
FOR LOOP :*************************** REVERSING THE NO.***********************
SQL> set serveroutput onSQL> declare 2 given_number varchar(5):='1234'; 3 str_length number(2); 4 inverted_number varchar(5); 5 begin 6 str_length:=length(given_number); 7 for cntr in reverse 1..str_length 8 loop 9 inverted_number:=inverted_number||substr(given_number,cntr,1); 10 end loop; 11 dbms_output.put_line('the given no is'||given_number); 12 dbms_output.put_line('the inverted number is'|| inverted_number); 13* end; 14 /
the given no is1234the inverted number is4321
PL/SQL procedure successfully completed.
******************************SUM OF 100 NO.*************************SQL> set serveroutput onSQL> declare 2 a number; 3 s1 number default 0; 4 begin 5 a:=1; 6 loop 7 s1:=s1+a; 8 exit when (a=100); 9 a:=a+1; 10 end loop; 11 dbms_output.put_line('sum bt 1 to 100 is'|| s1); 12 end; 13 /
sum bt 1 to 100 is5050PL/SQL procedure successfully completed.************************SUM OF ODD NO.USING USER I/P****************SQL> set serveroutput on
SQL> declare 2 n number; 3 sum1 number default 0; 4 endvalue number; 5 begin 6 endvalue:=&endvalue; 7 n:=1; 8 for n in 1..endvalue 9 loop 10 if mod(n,2)=1 11 then 12 sum1:=sum1+n; 13 end if; 14 end loop; 15 dbms_output.put_line('sum ='||sum1); 16* end;SQL> /
Enter value for endvalue: 5old 6: endvalue:=&endvalue;new 6: endvalue:=5;sum =9
PL/SQL procedure successfully completed.
*****************SUM OF ODD NO USING WHILE LOOP ****************SQL> set serveroutput on
SQL> declare 2 n number; 3 sum1 number default 0; 4 endvalue number; 5 begin 6 endvalue:=&endvalue; 7 n:=1; 8 while(n<endvalue) 9 loop 10 sum1:=sum1+n; 11 n:=n+2; 12 end loop; 13 dbms_output.put_line('sum of odd no. bt 1 and' ||endvalue||'is'||sum1); 14 end; 15 /
Enter value for endvalue: 5old 6: endvalue:=&endvalue;new 6: endvalue:=5;sum of odd no. bt 1 and5is4
PL/SQL procedure successfully completed.
SQL> /Enter value for endvalue: 7old 6: endvalue:=&endvalue;new 6: endvalue:=7;sum of odd no. bt 1 and7is9
PL/SQL procedure successfully completed.
*******************************NET SALARY***************************SQL> set serveroutput on
SQL> declare 2 ename varchar2(15); 3 basic number; 4 da number; 5 hra number; 6 pf number; 7 netsalary number; 8 begin 9 ename:=&ename;10 basic:=&basic;11 da:=basic*(41/100);12 hra:=basic*(15/100);13 if(basic<3000)14 then15 pf:=basic*(5/100);16 elsif(basic>=3000 and basic<=5000)17 then18 pf:=basic*(7/100);19 elsif(basic>=5000 and basic<=8000)20 then21 pf:=basic*(8/100);22 else23 pf:=basic*(10/100);24 end if;25 netsalary:=basic+da+hra-pf;26 dbms_output.put_line('employee name:'||ename);27 dbms_output.put_line('providend fund:'||pf);28 dbms_output.put_line('net salary:'||netsalary);
29* end;30 /
enter value for ename: 'ice'old 9: ename:=&ename;new 9: ename:='ice';enter value for basic: 1000old 10: basic:=&basic;new 10: basic:=1000;employee name:iceprovidend fund:50net salary:1510
PL/SQL procedure successfully completed.
***************************EXAMPLE FOR LOOP************************SQL> set serveroutput on
SQL> declare 2 begin 3 for i in 1..10 4 loop 5 dbms_output.put_line(to_char(i)); 6 end loop; 7* end; 8 /
12345678910
PL/SQL procedure successfully completed.
*********************EXAMPLE FOR WHILE**************************SQL> set serveroutput on
SQL> declare 2 i number:=0; 3 j number:=0; 4 begin 5 while i<=100 loop 6 j:=j+1;
7 i:=i+2; 8 end loop; 9 dbms_output.put_line(to_char(i)); 10 end; 11 /
102
PL/SQL procedure successfully completed.
*********************EXAMPLE FOR LOOP USING EXIT****************
SQL> set serveroutput on
SQL> declare 2 a number:=100; 3 begin 4 loop 5 a:=a+25; 6 exit when a=250; 7 end loop; 8 dbms_output.put_line(to_char(a)); 9 end; 10 /
250
PL/SQL procedure successfully completed.
***************************PRIME OR NOT******************************SQL> set serveroutput on
SQL> declare 2 no number(3):=&no; 3 a number(4); 4 b number(2); 5 begin 6 for i in 2..no-1 7 loop 8 a:=no MOD i; 9 if a=0 10 then 11 GOTO out; 12 end if; 13 end loop; 14 <<out>> 15 if a=1 16 then 17 dbms_output.put_line(no||'is a prime');
18 else 19 dbms_output.put_line(no||'is not a prime'); 20 end if; 21* end; 22 /
Enter value for no: 7old 2: no number(3):=&no;new 2: no number(3):=7;7is a prime
PL/SQL procedure successfully completed.
***********************AREA CALCULATION**************************SQL> set serveroutput on
SQL> declare 2 pi constant number(4,2):=3.14; 3 radius number(5); 4 area number(14,2); 5 begin 6 radius:=3; 7 while radius<=7 8 loop 9 area:=pi*power(radius,2); 10 insert into areas values(radius,area); 11 radius:=radius+1; 12 end loop; 13 end; 14 /
PL/SQL procedure successfully completed.
SQL> select* from areas;
RADIUS AREA---------- ---------- 3 28.26 4 50.24 5 78.5 6 113.04 7 153.86 7 154 5 78.54 3 28.26 4 50.24 5 78.5 6 113.04
RADIUS AREA---------- ---------- 7 153.86
12 rows selected.
RESULT:
Thus the above PL/SQL procedure successfully completed.
AIM: To design forms using Front end tools in visual Basic.
ALGORITHM:
Step 1: Start the program
Step 2: Design Authentication Form.
Step 3: Get User name and password.
Step 4: Design second form to get the student details
Step 5: Display message Box. Step 6: Stop the program.
SCREEN SHOTS:
LAB EXPERIMENTSDBMS/EXP-06 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
RESULT: Thus the program for Front end tool is executed and output is verified.
Forms
AIM:To implement the Forms using visual Basic.
ALGORITHM:
Step 1: Start the program
Step 2: Design sample Form.
Step 3: Use the various tools
Step 4: Design second form to get the details from the user.
Step 5: Display message Box. Step 6: Stop the program.
LAB EXPERIMENTSDBMS/EXP-07 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
SNAP SHOT:
RESULT:Thus the implementation of forms using VB is performed and output is verified.
TRIGGERS
TRIGGER WITH BEFORE UPDATE
TABLE
SQL> create table orders(order_id number(5),quantity number(4),cost_per_item number(6,2),total_cost number(8,2),updated_date date,updated_by varchar2(10));
Table created.
INSERT----------
SQL> insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_item);
Enter value for order_id: 1Enter value for quantity: 4Enter value for cost_per_item: 20old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_itnew 1: insert into orders(order_id,quantity,cost_per_item) values(1,4,20)
1 row created.
SQL> /Enter value for order_id: 2Enter value for quantity: 5Enter value for cost_per_item: 30old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_itnew 1: insert into orders(order_id,quantity,cost_per_item) values(2,5,30)
1 row created.
SQL> /Enter value for order_id: 3Enter value for quantity: 6Enter value for cost_per_item: 25
LAB EXPERIMENTSDBMS/EXP-08 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_itnew 1: insert into orders(order_id,quantity,cost_per_item) values(3,6,25)
1 row created.
SQL> select * from orders;
ORDER_ID QUANTITY COST_PER_ITEM TOTAL_COST UPDATED_D UPDATED_BY---------- ---------- ------------- ---------- --------- ---------- 1 4 20 2 5 30 3 6 25
TRIGGER SCRIPT------------------------
SQL> create or replace trigger orders_before_update 2 before update 3 on orders 4 for each row 5 declare 6 v_username varchar2(10); 7 begin 8 select user into v_username from dual; 9 :new.updated_date:=sysdate; 10 :new.updated_by:=v_username; 11 end; 12 /
Trigger created.
SQL> update orders set total_cost=3000 where order_id=2;
1 row updated.
SQL> select * from orders;
ORDER_ID QUANTITY COST_PER_ITEM TOTAL_COST UPDATED_D UPDATED_BY---------- ---------- ------------- ---------- --------- ---------- 1 4 20 2 5 30 3000 19-SEP-07 CSE3101 3 6 25
------------------------------------------------------------------------------------------------------------TRIGGER WITH AFTER UPDATE
------------------------------------------------------------------------------------------------------------
TABLE----------SQL> create table orders30(order_id number(5),quantity number(4),cost_per_item number(6,2),total_cost number(8,2));
Table created.
SQL> create table orders_audit(order_id number,quantity_before number,quantity_after number,username varchar2(20));
Table created.
SQL> insert into orders30(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_item);Enter value for order_id: 100Enter value for quantity: 5Enter value for cost_per_item: 10old 1: insert into orders30(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_new 1: insert into orders30(order_id,quantity,cost_per_item) values(100,5,10)
1 row created.
SQL> /Enter value for order_id: 101Enter value for quantity: 4Enter value for cost_per_item: 20old 1: insert into orders30(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_new 1: insert into orders30(order_id,quantity,cost_per_item) values(101,4,20)
1 row created.
SQL> /Enter value for order_id: 102Enter value for quantity: 5Enter value for cost_per_item: 30old 1: insert into orders30(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_new 1: insert into orders30(order_id,quantity,cost_per_item) values(102,5,30)
1 row created.
SQL> create or replace trigger orders_after_update 2 AFTER UPDATE 3 ON orders30 4 for each row
5 declare 6 v_username varchar2(10); 7 begin 8 select user into v_username 9 from dual; 10 insert into orders_audit 11 (order_id, 12 quantity_before, 13 quantity_after, 14 username) 15 values 16 (:new.order_id, 17 :old.quantity, 18 :new.quantity, 19 v_username); 20 end; 21 /
Trigger created.
SQL> update orders30 set quantity=25 where order_id=101;
1 row updated.
SQL> select *from orders_audit;
ORDER_ID QUANTITY_BEFORE QUANTITY_AFTER USERNAME---------- --------------- -------------- --------------------------------------------------------- 101 4 25 CSE3090
RESULT:
Thus the above program for triggers are executed and output is verified
MENU DESIGN
AIM: To design menus using Visual Basic.
SNAP SHOTS:
USING MENU EDITOR:
LAB EXPERIMENTSOS/EXP-09ISSUE NO:REVISION NO:ISSUE DATE:EFFECTIVE DATE:
USING APPLICATION WIZARD:
GENERATING REPORTS
AIM:To generate a report using PL/SQL.
PROGRAM:rem ***********************************************rem Purpose : Script to generate Payments Reportrem AUthor : P.Srikanthrem Date : 10-Oct-2001rem Place : Visakhapatanamrem ***********************************************rem set break and compute settingsbreak on report on course skip page on batch skip 2compute sum of amount on batch course reportset pagesize 24set linesize 90set feedback offcolumn amount format 99,999column name format a20 heading 'Student Name'column dj heading 'Date of|Joining'column dp heading 'Date of|Payment'ttitle skip 1 right 'Page:' format 99 sql.pno skip 1 center 'PaymentsReport' skip 2spool payreport.lstselect c.ccode course, b.bcode batch, p.rollno, s.name name, phone, dj, dp,amountfrom batches b, students s, payments p, courses cwhere b.ccode = c.ccode and b.bcode = s.bcode and s.rollno = p.rollnoorder by course, batch;spool offset feedback onrem clear settingsclear computeclear breakclear columnttitle off
LAB EXPERIMENTSDBMS/EXP-10 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
OUTPUT:
Page:1
Payments Report Date of Date of COURS BATCH ROLLNO Student Name PHONE Joining Payment AMOUNT----- ----- --------- -------------------- ---------- --------- --------- -------Asp b2 3 Andy Roberts 433554 11-JAN-01 13-JAN-01 2,000 3 Andy Roberts 433554 11-JAN-01 20-JAN-01 3,000 4 Malcom Marshall 653345 16-JAN-01 30-JAN-01 2,000 4 Malcom Marshall 653345 16-JAN-01 16-JAN-01 3,000 5 Vivan Richards 641238 16-JAN-01 16-JAN-01 5,000***** ------- sum 15,000***** -------
sum 15,000 c b 3 6 Chirs Evert 631712 14-JAN-01 14-JAN-01 3,500 7 Ivan Lendal 431212 15-JAN-01 15-JAN-01 3,500***** ------- sum 7,000***** -------sum 7,000
java b5 9 Richard Marx 876567 06-APR-01 07-APR-01 3,000 11 Jody Foster 234344 07-APR-01 10-APR-01 3,500 11 Jody Foster 234344 07-APR-01 07-APR-01 1,000 10 Tina Turner 565678 06-APR-01 10-APR-01 4,500***** -------
sum 12,000
REPORT: Thus a report is generated using the pl/sql functions.
MINI PROJECT
Banking
Design Window
LAB EXPERIMENTSDBMS/EXP-11 ISSUE NO:
REVISION NO:ISSUE DATE:EFFECTIVE DATE:
Adding Library
Project = > References => Microsoft ActiveX Data Objects 2.0 Library
Coding
Dim Con As New ADODB.ConnectionDim Rs As New ADODB.Recordset
Private Sub CmdAddNew_Click()
Rs.AddNewtxtClearText1.SetFocus
End Sub
Private Sub CmdDelete_Click()
On Error Resume Next
If Rs.EOF ThenMsgBox "No Records"ElseRs.DeleteRs.MoveNextDisplayTextMsgBox "Record Deleted"
End If
End Sub
Private Sub CmdFirst_Click()Rs.MoveFirstDisplayTextEnd Sub
Private Sub CmdNext_Click()Rs.MoveNextIf Not Rs.EOF ThenDisplayTextElseMsgBox "End Of The Record"Rs.MovePrevious
End IfEnd Sub
Private Sub CmdUpdate_Click()
Rs(0).Value = Val(Text1.Text)Rs(1).Value = Text2.TextRs(2).Value = Text3.TextRs(3).Value = Val(Text4.Text)
Rs.Update
MsgBox "Record Updated"
End Sub
Private Sub Form_Load()
Con.Open "Provider=MSDAORA.1;User ID=cse101;Password=cse101;Data Source=ibmrec;Persist Security Info=False"Con.CursorLocation = adUseClient
Rs.Open "select * from Bank", Con, adOpenKeyset, adLockOptimistic
End Sub
Sub txtClear()
Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""
End Sub
Sub DisplayText()
Text1.Text = Rs(0).ValueText2.Text = Rs(1).ValueText3.Text = Rs(2).ValueText4.Text = Rs(3).Value
End Sub
Private Sub CmdTransact_Click()
Form2.Show
End SubTransaction WindowDesign
Coding
Dim Con As New ADODB.ConnectionDim Rs As New ADODB.Recordset
Private Sub CmdDeposit_Click()
Dim AccNo As IntegerAccNo = Val(Text1.Text)Rs.MoveFirst
Do While Not Rs.EOF If Rs(0).Value = AccNo Then Rs(3).Value = Rs(3).Value + Val(Text2.Text) Rs.Update MsgBox "Amount Deposited" End If Rs.MoveNext Loop
End Sub
Private Sub CmdWithdraw_Click()
Dim AccNo As Integer, Bal As DoubleRs.MoveFirst
AccNo = Val(Text1.Text)
Do While Not Rs.EOF If Rs(0).Value = AccNo Then Bal = Rs(3).Value - Val(Text2.Text) If Bal >= 500 Then Rs(3).Value = Rs(3).Value - Val(Text2.Text) Rs.Update MsgBox "Amount Withdrew" Else MsgBox "Balance Problem" End If End If Rs.MoveNextLoop
End Sub
Private Sub Form_Load()
Con.Open "Provider=MSDAORA.1;User ID=cse101;Password=cse101;Data Source=ibmrec;Persist Security Info=False"Con.CursorLocation = adUseClient
Rs.Open "select * from Bank", Con, adOpenKeyset, adLockOptimistic
End Sub
Employees
Design Window
Adding Library
Project = > References => Microsoft ActiveX Data Objects 2.0 Library
Coding
Dim Con As New ADODB.ConnectionDim Rs As New ADODB.Recordset
Private Sub CmdAddNew_Click()
Rs.AddNewtxtClearText1.SetFocus
End Sub
Private Sub CmdDelete_Click()
On Error Resume Next
If Rs.EOF ThenMsgBox "No Records"ElseRs.DeleteRs.MoveNextDisplayTextMsgBox "Record Deleted"End If
End Sub
Private Sub CmdMoveFirst_Click()
Rs.MoveFirstDisplayText
End Sub
Private Sub CmdMoveNext_Click()
Rs.MoveNextIf Not Rs.EOF ThenDisplayTextElseMsgBox "End Of The Record"End If
End Sub
Private Sub CmdUpdate_Click()
Rs(0).Value = Val(Text1.Text)Rs(1).Value = Text2.TextRs(2).Value = Text3.TextRs(3).Value = Text4.Text
Rs.Update
MsgBox "Record Updated"
End Sub
Private Sub Form_Load()
Con.Open "Provider=MSDAORA.1;User ID=cse101;Password=cse101;Data Source=ibmrec;Persist Security Info=False"Con.CursorLocation = adUseClient
Rs.Open "select * from employees", Con, adOpenKeyset, adLockOptimistic
End Sub
Sub txtClear()
Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""
End Sub
Sub DisplayText()
Text1.Text = Rs(0).ValueText2.Text = Rs(1).ValueText3.Text = Rs(2).ValueText4.Text = Rs(3).Value
End Sub
RESULT:The implementation of mini project for banking system is performed.