Sie sind auf Seite 1von 77

LEIT116

Exp:1

Create and modifying the relations

Date: 30/7/2013
Aim:
To write a query on creation and modification of relations using library management
system..
Queries:
SQL> create table library(book_id number(7),isbn_no number(7),subject char(25),language
char(25),name char(25),copies number(7),available number(7),cost number(7),author
char(25));
Table created.
SQL>desc library;
Name

Null?

Type

-------------------------------- --------------- ---------------------------BOOK_ID

NUMBER(7)

ISBN_NO

NUMBER(7)

SUBJECT

CHAR(25)

LANGUAGE

CHAR(25)

NAME

CHAR(25)

COPIES

NUMBER(7)

AVAILABLE
COST
AUTHOR

NUMBER(7)
NUMBER(7)
CHAR(25)

SQL> create table libissue as select book_id from library;


Table created.
SQL> ALTER table libissue add(student_id
number(7),issue_datedate,due_datedate,return_datedate,fine number(7),issuers_id
number(7));
Table altered
SQL>desclibissue

LEIT116

Name

Null? Type

----------------------------------------- -------- ---------------------------BOOK_ID

NUMBER(7)

STUDENT_ID

NUMBER(7)

ISSUE_DATE

DATE

DUE_DATE

DATE

RETURN_DATE

DATE

FINE

NUMBER(7)

ISSUERS_ID

NUMBER(7)

SQL> create table libauthor as select author from library;


Table created.
SQL> alter table libauthor add(author_id number(7),edition number(7),publisher_name
char(25),publications char(25),yr_of_pub number(7),address varchar(50));
Table altered.
SQL>desclibauthor;
Name

Null?

Type

----------------------------------- -------- ---------------------------AUTHOR

CHAR(25)

AUTHOR_ID

NUMBER(7)

EDITION

NUMBER(7)

PUBLISHER_NAME

CHAR(25)

PUBLICATIONS

CHAR(25)

YR_OF_PUB

NUMBER(7)

ADDRESS

VARCHAR2(50)

SQL> create table student as select student_id from libissue;


Table created.

LEIT116

SQL> alter table student add(student_name char(25),acc_no number(7),reg_no


number(7),department char(25),total_limit number(7),books_returned
number(7),books_pending number(7));
Table altered.
SQL>desc student
Name

Null?

------------------------------------- --------

Type
------------------------

STUDENT_ID

NUMBER(7)

STUDENT_NAME

CHAR(25)

ACC_NO

NUMBER(7)

REG_NO

NUMBER(7)

DEPARTMENT

CHAR(25)

TOTAL_LIMIT

NUMBER(7)

BOOKS_RETURNED

NUMBER(7)

BOOKS_PENDING

NUMBER(7)

SQL> create table staffincharge as select issuers_id from libissue;


Table created.
SQL> alter table staffincharge add(staff_id number(7),name char(25),qualification
char(25),designation char(25),date_of_joiningdate,contact_no number(7),address
varchar(50));
Table altered.
SQL>descstaffincharge;
Name

Null? Type

----------------------------------------- -------- ---------------------------ISSUERS_ID

NUMBER(7)

NAME

CHAR(25)

QUALIFICATION

CHAR(25)

DESIGNATION

CHAR(25)

DATE_OF_JOINING

DATE

LEIT116

CONTACT_NO

NUMBER(7)

ADDRESS

VARCHAR2(50)

SQL> insert into library values(1,100,'computerscience','english','java',200,50,500,'samba');


1 row created.
SQL> select * from library;
BOOK_ID

ISBN_NO

----------------

-----------------

SUBJECT
--------------

100

COPIES

-------------------

200

NAME

-------------------

computer science

AVAILABLE

----------------

LANGUAGE

English

COST

java

AUTHOR

-----------------

50

--------

--------------500

samba

SQL> insert into student values(12,'ram',123,97,'it',100,5,15);


1 row created.
SQL> select * from student;
STUDENT_ID
---------------12

STUDENT_NAME
------------------------ram

TOTAL_LIMIT

ACC_NO
----------

----------

123

it

BOOKS_PENDING

--------------

-------------

15

100

----------------97

BOOKS_RETURNED

-----------

REG_NO DEPARTMENT

SQL> insert into libauthorvalues('samba',1,10,'samba','samba publish',2013,'anna


nagarchennai');
1 row created.
SQL> select * from libauthor;
AUTHOR
---------------samba

AUTHOR_ID
---------1

EDITION
---------10

PUBLISHER_NAME
---------------samba

LEIT116

PUBLICATIONS

YR_OF_PUB

ADDRESS

----------------------

-----------------

-----------

samba publish

2013

annanagarchennai

SQL> insert into staffincharge values('2','sita','mba','librarian','222222','anna nagarmadurai');


1 row created.
SQL> select * from staffincharge;
ISSUERS_ID
-----------

NAME

QUALIFICATION

------------

--------------

sita

DESIGNATION CONTACT_NO
---------------------

mba

librarian

---------222222

ADDRESS
----------annanagarmadurai
SQL> insert into libissue values('1','123','100','2','200713');
1 row created.
SQL> select * from libissue;
BOOK_ID

STUDENT_ID

FINE

----------

----------

---------1

123

ISSUERS_ID
----------

100

Table truncated.
SQL>desclibissue;
Name

---------2

SQL> truncate table libissue;

Null? Type

---------------------------------- -------- ---------------------------BOOK_ID

NUMBER(7)

STUDENT_ID

NUMBER(7)

FINE

NUMBER(7)

ISSUE_DATE

200713

LEIT116

ISSUERS_ID

NUMBER(7)

ISSUE_DATE

NUMBER(7)

SQL> select *from libissue;


no rows selected
SQL> delete from libissue where book_id=1;
0 rows deleted.
SQL> alter table libissue drop column issue_date;
Table altered.
SQL> alter table libissue drop column due_date;
Table altered.
SQL> alter table libissue drop column return_date;
Table altered.
SQL>desclibissue
Name

Null? Type

----------------------------------------- -------- ---------------------------BOOK_ID

NUMBER(7)

STUDENT_ID

NUMBER(7)

FINE

NUMBER

ISSUERS_ID

NUMBER(7)

SQL> alter table libissue add issue_datenumber(7);


Table altered.

LEIT116

Result:
Thus the creation and modification of relation are done and successfully output was
verified.

Exp:2

Integrity Constraint

LEIT116

Aim:
To create and implement the usage of queries using constraint.
Queries:
Primary key :
Column level:
SQL> create table book2(bid number(10),bnamevarchar(10),authnamevarchar(20),co
nstraint book2_bid_pk primary key(bid));
Table created.
SQL>desc book1;
Name
-----------------------

Null?
--------

BOOKNAME
PRICE

Type
---------------------------CHAR(20)

NOT NULL

NUMBER(18)

Table level:
SQL> create table book2(bid number(10),bnamevarchar(10),authnamevarchar(20),co
nstraint book2_bid_pk primary key(bid));
Table created.
SQL>desc book2;
Name
-----------------BID

Null?

Type

--------

--------

NOT NULL

NUMBER(10)

BNAME

VARCHAR2(10)

AUTHNAME

VARCHAR2(20)

BID BNAME

PID

---------- -------------------- ---------435 maths


123 social
Unique:

999
998

LEIT116

Column level:
SQL> create table bbbc(bid number(10) constraint
bbbc_bid_ukunique,bnamevarchar(20),pid number(10));
Table created.
SQL> insert into bbbcvalues(435,'maths',999);
1 row created.
SQL> insert into bbbcvalues(123,'social',998);
1 row created.
SQL> insert into bbbcvalues(123,'science',997);
insert into bbbc values(123,'science',997)
*ERROR at line 1:
ORA-00001: unique constraint (SCOTT.BBBC_BID_UK) violated
SQL> select * from bbbc;
BID BNAME

PID

---------- -------------------- ---------435 maths


123 social

999
998

SQL>alter table student2 add rollnonumber(6) constraint student2_rollno_ck


check(rollno>=55000);
Table altered.
SQL>insert into student2 values('12it70','Priya','Linux',52345);
ORA-02290: check constraint (SYSTEM.STUDENT2_ROLLNO_CK) violated
Table level:
SQL>create table book7(bid number(10),bnamevarchar(20),authnamevarchar(2),price
number(3),constraint book7_price_cc check(price>0));
Table created.
SQL>insert into book7 values(192,'dsd','morrismano',0);
ORA-02290: check constraint (SYSTEM.BOOK7_PRICE_CC) violated
Default:
SQL>create table student3(rollno number(5),regnovarchar(7),department varchar(6)
default 'IT');
Table created.
SQL>insert into student3(rollno,regno) values(456,'12it71');

LEIT116

1 row(s) inserted.
SQL>select * from student3;
ROLLNO
REGNO
----------------456
12it71

DEPARTMENT
-------------------IT

Foreign key
Table level:
SQL>create table publisher(pid number(10),pnamevarchar(20),phno
number(10),constraint publisher_pid_pk primary key(pid));
Table created
SQL>insert into book6 values(1232,'Linux',435,768,31245);
ORA-02291: integrity constraint (SYSTEM.BOOK6_PID_FK) violated - parent key not
found
SQL>insert into publisher values(111,'grewal',991123459)
1 row(s) inserted.
SQL>select * from publisher;
PID
PNAME
PHNO
------ -------------------111 Grewal
991123459
SQL>insert into book6 values(1241,'Linux',610,111,6122);
1 row(s) inserted.
Column level:
SQL>create table book01(bid number(10),bnamevarchar(20),authnamevarchar(20),pid
number(10),constraint book02_pid_fk foreign key(pid) references publisher01(pid) );
Table created.
SQL>insert into book01 values(11,'Maths','Grewall',190);
1 row(s) inserted.
SQL>insert into book01 values(124,'CO','Zvonko',191);
1 row(s) inserted.
Not null:
SQL>alter table book6 add isbnnumber(10) constraint book6_isbn_nn NOT NULL;
Table altered.
SQL>insert into book6(bid,bname,price,pid) values(465,'Java2',99.50,65);
ORA-01400: cannot insert NULL into ("SYSTEM"."BOOK6"."ISBN")
Cascade:

LEIT116

SQL>create table book02(bid number(10),bnamevarchar(20),authnamevarchar(20),pid


number(10),constraint book02_pid_fk foreign key(pid) references publisher02(pid) on
delete cascade);
Table created.
SQL>insert into book02 values(453,'Java','IraPohl',134);
1 row(s) inserted.
SQL>insert into book02 values(456,'dsd','Morrismano',135);
1 row(s) inserted.
Set :
SQL>create table book03(bid number(10),bnamevarchar(20),authnamevarchar(20),pid
number(10),constraint book03_pid_fk foreign key(pid) references publisher03(pid) on
delete set null);
Table created.
SQL>insert into book03 values(862,'Surveying','Punmia',637);
1 row(s) inserted.
SQL>insert into book03 values(852,'CO','Zvonko',737);
1 row(s) inserted.

Result:
Thus the constraint was successfully completed and output was verified

Exp:3

Simple SQL Queries

LEIT116

Aim:
To execute the simple sql queries.
Queries:
Query 1
To display the DOB and address of the employee John Smith.
SQL> select bdate,address from employee where fname='John' and lname='Smith';
BDATE

ADDRESS

---------

-------------------

18-AUG-90

Pudur, Madurai

Query 2
To select the name and address of the employee who works in Research
department
SQL> select fname||' '||lname as Name,address from employee where ssn=(select
mgrssn from department where dname='Research');
NAME

ADDRESS

--------------------

--------------------

Raj Kumar

Kodambakkam, Chennai

Query 3
To display the Project No, Department No. And Department managers last
name,DOB and address for the projects located in Chennai.
SQL> select p.pnumber,p.dnumber,e.lname,e.bdate as DOB,e.address from
employee e,projectp,department d where d.dnum=p.dnumber and
p.plocation='Chennai' and d.mgrssn=e.ssn;

LEIT116

PNUMBER

DNUMBER

----------

------------

21

LNAME

DOB

--------------

------------

Smith

18-AUG-90

ADDRESS
-------------------Pudur Madurai

Query 4
To retrieve the first and last name of all employees along with their Managers no.
SQL> select e.fname,e.lname,e.ssn,d.mgrssn from employee e,department d where
e.ssn!=d.mgrssn and e.dno=d.dnum;
FNAME

LNAME

SSN

----------

----------------

----------

MGRSSN
----------

Raj

Kumar

10

John

Smith

Ram

Kumar

Query 5
To select all employees name and SSN
SQL> select fname|| ||lname as Name,ssn from employee;
NAME

SSN

----------

--------

Ram Kumar

John Smith

Raj Kumar

LEIT116

Query 6:
To select all employees name, SSN and the departments name.
SQL> select d.dname,d.dnum,e.fname||||e.lname as name,e.ssn from employee
e,department d where d.mgrssn=e.ssn;
DNAME
----------

DNUM
----------

NAME
----------

----------

Research

Raj Kumar

Technical

John Smith

Accounts

Ram Kumar

SSN

Query 7:
Retrieving the salary of all employees
SQL> select fname||' '||lname as Name_Of_Employee,salary from employee;
NAME_OF_EMPLOYEE
-----------------------------Ram Kumar

SALARY
---------14000

John Smith

10500

Raj Kumar

10500

Query 8
To retrieve the distinct salary values.
SQL> select distinct salary from employee;

LEIT116

SALARY
---------14000
10500

Query 9
To retrieve the name of the employee who is from Chennai.
SQL> select fname||' '||lname as name from employee where address like
'%Theni';
NAME
------------------------------Ram Kumar

Query 10
Employees who were born in 1990.
SQL> select fname|| ||lname as name from employee where bdate like '%90';
NAME
---------------------------John Smith

Query 11
To show the resulting salary and the name of the employee who is working on the
project Web Design and is given 10% rise in salary.

LEIT116

SQL> select p.pname,e.fname,w.essn,e.salary+0.1*e.salary as salary from


employee e,projectp,workson w where p.pname='Web Design' and
w.pno=p.pnumber and w.essn=e.ssn;
PNAME

FNAME

ESSN

---------------

----------

----------

Web Design

John

SALARY
---------11550

Query 12
To retrieve all employees in the department 3 whose salary is in between 13K and
15K.
SQL> select fname,salary from employee where dno=3 and salary between 13000
and 15000;
FNAME

SALARY

----------

------------

Ram

14500

Query 13
To retrieve the list of employees and the project they are working on ordered by
the department number.
SQL> select distinct e.fname,p.pname,p.pnumber,e.dno from employee e,project p
where e.dno=p.dnumber order by e.dno;
FNAME

PNAME

----------

---------------

Raj

PNUMBER
--------------

Cryptography

--------

42

Ram

yyy

41

Ram

zzz

35

DNO

3
5
5

LEIT116

John

Web Design

21

Query 14
To retrieve the name of employee whose project is being controlled by department
number 6
SQL> select e.fname||' '||e.lname as name,p.pnumber,e.dno from project
p,employe e e,workson w where w.essn=e.ssn and w.pno=p.pnumber and
p.dnumber=6;
NAME
--------------------John Smith

PNUMBER
-------------21

DNO
---------6

LEIT116

Result:
Thus the simple sqlqueries was successfully executed and output was verified.
Exp:4

Basic simple SQL queries

20/8/2013
Aim:
To write a basic simple sql queries in library management system
Queries:
1. Find the id and title of all courses which do not require any prerequisities.
selectcourse_id,title from course where course.course_id not in (select course_id from
prereq);
COURSE_ID
BIO-301
BIO-399
CS-101
FIN-201
HIS-351
MU-199
PHY-101

TITLE
Genetics
Computational Biology
Intro.to Computer Science
Investment Banking
World History
Music Video Production
Physical Principles

2. Write SQL update query to increase 10% salary to all instructors.


SALARY
65000
90000
40000

LEIT116

195000
60000
87000
175000
62000
80000
72000
update instructor set salary=salary+(0.1*salary);
14 row(s) updated.
Select salary from instructor;
SALARY
71500
99000
44000
104500
66000
95700
82500
68200
88000
79200
3.Write SQL update query to increase the total credits of all students who have taken
the course title Genetics by the no. Of credits associated with the course.
select * from student;
ID

NAME DEPT_NAME

00128
Zhang
Comp. Sci.
12345
Shankar Comp. Sci.
19991
Brandt
History
23121
Chavez
Finance
44553
Peltier
Physics
45678
Levy
Physics
54321
Williams Comp. Sci.
55739
Sanchez
Music
70557
Snow
Physics
76543
Brown
Comp. Sci.
76653 Aoi
Elec. Eng.
98765 Bourikas
Elec. Eng.
98988 TanakaBiology
120

TOT_CRED
102
32
80
110
56
46
54
38
0
58
60
98

LEIT116

update student120 set tot_cred=tot_cred+(select credits from course where


course.title='Genetics') where id in(select student120.id from student120,course where
student120.dept_name=course.dept_name and course.title='Genetics');
1 row(s) updated.
ID
NAME
DEPT_NAME TOT_CRED
00128
Zhang
Comp. Sci.
102
12345
Shankar
Comp. Sci.
32
19991 Brandt
History
80
23121 Chavez
Finance
110
44553 Peltier
Physics
56
45678 Levy
Physics
46
54321 Williams
Comp. Sci.
54
55739 Sanchez
Music
38
70557 Snow
Physics
0
76543
Brown
Comp. Sci.
58
76653 Aoi
Elec. Eng.
60
98765 Bourikas
Elec. Eng.
98
98988 Tanaka
Biology
122
4.Find the names of students who have not taken any biology department courses.
select name from student120 where dept_name!='Biology';
NAME
Zhang
Shankar
Brandt
Chavez
Peltier
Levy
Williams
Sanchez
Snow
Brown
5. Write SQL update query to list all the instructors who are advisor of atleast two
students,increase the salary by 50000.
Srinivasan
Wu

71500

99000

Mozart

44000

Einstein

104500

LEIT116

Elsaid

66000

Gold

95700

Katz

82500

Califeri

68200

Singh

88000

Crick

79200

Brandt 101200
Sara

55000

Sandy

44000

Kim

193000

select count(advisor.s_id),instructor.name from advisor,instructor,student where


student.id=advisor.s_id and instructor.id=advisor.i_id group by instructor.name;
COUNT(ADVISOR.S_ID)

NAME
Einstein
Crick
Srinivasan
Kim
Singh
Katz

2
1
1
2
1
2

update instructor set salary=salary+50000 where name in (select name from


instructor,advisor where instructor.id=advisor.i_id group by instructor.name having
count(s_id) > 1);
3 row(s) updated.
NAME
Srinivasan
Wu
Mozart
Einstein
El Said
Gold

SALARY
71500
99000
44000
214500
66000
95700

LEIT116

Katz
192500
Califieri
68200
Singh
88000
Crick
79200
Brandt
101200
Kim
198000
Sara
55000
Sandy
44000
6.Write SQL update query to set the credits to 2 for all courses which have less than 5
students taking them COURSE_ID
TITLE
DEPT_NAME
CREDITS
BIO-301
BIO-399
CS-101

Genetics

Biology

ComputationalBiology
Intro.to Computer Science

Biology

Comp. Sci.

CS-190

Game Design

Comp. Sci.

CS-315

Robotics

Comp. Sci.

CS-319

Image Processing

Comp. Sci.

CS-347

Database System Concepts Comp. Sci.

EE-181

Intro.to Digital Systems

FIN-201

Investment Banking

HIS-351

World History

MU-199

Music Video Production

PHY-101

Physical Principles

3
3

Elec. Eng.
Finance

3
3

History
Music

3
3

Physics

update course set credits=2 where course_id in (select course.course_id from course,takes
where course.course_id=takes.course_id group by course.course_id having
count(takes.id)<5);

COURSE_ID
BIO-301

TITLE
Genetics

DEPT_NAME

CREDITS

Biology

LEIT116

BIO-399

Computational Biology

CS-101

Intro.to Computer Science Comp. Sci.

CS-190

Game Design

CS-315

Robotics

CS-319

Image Processing

CS-347

Database System Concepts

EE-181

Intro.to Digital Systems

FIN-201

Investment Banking

HIS-351

World History

MU-199

Music Video Production

Biology

Comp. Sci.

3
4
2

Comp. Sci.
Comp. Sci.
Comp. Sci.

2
2
2

Elec. Eng.
Finance

2
2

History
Music

2
2

LEIT116

Result;
Thus the basic simple sql queries are successfully executed and the output was
verified.

EXP:5

JOINS

27/8/13
Aim:
To write a simple sql queries on joins using our application.
Queries:
SQL> create table stu(id number(7),name varchar(20),dept_namevarchar(20),tot_credit
number(3));
Table created.
SQL>descstu
Name

Null? Type

----------------------------------------- -------- ---------------------------ID


NAME

NUMBER(7)
VARCHAR2(20)

DEPT_NAME

VARCHAR2(20)

TOT_CREDIT

NUMBER(3)

SQL> insert into stuvalues(116,'maha','it',60);


1 row created.
SQL> insert into stuvalues(97,'subha','it',90);
1 row created.
SQL> insert into stuvalues(116,'sne','it',50);
1 row created.

LEIT116

SQL> create table tak(id number(7),cource_id number(7),sec_id number(7),semester


number(3),year number(7),grade char(3));
Table created.
SQL>desctak
Name

Null? Type

----------------------------------------- -------- --------------ID


COURCE_ID
SEC_ID
SEMESTER
YEAR
GRADE

NUMBER(7)
NUMBER(7)
NUMBER(7)
NUMBER(3)
NUMBER(7)
CHAR(3)

SQL> insert into takvalues(45,'32',5,3,2013,'A');


1 row created.
SQL> insert into takvalues(52,31,7,3,2012,'C');
1 row created.
SQL> insert into tak values(47,35,8,4,2010,'A');
1 row created.
SQL> insert into tak(id,sec_id,semester,year,grade) values(78,9,4,2009,'C');
1 row created.
SQL> insert into takvalues(116,45,6,3,2007,'B' );
1 row created.
SQL> create table ins(id number(7),name varchar(20),dept_namevarchar(20),salary
number(10));
Table created.
SQL>descins;
Name

Null? Type

LEIT116

----------------------------------------- -------- ---------------------------ID


NAME
DEPT_NAME
SALARY

NUMBER(7)
VARCHAR2(20)
VARCHAR2(20)
NUMBER(10)

SQL> insert into ins values(78,'susila','cse',40000);


1 row created.
SQL> insert into ins values(95,'chells','maths',45000);
1 row created.
SQL> insert into ins values(64,'sankar','it',48000);
1 row created.
SQL> create table teach(id number(7),cource_id number(7),sec_id number(7),semester
number(3),year number(7));
Table created.
SQL>desc teach
Name

Null? Type

----------------------------------------- -------- ------------------ID


COURCE_ID
SEC_ID
SEMESTER
YEAR

NUMBER(7)
NUMBER(7)
NUMBER(7)
NUMBER(3)
NUMBER(7)

SQL> insert into teach values(118,33,7,3,2009);


1 row created.
SQL> insert into teach values(114,34,8,3,2009);
1 row created.
SQL> insert into teach values(113,36,9,3,2010);

LEIT116

1 row created.
Joins queries:
INNER JOINS:
SQL> select stu.name,tak.id from stu inner join tak on stu.id=tak.id;
NAME

ID

-------------------- ---------maha

116

sne

116

OUTER JOINS:
Left outer join:
SQL> select * from stu left outer join tak on stu.id=tak.id;
ID NAME

DEPT_NAME

TOT_CREDIT

ID

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

YEAR GRA

---------- ---------- ---------- ---------- --97 subha

it

90

116 sne

it

50

Rigtht outer join:


SQL> select * from stu right outer join tak on stu.id=tak.id;

ID NAME

DEPT_NAME

TOT_CREDIT

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

---------- ---------- ---------- ---------- ---

YEAR GRA

ID

LEIT116

78
9

2009 C

52
31

2012 C

45
32

2013 A

ID NAME

DEPT_NAME

TOT_CREDIT

ID

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

YEAR GRA

---------- ---------- ---------- ---------- --47


35

116 maha

2010 A

it

60

Full outer join:


SQL> select * from stu full outer join tak on stu.id=tak.id;

ID NAME

DEPT_NAME

TOT_CREDIT

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

YEAR GRA

---------- ---------- ---------- ---------- --97 subha

it

90

ID

LEIT116

116 sne

it

116 maha

50

it

ID NAME

60

DEPT_NAME

TOT_CREDIT

ID

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

YEAR GRA

---------- ---------- ---------- ---------- --78


9

2009 C

52
31

2012 C

45
32

ID NAME

2013 A

DEPT_NAME

TOT_CREDIT

---------- -------------------- -------------------- ---------- ---------COURCE_ID

SEC_ID SEMESTER

YEAR GRA

ID

LEIT116

---------- ---------- ---------- ---------- --47


35

2010 A

7 rows selected.
Interact:
SQL>select name from tak interact select name from stu;
NAME
----------Maha
Subha
Sne
Union:
SQL> select namedept_name from stu union select semester from tak where
tot_cred=90;
DEPT_NAME

SEMESTER

Subha

LEIT116

LEIT116

Result;
Thus the joins queries are successfully executed by using the library management
application application.
EXP:6

creation and updation of views

10/9/13
Aim:
To write a simple queries by using views
Queries:
Create view:
SQL> create view lib_view as select subject,author from library;
View created.
Display:
SQL> select * from lib_view;
SUBJECT

AUTHOR

------------------------- ------------------------computer science

balagursamy

SQL>desclib_view;
Name

Null?

Type

----------------------------------------- -------- -------------SUBJECT

CHAR(25)

AUTHOR

CHAR(25)

SQL> select author from lib_view where subject='computer science';


AUTHOR
-------------------------

LEIT116
Balagursamy
SQL> create view lib_view1(name,dob,cellno) as select docname,docid,cellno
from docdet where docid=12 ;
View created.
SQL>desc lib_view1;
Name

Null?

Type

----------------------------------------- -------- --------------------------NAME


DOB

VARCHAR2(5)
NUMBER(10)

CELLNO

NUMBER(10)

Check option:
SQL> create view lib_view3(name,address,wardno) as select
docname,docid,cellno from docdet where docid=112 with check option;
View created.
Update:
SQL>update lib_view3 libno=116 where name=main;
O Rows selected.
SQL> alter view lib_view3 compile;
View altered.
Read only option:
SQL> create view lib_view4(name,dob,cellno) as select docname,docid,cellno
from docdet where docid=1WITH READ ONLY;
View created.
SQL>desc lib_view4;
Name

Null?

Type

----------------------------------------- -------- ----------------NAME


DOB
CELLNO

VARCHAR2(5)
NUMBER(10)
NUMBER(10)

LEIT116
Drop view:
SQL> drop view lib_view;
View dropped.
SQL> select * from lib_view;
no rows selected.

LEIT116

Result:
Thus the creation and updation of view was successfully executed and
output was verified.

Expno:7

EXERCISES IN PL/SQL

17/09/2013
Aim:
To implement an query on pl/sql statement.
Pl/sql blocks:
Bind variable:
SQL> set serveroutput on
SQL> VARIABLE bindvar NUMBER
SQL> declare
2 v_num number(2);
3 BEGIN
4 v_num := 5;
5 :bindvar := v_num*2;
6 END;
7 /
PL/SQL procedure successfully completed.
SQL> PRINT bindvar;
G_DOUBLE
---------10
SQL> VARIABLE g_double NUMBER

LEIT116

SQL> declare
2 v_num number(2);
3 begin
4 v_num := &p_num;
5 :g_double := v_num*2;
6 end;
7 /
Enter value for p_num: 20
old 4: v_num := &p_num;
new 4: v_num := 20;
PL/SQL procedure successfully completed.
SQL> print g_double;
G_DOUBLE
---------40
SQL> variable num number
SQL> set serveroutput on
SQL> declare
2 double number;
3 begin
4 :num := 5;
5 double := :num*2;
6 dbms_output.put_line(('double of'||to_char(:num) || 'is' || to_char(double)
));
7 end;
8 /

LEIT116

double of5is10
PL/SQL procedure successfully completed.

Anchor declaration
SQL> variable b number
SQL> declare
2 v_num number(2);
3 v_num2 v_num%type;
4 begin
5 v_num:=4;
6 v_num2:=8;
7 :b:=v_num*v_num2;
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> print b
B
---------32

Control statements
Decode function
SQL> select fname,lname,
2 decode(101,1000,
3 102,2000,
4 103,3000)from emp;

LEIT116

FNAME

LNAME

DECODE(101,1000,102,2000,103,3000)

---------- ---------- ---------------------------------thrigaya

3000

nathpriy

3000

kumararun

3000

if..then..elseif..endif
SQL> declare
2 m number:=&mark;
3 grade char;
4 begin
5 if m>=190 and m<=200then
6 grade:='a';
7 elseif m>=160 and m<=190 then
8 grade:='b';
9 elseif m>=120 and n<=160 then
10 grade:='u';
11 end if;
12 dbms_output.put_line(grade);
13 end;
14 /
Enter value for mark: 199
old 2: m number:=&mark;
new 2: m number:=199;
a
PL/SQL procedure successfully completed.
Searched case:

LEIT116

SQL> declare
2 v_num number:=&any_num;
3 v_res number;
4 begin
5 v_res:=v_num
6 casev_res
7 when 0 then dbms_output.put_line(v_num||'is even');
8 elsedbms_output.put_line(v_num||'is odd');
9 end case;
10 end;
11./
Enter value for any_num: 3
old 2: v_num number:=&any_num;
new 2: v_num number:=3;
3is odd
PL/SQL procedure successfully completed.
Case structure
SQL> declare
2 v_num number:=&any_num;
3 v_res number;
4 begin
5 v_res:=v_num
6 casev_res
7 when 0 then dbms_output.put_line(v_num||'is even');
8 elsedbms_output.put_line(v_num||'is odd');
9 end case;

LEIT116

10 end;
11 /
Enter value for any_num: 4
old 2: v_num number:=&any_num;
new 2: v_num number:=4;
4is even
PL/SQL procedure successfully completed.
Nested if
SQL> set serveroutput on
SQL> declare
2 v_name char:='&name';
3 v_id number(2):='&id';
4 v_age number(2):='&age';
5 begin
6 if(v_name='gayu' and v_id=11)then
7 v_age:=23;
8 end if;
9 if(v_name='anu' and v_id=12)then
10 v_age:=24;
11 end if;
12 if(v_name='priya' and v_id=13)then
13 v_age:=25;
14 end if;
15 if(v_name='kris' and v_id=14)then
16 v_age:=26;
17 end if;

LEIT116

18 dbms_output.put_line(v_name);
19 dbms_output.put_line(to_char(v_id));
20 dbms_output.put_line(to_char(v_age));
21 en
2 /
Enter value for name: anu
old 2: v_name char:='&name';
new 2: v_name char:='anu';
Enter value for id: 12
old 3: v_id number(2):='&id';
new 3: v_id number(2):='12';
Enter value for age: 24
old 4: v_age number(2):='&age';
new 4: v_age number(2):='24';
anu
12
24
PL/SQL procedure successfully completed.
If..then.end..if
SQL> declare
2 v_num number(5):=112;
3 v_id number(5):=115;
4 employee number(5);
5 begin
6 ifv_num>113 then
7. employee:=114;

LEIT116

8. employee:=112;
9. end if;
10. end;
11./
PL/SQL procedure successfully completed.

If..then..else..endif
SQL> declare
2 v_num number(5):=112;
3 v_id number(5):=115;
4 employee number(5);
5 begin
6 ifv_num>113 then
7 employee:=114;
8 else
9 employee:=112;
10 end if;
11 end;
12 /
PL/SQL procedure successfully completed.
If..then..elseif..endif
SQL> declare
2 m number(3):=&mark;
3 grade char;
4 begin
5 if m>=190 and m<=200then

LEIT116

6 grade:='good';
7 elseif m>=170 and m<=190;
8 grade:='excellent';
9 elseif m>=140 and m<=170;
10 grade:='fair';
11 endif;
12 dbms_output.put_line(grade);
13 end;
14 /
Enter value for mark: 170
old 2: m number(3):=&mark;
new 2: m number(3):=170;

Looping statements
for loop
SQL> declare
2 v_countnumber(2);
3 v_sumnumber(2):=0;
4 v_avgnumber(3,1);
5 begin
6 for v_count in 1..10 loop
7 v_sum:=v_sum+v_count;
8 end loop;
9 v_avg:=v_sum/10;
10 dbms_output.put_line(to_char(v_avg));
11 end;

LEIT116

12 /
5.5
PL/SQL procedure successfully completed.
While loop:
SQL> set serveroutput on
SQL> declare
2 v_count number(2);
3 v_sum number(2):=0;
4 v_avg number(3,1);
5 begin
6 v_count:=1;
7 whilev_count<=10 loop
8 v_sum:=v_sum+v_count;
9 v_count:=v_count+1;
10 end loop;
11 v_sum:=v_sum+v_count;
12 v_avg:=v_sum/(v_count-1);
13 dbms_output.put_line(to_char(v_avg));
14 end;
15 /
6.6
PL/SQL procedure successfully completed.
Basic loop:
SQL> setserveroutput on
SQL> declare
2 numnumber(5);

LEIT116

3 id number(5);
4 begin
5 loop
6 num:=num+1;
7 id:=id+1;
8 exit when num=2;
9 end loop;
10 end;
11 /
10
2
PL/SQL procedure successfully completed.
Update:
SQL> set serveroutput on
SQL> declare
2 cnumber number:=&value;
3 begin
4 update employee
5 set salary=salary*(1+value)
6 whereemployeeif=&emp_id;
7 commit;
8 end;
9 /
Enter value for value: 3
old 2: cnumber number:=&value;
new 2: cnumber number:=3;

LEIT116

Enter value for emp_id: 3


old 6: where employeeif=&emp_id;
new 6: where employeeif=3;
PL/SQL procedure successfully completed.
Insert:
SQL> declare
2 v_nameemployee.name%type;
3 begin
4 insert into employee(name,id,salary) values('gayu',112,1000);
5 commit;
6 end;
7 /
PL/SQL procedure successfully completed.
Delete:
SQL> declare
2 v_nameemployee.name%type;
3 begin
4 select id from employee where name='gayu';
5 delete from employee
6 where name=v_name;
7 commit;
8 end;
9 /
PL/SQL procedure successfully completed.
Comment line:
Singleline:

LEIT116

SQL> set serveroutput on


SQL> variable a number
SQL> declare
2 v_num number(10);
3 v_num2 v_num%type;
4 begin
5 v_num:=5;
6 v_num2:=10;
7 :a:=v_num*v_num2;
8 end;
9 --PROGRAM ENDED
10 /
PL/SQL procedure successfully completed.
Multiline:
SQL> variable b number
SQL> declare
2 v_num number(5);
3 v_num2 v_num%type;
4 begin
5 v_num:=5;
6 v_num2:=10;
7 :a:=v_num*v_num2;
8 end;
9 /*
10 */
11 /

LEIT116

PL/SQL procedure successfully completed.

LEIT116

Result:
Thus the pl/sql program was executed successfully.
EXP:08

CURSOR MANAGEMENT

01/10/13
Aim:
To implement the cursor management on library management system.
Queries:
Explicit cursor attributes:
SQL> set serveroutput on;
SQL> declare
2 -- declare the variables
3 c_namestudent.name%type;
4 c_tot_credstudent.tot_cred%type;
5

--declare the cursor

6 cursor student_cur is
7 select name,tot_cred
8 from student
9 where id=76543;
10 begin
11 if not student_cur%isopen then
12 --open the cursor
13

open student_cur;

14

end if;

LEIT116

15

loop

16 --fetch the rows from the cursor


17 fetch student_cur
18 into c_name,c_tot_cred;
19

exit when not student_cur%found;

20 dbms_output.put_line(c_name||' '||c_tot_cred);
21 end loop;
22 dbms_output.put_line(student_cur%rowcount||'student(s) found');
23 --close the cursor
24 closestudent_cur;
25 end;
26 /

Brown 58
1student(s) found
PL/SQL procedure successfully completed.

Cursor for loop:


SQL> declare
2 cursorstudent_cur is
3 selectname,tot_cred
4 from
5 student;
6 begin
7 forstu_rec in student_cur loop
8 ifstu_rec.tot_cred>90 then

LEIT116

9 dbms_output.put_line(stu_rec.name||' ');
10 dbms_output.put_line(stu_rec.tot_cred||' ');
11 end if;
12 end loop;
13 end;
14 /

Zhang
102
Chavez
110
Bourikas
98
Tanaka
120

PL/SQL procedure successfully completed.


Create a cursor for update:
SQL> declare
2 cursor student_cur is
3 select * from student
4 for update of tot_cred;
5 begin
6 for stu_rec in student_cur
7 loop
8

update student

LEIT116

9 set tot_cred=(stu_rec.tot_cred/10)
10 --Where current of clause
11 where current of student_cur;
12

end loop;

13

end;

14 /

PL/SQL procedure successfully completed.


Cursor for loop using a subquery:
begin
forlib_rec in
(selectname,reg_no,dept,no_of_book,fine
from library
wheredept='it')loop
dbms_output.put_line
(lib_rec.name||''||lib_rec.reg_no||'$'||to_char(lib_rec.no_of
_book+NVL(lib_rec.fine,0)));
end loop;
end;
/
PL/SQL procedure successfully completed.
Cursor with parameter
SQL> declare
2 cursorc_lib is select * from library;
3 begin
4 forlib_no in c_lib loop

LEIT116

5 dbms_output.put_line('lib_no.id:'||lib_no.id);
6 end loop;
7 commit;
8 end;
9 /
lib_no.id:112
lib_no.id:114
lib_no.id:115

Cursor with REF:


SQL> declare
2 typebook_type is ref cursor return book%rowtype;
3 v_bookbook_type;
4 n_bookbook%rowtype;
5 begin
6 openv_book for select * from library where id=112;
7 fetchv_book into n_book;
8 dbms_output.put_line(v_book.number||' is '||n_book.name);
9 closev_book;
10 end;
11 /
java
112
Exception:
TOO_MANY_ROWS:
SQL> set serveroutput on

LEIT116

SQL> declare
2 v_namelibrary.id%type;
3 begin
4 dbms_output.put_line('first'||v_name);
5 select id into v_name from library;
6 dbms_output.put_line('second'||v_name);
7 exception
8 whentoo_many_rows then
9 dbms_output.put_line('third'||v_name);
10 dbms_output.put_line('exception'||v_name);
11 end;
12 /
first
third112
exception112
PL/SQL procedure successfully completed.
User defined exception:
SQL> declare
2 v_name exception;
3 v_no exception;
4 v_namelibrary.name%type;
5 begin
6 select name into v_name from libaray
7 wherelibraryid=&v_id;
8 ifv_name<0 then
9 raisev_name;

LEIT116

10 elseifv_name is null then


11 raisev_id;
12 else
13 dbms_output.put_line(to_char(v_name);
14 endif;

15 exception
16 whenno_data_found
17 dbms_output.put_line('no_data_found');
18 end;
19 /
Enter value for v_id: 2
old 7: where libraryeid=&v_id;
new 7: where libraryid=2

LEIT116

Result:
Thus the cursor was successfully executed and output was verified.
EXP:9

PROCEDURE,FUNCTION AND PACKAGE

DATE:15/10/13
PL/SQL BLOCKS:
Procedures:
SQL> create or replace procedure search_lib
2 (i_libid in number,
3 o_last out varchar,
4 o_first out varchar)
5 is
6 begin
7 selectid,name
8 intoo_last,o_first
9 from wow
10 where wow.id=i_empid;
11 exception
12 when others then
13 dbms_output.put_line('name is'||o_last);
14 endsearch_emp;
15 /
Procedure created.
SQL> set serveroutput on;
SQL> declare
2 v_lastwow.name%type;

LEIT116
3 v_firstwow.category%type;
4 v_idwow.id%type:=&mp_id;
5 begin
6 search_emp(v_id,v_last,v_first);
7 ifv_last is not null then
8 dbms_output.put_line('library'||v_id);
9 dbms_output.put_line('name'||v_last||','||v_first);
10 end if;
11 end;
12 /
Enter value for mp_id: 12
old 4: v_idwow.id%type:=&mp_id;
new 4: v_idwow.id%type:=12;
library 12
name12,maha
PL/SQL procedure successfully completed.
Function:
SQL> create or replace function val_get
2 (i_id in number)
3 returnvarchar
4 is
5 v_namevarchar(10);
6 begin
7 select name into v_name
8 from wow
9 where id=i_id;
10 returnv_name;
11 endval_get;

LEIT116
12 /
Function created.
SQL> declare
2 v_idwow.id%type:=&id;
3 v_namewow.name%type;
4 begin
5 select id
6 intov_id from wow
7 where wow.id=v_id;
8 v_name:=val_get(v_id);
9 dbms_output.put_line('the name is'||v_name);
10 exception
11 when others then
12 dbms_output.put_line(v_id||'not found');
13 end;
14 /
Enter value for id: 12
old 2: v_idwow.id%type:=&id;
new 2: v_idwow.id%type:=12;
the name is maha
PL/SQL procedure successfully completed.
SQL> create or replace procedure displayquantity is
2

temp_quantitynumber(10);

3 begin
4 select quantity into temp_quantity from book
5 where bookno=12;
6

if temp_quantity>100 then

dbms_output.put_line('success');

LEIT116
8

else

dbms_output.put_line('not');

10
11

end if;
exception

12

when NO_DATA_FOUND then

13

dbms_output.put_line('medicene not found');

14

end displayquantity;

15 /
Procedure created.
Execute:
SQL> execute displayquantity
PL/SQL procedure successfully completed.
SQL> set serveroutput on;
SQL> execute displayquantity
success
PL/SQL procedure successfully completed.
SQL>drop procedure displayquantity;
Procedure dropped.
SQL> create or replace function retrievequantity
2 return number
3 is
4 v_quantity number(10);
5 begin
6 select quantity into v_quantity
7 from book
8 wherebookno=12;
9 returnv_quantity;
10 endretrievequantity;

LEIT116
11 /
Function created.
SQL>varv_qty number;
SQL>EXEC :v_qty := retrievequantity;
PL/SQL procedure successfully completed.
SQL> print v_qty;
V_QTY
---------150
Drop a function:
SQL>drop function retrievequantity;
Function dropped.
Package:
SQL> create or replace PACKAGE book AS
2 PROCEDUREfindbook(
3 medno IN book.bkno%type,
4 description IN book.description%type,
5 cost IN book.cost%type);
6 v_bknoNOTFOUND EXCEPTION;
7 FUNCTIONgoodidentifier(
8 bkno IN book.bkno%type)
9 return BOOLEAN;
10 end book;
11 /
Package created.
SQL> create or replace PACKAGE BODY book AS
2

PROCEDURE findbook(

3 v_medno IN book.bkno%type,

LEIT116
4 v_description OUT book.description%type,v_cost OUT book.cost%type) IS
5 begin
6 select description,cost
7 into v_description,v_cost
8 from
9 book where medno=v_medno;
10 if SQL%ROWCOUNT = 0 then
11 RAISE v_bkno NOTFOUND;
12 end if;
13 end findbook;
14 FUNCTION goodidentifier(
15 v_medno IN book.bkno%type)
16 return BOOLEAN
17 IS
18 v_id_count number;
19 begin
20 select count(*) into v_id_count
21 from book
22 where bkno=v_bkno;
23 return (1=v_id_count);
24 EXCEPTION
25 WHEN OTHERS THEN
26 RETURN FALSE;
27 END goodidentifier;
28 end med;
29 /

Package Body created.

LEIT116
SQL> declare
2

v_descriptionbook.description%type;

v_costbook.cost%type;

v_mednobook.bkno%type;

begin

book.findbook(v_bkno,v_description,v_cost);

7 dbms_output.put_line('the book is found');


8 EXCEPTION
9 WHEN OTHERS THEN
10 DBMS_OUTPUT.PUT_LINE('cannot find book');
11 end;
12 /
the book is found
PL/SQL procedure successfully completed.

Result:
Thus the pl/sql in procedure,function and packages was successfully
executed and the output was verified.

EXP:10
22.10.2013

TRIGGERS

LEIT116

BEFORE TRIGGERS:
SQL> SET SERVEROUTPUT ON
SQL> CREATE OR REPLACE TRIGGER LIB_BI_TRIGGER
2 BEFORE INSERT ON LIB
3 FOR EACH ROW
4 DECLARE
5 V_BKID NUMBER(9);
6 V_BKNAME VARCHAR(12);
7 BEGIN
8 SELECT BKID,BKNAME INTO V_BKID,V_BKNAME FROM LIB;
9 :NEW.BKID:=V_BKID;
10 :NEW.BKNAME:=V_BKNAME;
11 END;
12 /
Trigger created.
AFTER TRIGGERS:
SQL> CREATE OR REPLACE TRIGGER LIB_ADU_TRIGGER
2 AFTER DELETE OR UPDATE ON LIB
3 DECLARE
4 V_LIBNAME VARCHAR(9);
5 BEGIN
6 IF DELETING THEN
7 V_LIBNAME:='DELETE';
8 ELSIF UPDATING THEN
9 V_LIBNAME:='UPDATE';
10 END IF;

LEIT116

11 INSERT INTO LIB VALUES('AVIL',78,'RASES');


12 END;
13 /
Trigger created.
DELETE:
SQL> DELETE FROM LIB1 WHERE MEDNAME='PARACIT';
1 row deleted.
SQL> SELECT * FROM LIB1;
BKNAME BKTYPE

BKID

--------- --------- ---------JAVA ENGLISH

80

UPDATE:
SQL> UPDATE LIB1 SET BKID=BKID+10 WHERE BKNAME='JAVA';
1 row updated.
SQL> SELECT * FROM LIB1;
BKNAME BKTYPE

LIBID

--------- --------- ---------JAVA ENGLISH

90

INSTEAD OF TRIGGERS:
NO DATA MANIPULATION THROUGH COMPLEX VIEW:
SQL> CREATE TABLE DOC1(DOCNAME VARCHAR(10),DOCID
NUMBER(9),CELLNO NUMBER(10));
Table created.
SQL> INSERT INTO DOC1 VALUES('SIVA',789,9876543456);
1 row created.
SQL> INSERT INTO DOC1 VALUES('GUNA',779,9878967251);
1 row created.

LEIT116

SQL> SELECT * FROM DOC1;


DOCNAME

DOCID

CELLNO

---------- ---------- ---------SIVA

789 9876543456

GUNA

779 9878967251

SQL> CREATE OR REPLACE VIEW HOST ASSELECT DOCNAME,CELLNO


FROM DOC1 WHERE DOCID=779;
View created.
DELETE:
SQL> DELETE FROM HOST WHERE DOCNAME='GUNA';
1 row deleted.
SQL> SELECT * FROM HOST;
no rows selected
SQL> SELECT * FROM DOc1;
DOCNAME

DOCID

CELLNO

---------- ---------- ---------SIVA

789 9876543456

DATA MANIPULATION AND THE INSTEAD OF TRIGGER:


SQL> CREATE TABLE HOS4(DOCNAME VARCHAR(9),DOCID
NUMBER(9),CELLNO NUMBER(10));
Table created.
SQL> INSERT INTO HOS4 VALUES('RAVI',897,9876543212);
1 row created.
SQL> INSERT INTO HOS4 VALUES('KAVI',899,9876543218);
1 row created.
SQL> CREATE OR REPLACE VIEW DOCHOS AS
2 SELECT DOCNAME,CELLNO FROM HOS4

LEIT116

3 WHERE DOCID=899;
View created.
SQL> CREATE OR REPLACE TRIGGER GOVTHOS_DELETE_IOD
2 INSTEAD OF DELETE ON DOCHOS
3 FOR EACH ROW
4 BEGIN
5 DELETE FROM HOS4
6 WHERE DOCID=899;
7 END;
8 /
Trigger created.
DELETE:
SQL> DELETE FROM DOCHOS WHERE DOCNAME='RAVI';
0 rows deleted.

QUERIES:
WRITE A PL/SQL TRIGGER TO ENFORCE THE FOLLOWING RULES :
A.) AN EMPLOYEE CANT HAVE A SALARY HIGHER THAN HIS/HER DEPT
MANAGER:
B.) AN EMPLOYEE CANT WORK ON MORE THAN TWO PROJECTS
CONTOLLED BY A SINGLE DEPT:
SQL> create or replace trigger tri1 before insert on employee
2 for each row
3 declare
4 p number(20);
5 s number(10);
6 begin

LEIT116

7 select salary into s from employee e,department d


8 wheree.dno=d.dno;
9 selectmgrssn into p from employee e,department d
10 wheree.dno=d.dno;
11 if p>s then
12 raise_application_error(-20078,'salary of the employee shld not be greater
than the manager');
13 end if;
14 end;
15 /
Trigger created.

SQL> create or replace trigger pro1 before insert or update on project


2 for each row
3 declare
4 no number(10);
5 begin
6 select count(pname) into no from project where dnum=:new.dnum;
7 if no>2 then
8 raise_application_error(-20011,'an employee cant work on more than two projects');
9 end if;
10 end;
11 /
Trigger created.

SQL> insert into project values('p1',15,'ngl',13);

LEIT116

1 row created.
SQL> insert into project values('p1',16,'ngl',13);
1 row created.

RESULT:
Thus the queries are implemented by using triggers.
EXP:11
29.10.13

CLASSIFICATION AND CLUSTERING USING WEKA

LEIT116
Aim :
To implement clustering and classification by using weka.
CLASSIFICATION:
=== Run information ===

Scheme:

weka.classifiers.rules.ZeroR

Relation:

weather

Instances:

14

Attributes: 5
outlook
temperature
humidity
windy
play
Test mode:

10-fold cross-validation

=== Classifier model (full training set) ===

ZeroR predicts class value: yes

Time taken to build model: 0 seconds

=== Stratified cross-validation ===


=== Summary ===

Correctly Classified Instances

64.2857 %

Incorrectly Classified Instances

35.7143 %

Kappa statistic

LEIT116
Mean absolute error

0.4762

Root mean squared error

0.4934

Relative absolute error

100

Root relative squared error

100

Total Number of Instances

14

%
%

=== Detailed Accuracy By Class ===

TP Rate FP Rate Precision Recall F-Measure ROC Area Class


1

0.643

Weighted Avg.

0.643

0.643

=== Confusion Matrix ===

a b <-- classified as
9 0 | a = yes
5 0 | b = no

1
0

0.783
0
0.413

0.178 yes

0.178 no
0.643

0.503

0.178

LEIT116

@relation weather

@attribute outlook {sunny, overcast, rainy}


@attribute temperature real
@attribute humidity real
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}

@data
sunny,85,85,FALSE,no
sunny,80,90,TRUE,no
overcast,83,86,FALSE,yes
rainy,70,96,FALSE,yes
rainy,68,80,FALSE,yes
rainy,65,70,TRUE,no
overcast,64,65,TRUE,yes

LEIT116
sunny,72,95,FALSE,no
sunny,69,70,FALSE,yes
rainy,75,80,FALSE,yes
sunny,75,70,TRUE,yes
overcast,72,90,TRUE,yes
overcast,81,75,FALSE,yes
rainy,71,91,TRUE,no

CLUSTERING:
=== Run information ===
Scheme:

weka.clusterers.EM -I 100 -N -1 -M 1.0E-6 -S 100

Relation:

weather

Instances:

14

Attributes: 5
outlook
temperature
humidity
windy
play
Test mode:

split 50% train, remainder test

=== Clustering model (full training set) ===

LEIT116
EM
==

Number of clusters selected by cross validation: 1

Cluster
Attribute

0
(1)

======================
outlook
sunny

overcast

rainy

[total]

17

temperature
mean

73.5714

std. dev.

6.3326

humidity
mean

81.6429

std. dev.

9.9111

windy
TRUE

FALSE

[total]
play

16

LEIT116
yes

10

no

[total]

16

=== Model and evaluation on test split ===

EM
==

Number of clusters selected by cross validation: 1

Cluster
Attribute

0
(1)

======================
outlook
sunny

overcast

rainy

[total]

10

temperature
mean
std. dev.

72.2857
6.227

humidity
mean

79.5714

std. dev. 11.4998

LEIT116

windy
TRUE

FALSE

[total]

play
yes

no

[total]

Clustered Instances

7 (100%)

Log likelihood: -9.73408

LEIT116

LEIT116

Result:
Thus the implementation of classification and clustering was successfully executed.

Das könnte Ihnen auch gefallen