Anda di halaman 1dari 62

SNS COLLEGE OF TECHNOLOGY COIMBATORE-35

ISO 9001- 2000

DBMS LAB LABORATORY MANUAL


SNSCT/TLE/61

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SNS COLLEGE OF TECHNOLOGY COIMBATORE-35

ISO 9001- 2000

DBMS LAB LABORATORY MANUAL


SNSCT/TLE/61

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

PREPARED BY: SIGNATURE: DATE:

APPROVED BY: SIGNATURE: DATE:

CONTENTS
DS/CONT ISSUE NO EFFECTIVE DATE REVISION DATE ISSUE DATE -

S.NO

DOCUMENTS

DOCUMENT REF

REVISION

1 2 3 4 5 6 7 8 9 1 Content DS/CONT

PAGE

2 3

Distribution List

DS/DIST

Responsibilities DS/RES

Organization

DS/ORG

Instruction to the students

DS/INS

Format for the Intent Slip

DS/IND

Syllabus

DS/SYL

List of Experiments

DS/LIST

Lab Experiments

DS/EXP

DBMS/DIST

DISTRIBUTION LIST

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

SL.NO 1

DESIGNATION MANAGEMENT REPRESENTATIVE

TYPE ELECTRONIC/ HARDCOPY ELECTRONIC & HARD COPY ELECTRONIC & HARD COPY ELECTRONIC & HARD COPY

ACKNOWLEDGED

PRINCIPAL

HEAD OF THE DEPARTMENT

ISO CO-ORD

ELECTRONIC & HARD COPY

RESPONSIBILITIES
DS/RES ISSUE NO EFFECTIVE DATE REVISION 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 EFFECTIVE DATE -

REVISION 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/IND

FORMAT FOR INDENT SLIP

ISSUE NO. : REVISION NO : ISSUE DATE : EFFECTIVE DATE :

S.N O

Dat e

Studen t Name

Class

System No

In time

Student sign

Staff Sign

Out time

Student s Sign

Staff Sign

Remarks

DBMS/LIST

LIST OF EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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).

DBMS/EXP-01

LAB EXPERIMENTS

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)

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 PHNO

VARCHAR2(10) 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.

DBMS/EXP-02

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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. SQL> insert into cust values('&cname',&cid,'&caddr',&caccno,'&cacctype',&cbalance); Enter value for cname: Subha Enter value for cid: 04 Enter value for caddr: Salem Enter value for caccno: 1009 Enter value for cacctype: 5000

Enter value for cbalance: 5000 Old 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: Madhan Enter value for cid: 4 Enter value for caddr: Salem Enter value for caccno: 1004 Enter value for cacctype: checkings Enter value for cbalance: 5000 old 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: Subha Enter value for cid: 5 Enter value for caddr: Trichy Enter value for caccno: 1005 Enter value for cacctype: checkings Enter value for cbalance: 10000 old 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: Jayashree Enter value for cid: 6 Enter value for caddr: Pondy Enter value for caccno: 1006 Enter value for cacctype: fd Enter value for cbalance: 15000 old 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: 7 Enter value for caddr: Kanchi Enter value for caccno: 1007 Enter value for cacctype: fd Enter value for cbalance: 22000 old 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 15000 Shriram 2 Pondy 1002 savings 25000 Chamundi 3 Salem 1003 fd 36200 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 Jayashree 6 Pondy 1006 fd 15000 Sridharan 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 15000 Shriram 2 Pondy 1002 savings 25000 Chamundi 3 Salem 1111 fd 36200 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 Jayashree 6 Pondy 1006 fd 15000 Sridharan 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 15000 Shriram 2 Pondy 1002 savings 25000 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 4 rows selected.

DBMS/EXP-03

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

NESTED QUERIES & JOIN QUERIES Nested Queries:


Betweenand In Not in Like Relational Operators Logical Operators SQL> select * from cust; CNAME CID CADDR CACCNO CACCTYPE CBALANCE --------------- ---------- ---------- ---------- ---------- --------------------------------Anusha 1 Chennai 1001 savings 15000 Shriram 2 Pondy 1002 savings 25000 Chamundi 3 Salem 1003 fd 36200 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 Jayashree 6 Pondy 1006 fd 15000 Sridharan 7 Kanchi 1007 fd 22000 7 rows selected. SQL> select cname,caddr from cust where cbalance between 1000 and 10000; CNAME CADDR --------------- ---------Madhan Salem Subha Trichy SQL> select cname,cid,cacctype from cust where cacctype in ('savings','checkings','fd'); CNAME CID CACCTYPE --------------- ---------- ---------Anusha 1 savings Shriram 2 savings Chamundi 3 fd Madhan 4 checkings Subha 5 checkings Jayashree 6 fd Sridharan 7 fd 7 rows selected.

SQL> select cname,cid,cacctype from cust where cacctype not in ('savings','checkings'); CNAME CID CACCTYPE --------------- ---------- ---------Chamundi 3 fd Jayashree 6 fd Sridharan 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 15000 Shriram 25000 Chamundi 36200 Jayashree 15000 Sridharan 22000 5 rows selected. SQL> select cname,cacctype,cbalance from cust where cbalance>20000 and CNAME CACCTYPE CBALANCE --------------- ---------- ---------- ---------- ---------- ---------Chamundi fd 36200 Sridharan 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) cacctype=fd;;

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:1 enter city:chennai

enter area:aaa old 1: insert into locn values(&lid,'&city','&area') new 1: insert into locn values(1,'chennai','aaa') 1 row created SQL>insert into dep values(&dno,'&dname',&lid); enter dno:1 enter dname:admin enter lid:2 old 1: insert into dep values(&dno,'&dname',&lid) new 1: insert into dep values(1,'admin',2) 1 row created SQL>insert into emp values(&eid,'&ename',&dno,&esal, &jobid,&mgr id); enter eid:3 enter ename:zzz enter dno:3 enter esal :3500 enter jobid:2 enter mgr id:2 old 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:1 enter ls:1000 enter hs:2000 old 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 2 3

chennai bombay calcutta

aaa bbb 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 admin yyy finance zzz hr abc 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 3 yyy 2000 1 zzz 3500 3 abc 4500 4

LEFTOUT-JOIN ~~~~~~~~~~~~ SQL> select e.ename,d.dname from emp e,dep d where e.dno(+)=d.dno;

ENAME DNAME ---------- ---------------xxx admin yyy finance abc finance zzz hr market sales RIGHTOUTER-JOIN ~~~~~~~~~~~~~~~ SQL> select e.ename,d.dname from emp e,dep d where e.dno=d.dno(+); ENAME DNAME ---------- --------------bbc xxx admin yyy finance zzz hr abc finance FULLOUTER-JOIN ~~~~~~~~~~~~~~ SQL>select e.ename,d,dname from emp e,dep d where e.dno(+)=(+)d.dno; ENAME DNAME -------- --------------bbc xxx admin yyy finance zzz hr abc 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 yyy yyy xxx zzz 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 2000 yyy 4000 zzz 2000

NESTED QUERIES & JOIN QUERIES Nested Queries:

Betweenand 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;

DBMS/EXP-04

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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.

DBMS/EXP-05

LAB EXPERIMENTS

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 ---------- ---------- ---------- ---------1 80 85 0 2 75 84 0 3 65 80 0 4 90 85 0 TOTAL

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 /

Procedure created. SQL> exec studd(1);

PL/SQL procedure successfully completed.

RESULT:
Thus the above PL/SQL procedure successfully completed.

CONTROL STRUCTURES

AIM:
To implement control structures using PL/SQL.

PROGRAM: FOR LOOP : *************************** REVERSING THE NO.*********************** SQL> set serveroutput on SQL> 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 is1234 the inverted number is4321 PL/SQL procedure successfully completed. ******************************SUM OF 100 NO.************************* SQL> set serveroutput on SQL> 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 is5050 PL/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: 5 old 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: 5 old 6: endvalue:=&endvalue; new 6: endvalue:=5; sum of odd no. bt 1 and5is4

PL/SQL procedure successfully completed. SQL> / Enter value for endvalue: 7 old 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 then 15 pf:=basic*(5/100); 16 elsif(basic>=3000 and basic<=5000) 17 then 18 pf:=basic*(7/100); 19 elsif(basic>=5000 and basic<=8000) 20 then 21 pf:=basic*(8/100); 22 else 23 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: 1000 old 10: basic:=&basic; new 10: basic:=1000; employee name:ice providend fund:50 net 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/ 1 2 3 4 5 6 7 8 9 10 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: 7 old 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.

DBMS/EXP-06

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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:

RESULT:
Thus the program for Front end tool is executed and output is verified.

DBMS/EXP-07

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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.

SNAP SHOT:

RESULT:
Thus the implementation of forms using VB is performed and output is verified.

DBMS/EXP-08

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

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: 1 Enter value for quantity: 4 Enter value for cost_per_item: 20 old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_it new 1: insert into orders(order_id,quantity,cost_per_item) values(1,4,20) 1 row created. SQL> / Enter value for order_id: 2 Enter value for quantity: 5 Enter value for cost_per_item: 30 old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_it new 1: insert into orders(order_id,quantity,cost_per_item) values(2,5,30) 1 row created. SQL> / Enter value for order_id: 3 Enter value for quantity: 6 Enter value for cost_per_item: 25 old 1: insert into orders(order_id,quantity,cost_per_item) values(&order_id,&quantity,&cost_per_it

new 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: 100 Enter value for quantity: 5 Enter value for cost_per_item: 10 old 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: 101 Enter value for quantity: 4 Enter value for cost_per_item: 20 old 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: 102 Enter value for quantity: 5 Enter value for cost_per_item: 30 old 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

OS/EXP-09

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

MENU DESIGN AIM:


To design menus using Visual Basic.

SNAP SHOTS:

USING MENU EDITOR:

USING APPLICATION WIZARD:

DBMS/EXP-10

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

GENERATING REPORTS AIM: To generate a report using PL/SQL. PROGRAM: rem *********************************************** rem Purpose : Script to generate Payments Report rem AUthor : P.Srikanth rem Date : 10-Oct-2001 rem Place : Visakhapatanam rem *********************************************** rem set break and compute settings break on report on course skip page on batch skip 2 compute sum of amount on batch course report set pagesize 24 set linesize 90 set feedback off column amount format 99,999 column 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 'Payments Report' skip 2 spool payreport.lst select c.ccode course, b.bcode batch, p.rollno, s.name name, phone, dj, dp, amount from batches b, students s, payments p, courses c where b.ccode = c.ccode and b.bcode = s.bcode and s.rollno = p.rollno order by course, batch; spool off set feedback on rem clear settings clear compute clear break clear column ttitle off

OUTPUT: Page: 1 Payments Report COURS BATCH ROLLNO Student Name -----------------------------------Asp b2 3 Andy Roberts 3 Andy Roberts 4 Malcom Marshall 4 Malcom Marshall 5 Vivan Richards ***** ***** sum 15,000 cb ***** ***** sum 7,000 java b5 9 Richard Marx 11 Jody Foster 11 Jody Foster 10 Tina Turner PHONE ---------433554 433554 653345 653345 641238 Date of Date of Joining Payment AMOUNT --------- --------- ------11-JAN-01 13-JAN-01 2,000 11-JAN-01 20-JAN-01 3,000 16-JAN-01 30-JAN-01 2,000 16-JAN-01 16-JAN-01 3,000 16-JAN-01 16-JAN-01 5,000 ------sum 15,000 -------

3 6 Chirs Evert 7 Ivan Lendal

631712 14-JAN-01 14-JAN-01 3,500 431212 15-JAN-01 15-JAN-01 3,500 ------sum 7,000 ------876567 234344 234344 565678 06-APR-01 07-APR-01 3,000 07-APR-01 10-APR-01 3,500 07-APR-01 07-APR-01 1,000 06-APR-01 10-APR-01 4,500

***** ------sum 12,000

REPORT: Thus a report is generated using the pl/sql functions.

DBMS/EXP-11

LAB EXPERIMENTS

ISSUE NO: REVISION NO: ISSUE DATE: EFFECTIVE DATE:

MINI PROJECT Banking Design Window

Adding Library
Project = > References => Microsoft ActiveX Data Objects 2.0 Library Coding Dim Con As New ADODB.Connection Dim Rs As New ADODB.Recordset Private Sub CmdAddNew_Click() Rs.AddNew txtClear Text1.SetFocus End Sub Private Sub CmdDelete_Click() On Error Resume Next If Rs.EOF Then MsgBox "No Records" Else Rs.Delete Rs.MoveNext DisplayText MsgBox "Record Deleted" End If End Sub Private Sub CmdFirst_Click() Rs.MoveFirst DisplayText End Sub Private Sub CmdNext_Click() Rs.MoveNext If Not Rs.EOF Then DisplayText Else MsgBox "End Of The Record" Rs.MovePrevious End If

End Sub Private Sub CmdUpdate_Click() Rs(0).Value = Val(Text1.Text) Rs(1).Value = Text2.Text Rs(2).Value = Text3.Text Rs(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).Value Text2.Text = Rs(1).Value Text3.Text = Rs(2).Value Text4.Text = Rs(3).Value End Sub Private Sub CmdTransact_Click() Form2.Show End Sub

Transaction Window Design

Coding
Dim Con As New ADODB.Connection Dim Rs As New ADODB.Recordset Private Sub CmdDeposit_Click() Dim AccNo As Integer AccNo = 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 Double

Rs.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.MoveNext Loop 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.Connection Dim Rs As New ADODB.Recordset Private Sub CmdAddNew_Click() Rs.AddNew txtClear Text1.SetFocus End Sub

Private Sub CmdDelete_Click() On Error Resume Next If Rs.EOF Then MsgBox "No Records" Else Rs.Delete Rs.MoveNext DisplayText MsgBox "Record Deleted" End If End Sub Private Sub CmdMoveFirst_Click() Rs.MoveFirst DisplayText End Sub Private Sub CmdMoveNext_Click() Rs.MoveNext If Not Rs.EOF Then DisplayText Else MsgBox "End Of The Record" End If End Sub Private Sub CmdUpdate_Click() Rs(0).Value = Val(Text1.Text) Rs(1).Value = Text2.Text Rs(2).Value = Text3.Text Rs(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).Value Text2.Text = Rs(1).Value Text3.Text = Rs(2).Value Text4.Text = Rs(3).Value End Sub

RESULT:
The implementation of mini project for banking system is performed.

Anda mungkin juga menyukai