Sei sulla pagina 1di 19

SQL> create table department(deptname varchar2(20),building

varchar2(20),budget number);

Table created.

SQL> create table instructor(id number,name varchar2(20),deptname


varchar2(20),salary number);

Table created.

SQL> create table student(id number,name varchar2(20),deptname


varchar2(20),totcred number);

Table created.

SQL> create table course(courseid number,title varchar2(20),deptname


varchar2(20),credits number);

Table created.

SQL> create table section(courseid number,secid number,semester number,year


number,building varchar2
(20),roomno number);

Table created.

SQL> insert into department values('&deptname','&building',&budget);


Enter value for deptname: cse
Enter value for building: b1

Enter value for budget: 5000


old 1: insert into department values('&deptname','&building',&budget)
new 1: insert into department values('cse','b1',5000)

1 row created.

SQL> /
Enter value for deptname: ece
Enter value for building: b2
Enter value for budget: 4000
old 1: insert into department values('&deptname','&building',&budget)
new 1: insert into department values('ece','b2',4000)

1 row created.

SQL> /
Enter value for deptname: civil
Enter value for building: b3
Enter value for budget: 6000
old 1: insert into department values('&deptname','&building',&budget)
new 1: insert into department values('civil','b3',6000)

1 row created.

SQL> insert into instructor values(&id,'&name','&deptname',&salary);


Enter value for id: 1
Enter value for name: xx
Enter value for deptname: cse

Enter value for salary: 15000


old 1: insert into instructor values(&id,'&name','&deptname',&salary)
new 1: insert into instructor values(1,'xx','cse',15000)

1 row created.

SQL> /
Enter value for id: 2
Enter value for name: yy
Enter value for deptname: it
Enter value for salary: 43000
old 1: insert into instructor values(&id,'&name','&deptname',&salary)
new 1: insert into instructor values(2,'yy','it',43000)

1 row created.

SQL> insert into instructor values(&id,'&name','&deptname',&salary);


Enter value for id: 3
Enter value for name: zz
Enter value for deptname: ece
Enter value for salary: 45000
old 1: insert into instructor values(&id,'&name','&deptname',&salary)
new 1: insert into instructor values(3,'zz','ece',45000)

1 row created.

SQL> /

Enter value for id: 4


Enter value for name: ww
Enter value for deptname: civil
Enter value for salary: 30000
old 1: insert into instructor values(&id,'&name','&deptname',&salary)
new 1: insert into instructor values(4,'ww','civil',30000)

1 row created.

SQL> Ed
Wrote file afiedt.buf

1* insert into student values(&id,'&name','&deptname',&totcred)


SQL> /
Enter value for id: 101
Enter value for name: aaa
Enter value for deptname: civil
Enter value for totcred: 3
old 1: insert into student values(&id,'&name','&deptname',&totcred)
new 1: insert into student values(101,'aaa','civil',3)

1 row created.

SQL> /
Enter value for id: 102
Enter value for name: bbb
Enter value for deptname: cse
Enter value for totcred: 3

old 1: insert into student values(&id,'&name','&deptname',&totcred)


new 1: insert into student values(102,'bbb','cse',3)

1 row created.

SQL> /
Enter value for id: 103
Enter value for name: ccc
Enter value for deptname: ece
Enter value for totcred: 2
old 1: insert into student values(&id,'&name','&deptname',&totcred)
new 1: insert into student values(103,'ccc','ece',2)

1 row created.

SQL> /
Enter value for id: 104
Enter value for name: ddd
Enter value for deptname: it
Enter value for totcred: 1
old 1: insert into student values(&id,'&name','&deptname',&totcred)
new 1: insert into student values(104,'ddd','it',1)

1 row created.

SQL> Ed
Wrote file afiedt.buf

1* insert into course values(&courseid,'&title','&deptname',&credits)


SQL> /
Enter value for courseid: 10
Enter value for title: dm
Enter value for deptname: cse
Enter value for credits: 3
old 1: insert into course values(&courseid,'&title','&deptname',&credits)
new 1: insert into course values(10,'dm','cse',3)

1 row created.

SQL> /
Enter value for courseid: 20
Enter value for title: ds
Enter value for deptname: it
Enter value for credits: 2
old 1: insert into course values(&courseid,'&title','&deptname',&credits)
new 1: insert into course values(20,'ds','it',2)

1 row created.

SQL> /
Enter value for courseid: 30
Enter value for title: ed
Enter value for deptname: civil
Enter value for credits: 3
old 1: insert into course values(&courseid,'&title','&deptname',&credits)
new 1: insert into course values(30,'ed','civil',3)

1 row created.

SQL> /
Enter value for courseid: 40
Enter value for title: beee
Enter value for deptname: ece
Enter value for credits: 2
old 1: insert into course values(&courseid,'&title','&deptname',&credits)
new 1: insert into course values(40,'beee','ece',2)

1 row created.

SQL> Ed
Wrote file afiedt.buf

1* alter table section modify(secid varchar2(10))


SQL> /

Table altered.

SQL> insert into section


values(&courseid,'&secid',&semester,&year,'&building',&roomno);
Enter value for courseid: 10
Enter value for secid: a
Enter value for semester: 4
Enter value for year: 2
Enter value for building: b1
Enter value for roomno: 108

old 1: insert into section


values(&courseid,'&secid',&semester,&year,'&building',&roomno)
new 1: insert into section values(10,'a',4,2,'b1',108)

1 row created.

SQL> /
Enter value for courseid: 20
Enter value for secid: b
Enter value for semester: 3
Enter value for year: 2
Enter value for building: b1
Enter value for roomno: 100
old 1: insert into section
values(&courseid,'&secid',&semester,&year,'&building',&roomno)
new 1: insert into section values(20,'b',3,2,'b1',100)

1 row created.

SQL> /
Enter value for courseid: 30
Enter value for secid: a
Enter value for semester: 2
Enter value for year: 1
Enter value for building: b3
Enter value for roomno: 113
old 1: insert into section
values(&courseid,'&secid',&semester,&year,'&building',&roomno)

new 1: insert into section values(30,'a',2,1,'b3',113)

1 row created.

SQL> select deptname from instructor group by deptname having


avg(salary)>42000;

DEPTNAME
-------------------it
ece

SQL> select title from course where courseid=(select courseid from section
where semester in(3,4));
select title from course where courseid=(select courseid from section where
semester in(3,4))
*
ERROR at line 1:
ORA-01427: single-row subquery returns more than one row

SQL> Ed
Wrote file afiedt.buf

1* select title from course where courseid in(select courseid from section where
semester in(3,4))
SQL> /

TITLE
--------------------

dm
ds

SQL> Ed
Wrote file afiedt.buf

1* select title from course where courseid in(select courseid from section where
(semester=3 and s
SQL> /

no rows selected

1* select name from instructor where name not in('mozart','einstein')


SQL> /

NAME
-------------------xx
yy
zz
ww

SQL> select * from product;

PROID PRONAME

SUPNAME

UNITPRICE

---------- -------------------- ---------- ---------100 camera


101 tv

nikon
onida

300
100

102 fridge

videocon

103 ipod

apple

104 mobile

nokia

150
75
50

SQL> select * from orderitems;

ORDERID

PROID TOTALUNITS CUSTOMER

---------- ---------- ---------- ---------5100

104

30 infosys

5101

103

5 satyam

5102

102

25 wipro

5103

101

10 tcs

SQL> select supname from product natural join orderitems where


customer='wipro';

SUPNAME
---------videocon

SQL> Ed
Wrote file afiedt.buf

1* select supname from product natural inner join orderitems where


customer='wipro'
SQL> /

SUPNAME
----------

videocon

SQL> Ed
Wrote file afiedt.buf

1* select supname from product natural outer join orderitems where


customer='wipro'
SQL> /
select supname from product natural outer join orderitems where
customer='wipro'
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> Ed
Wrote file afiedt.buf

1* select supname from product natural left outer join orderitems where
customer='wipro'
SQL> /

SUPNAME
---------videocon

SQL> Ed
Wrote file afiedt.buf

1* select a.proname from product a where a.unitprice<(select


max(unitprice)from product b)
SQL> /

PRONAME
-------------------tv
fridge
ipod
mobile

SQL> select orderitems.orderid from product,orderitems


where((product.orderid=orderitems.orderid) am

2
SQL> Ed
Wrote file afiedt.buf

1* select orderitems.orderid from product,orderitems


where((product.orderid=orderitems.orderid) an
SQL> /
select orderitems.orderid from product,orderitems
where((product.orderid=orderitems.orderid) and sup
*
ERROR at line 1:
ORA-00904: "PRODUCT"."ORDERID": invalid identifier

SQL> Ed
Wrote file afiedt.buf

1* select orderitems.orderid from product,orderitems


where((product.proid=orderitems.proid) and (s
SQL> /

ORDERID
---------5101

SQL> Ed
Wrote file afiedt.buf

1* select * from product,orderitems where((product.proid=orderitems.proid)


and (supname not like t
SQL> /
select * from product,orderitems where((product.proid=orderitems.proid) and
(supname not like tcs))
*
ERROR at line 1:
ORA-00904: "TCS": invalid identifier

SQL> Ed
Wrote file afiedt.buf

1* select * from product,orderitems where((product.proid=orderitems.proid)


and (product.supname no
SQL> /

PROID PRONAME

SUPNAME

UNITPRICE

ORDERID

PROID

---------- -------------------- ---------- ---------- ---------- ---------TOTALUNITS CUSTOMER


---------- ---------104 mobile

nokia

50

5100

104

30 infosys

103 ipod

apple

75

5101

103

5 satyam

102 fridge

videocon

150

5102

102

25 wipro

PROID PRONAME

SUPNAME

UNITPRICE

ORDERID

PROID

---------- -------------------- ---------- ---------- ---------- ---------TOTALUNITS CUSTOMER


---------- ---------101 tv

onida

100

5103

101

10 tcs

SQL> Ed
Wrote file afiedt.buf

SQL> select * from product cross join orderitems;

PROID PRONAME

SUPNAME

UNITPRICE

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

ORDERID

PROID

TOTALUNITS CUSTOMER
---------- ---------100 camera

nikon

300

5100

104

30 infosys

101 tv

onida

100

5100

104

30 infosys

102 fridge

videocon

150

5100

104

30 infosys

PROID PRONAME

SUPNAME

UNITPRICE

ORDERID

PROID

---------- -------------------- ---------- ---------- ---------- ---------TOTALUNITS CUSTOMER


---------- ---------103 ipod

apple

75

5100

104

30 infosys

104 mobile

nokia

50

5100

104

30 infosys

100 camera

nikon

300

5101

103

5 satyam

PROID PRONAME

SUPNAME

UNITPRICE

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

ORDERID

PROID

TOTALUNITS CUSTOMER
---------- ---------101 tv

onida

100

5101

103

5 satyam

102 fridge

videocon

150

5101

103

5 satyam

103 ipod

apple

75

5101

103

5 satyam

PROID PRONAME

SUPNAME

UNITPRICE

ORDERID

PROID

---------- -------------------- ---------- ---------- ---------- ---------TOTALUNITS CUSTOMER


---------- ---------104 mobile

nokia

50

5101

103

5 satyam

100 camera

nikon

300

5102

102

25 wipro

101 tv

onida

100

5102

102

25 wipro

PROID PRONAME

SUPNAME

UNITPRICE

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

ORDERID

PROID

TOTALUNITS CUSTOMER
---------- ---------102 fridge

videocon

150

5102

102

25 wipro

103 ipod

apple

75

5102

102

25 wipro

104 mobile

nokia

50

5102

102

25 wipro

PROID PRONAME

SUPNAME

UNITPRICE

ORDERID

PROID

---------- -------------------- ---------- ---------- ---------- ---------TOTALUNITS CUSTOMER


---------- ---------100 camera

nikon

300

5103

101

10 tcs

101 tv

onida

100

5103

101

10 tcs

102 fridge

videocon

150

5103

101

10 tcs

PROID PRONAME

SUPNAME

UNITPRICE

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

ORDERID

PROID

TOTALUNITS CUSTOMER
---------- ---------103 ipod

apple

75

5103

101

10 tcs

104 mobile
10 tcs

20 rows selected.

nokia

50

5103

101