Vous êtes sur la page 1sur 51

1-Design the following table:-

Course(course_id,c_name)

create table course


(
courseid varchar(20),
cname varchar(20),
primary key(courseid));

Table created.

course_fee(course_id,c_fee)

create table course_fee


(
courseid varchar(20),
cfee number);

Table created.

course_taken(pros_no,course_id,start_date,time,performance,certificate
create table course_taken
(
pros_no number not null,
courseid varchar(20),
start_date date,
time date,
performance varchar(20),
certificate varchar(20));

Table created.

installment(pros_no,inst_amt,due_date,paid)"
create table installment
(
pros_no number,
inst_amt number,
due_date date,
paid number);

Table created.
Student(pros_no,s_name,address,phone,dob,doa,strong_pts,weak_pts,total,a
mt_paid,inst_amt,due_date,paid)

create table student


(
pros_no number,
s_name varchar(20),
address varchar(20),
phone number,
dob date,
doa date,
strng_pts varchar(20),
weak_pts varchar(20),
total number,
amt_paid number,
inst_full number,
comments varchar(20));

Table created.

2) Insert Records into Course table.


SQL> insert into course values('&courseid','&cname');
Enter value for courseid: ora101
Enter value for cname: oracle
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('ora101','oracle')

1 row created.

SQL> /
Enter value for courseid: ora102
Enter value for cname: oracle
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('ora102','oracle')

1 row created.

SQL> /
Enter value for courseid: ora105
Enter value for cname: oracle
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('ora105','oracle')

1 row created.
SQL> /
Enter value for courseid: uni101
Enter value for cname: unix
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('uni101','unix')

1 row created.

SQL> /
Enter value for courseid: uni102
Enter value for cname: unix
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('uni102','unix')

1 row created.

SQL> /
Enter value for courseid: sof101
Enter value for cname: SE
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('sof101','SE')

1 row created.

SQL> /
Enter value for courseid: c101
Enter value for cname: clang
old 1: insert into course values('&courseid','&cname')
new 1: insert into course values('c101','clang')

1 row created.
SQL> alter table course add foreign key(courseid) references course_fee(courseid);

Table altered.

3) 3-Insert Records into Course_Fee table.

SQL> insert into course_fee values('&courseid',&cfee);


Enter value for courseid: ora101
Enter value for cfee: 500
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('ora101',500)

1 row created.
SQL> /
Enter value for courseid: ora102
Enter value for cfee: 550
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('ora102',550)
1 row created.
SQL> /
Enter value for courseid: ora105
Enter value for cfee: 500
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('ora105',500)

1 row created.

SQL> /
Enter value for courseid: uni101
Enter value for cfee: 1000
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('uni101',1000)

1 row created.

SQL> /
Enter value for courseid: uni102
Enter value for cfee: 750
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('uni102',750)

1 row created.

SQL> /
Enter value for courseid: sof101
Enter value for cfee: 750
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('sof101',750)

1 row created.

SQL> /
Enter value for courseid: c101
Enter value for cfee: 725
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('c101',725)

1 row created.

SQL> /
Enter value for courseid: c102
Enter value for cfee: 425
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('c102',425)

1 row created.
SQL> /
Enter value for courseid: gra101
Enter value for cfee: 1050
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('gra101',1050)

1 row created.

SQL> /
Enter value for courseid: gra102
Enter value for cfee: 300
old 1: insert into course_fee values('&courseid',&cfee)
new 1: insert into course_fee values('gra102',300)

1 row created.

4) Insert Records into Course_taken table.

SQL> insert into course_taken


values(&pros_no,'&courseid','&start_date','&time','&performance','&ce
rtificate');
Enter value for pros_no: 1
Enter value for courseid: ora101
Enter value for start_date: 02-sep-2005
Enter value for time:
Enter value for performance: gud
Enter value for certificate: bsc
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(1,'ora101','02-sep-2005','','gud','bsc')

1 row created.

SQL> /
Enter value for pros_no: 1
Enter value for courseid: ora102
Enter value for start_date: 02-oct-2005
Enter value for time:
Enter value for performance: average
Enter value for certificate: bsc
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(1,'ora102','02-oct-2005','','average','bsc')

1 row created.

SQL> /
Enter value for pros_no: 2
Enter value for courseid: uni102
Enter value for start_date: 08-sep-2001
Enter value for time:
Enter value for performance: gud
Enter value for certificate: bca
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(2,'uni102','08-sep-2001','','gud','bca')

1 row created.

SQL> /
Enter value for pros_no: 4
Enter value for courseid: gra102
Enter value for start_date: 06-sep-2004
Enter value for time:
Enter value for performance: bad
Enter value for certificate: bcom
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(4,'gra102','06-sep-2004','','bad','bcom')

1 row created.

SQL> /
Enter value for pros_no: 5
Enter value for courseid: c102
Enter value for start_date: 15-jun-2009
Enter value for time:
Enter value for performance: very gud
Enter value for certificate: bca
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(5,'c102','15-jun-2009','','very gud','bca')

1 row created.

SQL> /
Enter value for pros_no: 3
Enter value for courseid: uni102
Enter value for start_date: 20-jul-2008
Enter value for time:
Enter value for performance: gud
Enter value for certificate: bcom
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(3,'uni102','20-jul-2008','','gud','bcom')

1 row created.
SQL> /
Enter value for pros_no: 3
Enter value for courseid: c102
Enter value for start_date: 22-jul-2008
Enter value for time:
Enter value for performance: poor
Enter value for certificate: bcom
old 1: insert into course_taken
values(&pros_no,'&courseid','&start_date','&time','&performance',
new 1: insert into course_taken values(3,'c102','22-jul-2008','','poor','bcom')

1 row created.

SQL> alter table course_taken add foreign key(courseid) references


course_fee(courseid);

Table altered.

5) Insert Records into Installment table.

SQL> insert into installment values(&pros_no,&inst_amt,'&due_date',&paid);


Enter value for pros_no: 4
Enter value for inst_amt: 200
Enter value for due_date: 26-sep-2009
Enter value for paid: 100
old 1: insert into installment values(&pros_no,&inst_amt,'&due_date',&paid)
new 1: insert into installment values(4,200,'26-sep-2009',100)

1 row created.

SQL> /
Enter value for pros_no: 5
Enter value for inst_amt: 225
Enter value for due_date: 30-sep-2009
Enter value for paid: 200
old 1: insert into installment values(&pros_no,&inst_amt,'&due_date',&paid)
new 1: insert into installment values(5,225,'30-sep-2009',200)

1 row created.
SQL> alter table installment add foreign key(pros_no) references student(pros_no);

Table altered.
6) Insert Records into Student table.

SQL> insert into student


values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts','&we
ak_pts',&total,&amt_paid,&inst_full,'&comments');
Enter value for pros_no: 1
Enter value for s_name: asif
Enter value for address: delhi

Enter value for phone: 5949094


Enter value for dob: 16-aug-1998
Enter value for doa: 01-aug-2010
Enter value for strng_pts: null
Enter value for weak_pts: null
Enter value for total: 1050
Enter value for amt_paid: 1050
Enter value for inst_full: null
Enter value for comments: null
old 1: insert into student
values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts',
new 1: insert into student values(1,'asif','delhi',5949094,'16-aug-1998','01-aug-
2010','null','nul

1 row created.

SQL> /
Enter value for pros_no: 2
Enter value for s_name: manali
Enter value for address: canada
Enter value for phone: 47892793
Enter value for dob: 01-aug-1984
Enter value for doa: 02-sep-2007
Enter value for strng_pts: null
Enter value for weak_pts: null
Enter value for total: 750
Enter value for amt_paid: 750
Enter value for inst_full: null
Enter value for comments: null
old 1: insert into student
values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts',
new 1: insert into student values(2,'manali','canada',47892793,'01-aug-1984','02-
sep-2007','null',

1 row created.
SQL> /
Enter value for pros_no: 3
Enter value for s_name: meenal
Enter value for address: mumbai
Enter value for phone: 430284
Enter value for dob: 09-nov-1982
Enter value for doa: 10-may-2006
Enter value for strng_pts: null
Enter value for weak_pts: null
Enter value for total: 300
Enter value for amt_paid: 100
Enter value for inst_full: null
Enter value for comments: null
old 1: insert into student
values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts',
new 1: insert into student values(3,'meenal','mumbai',430284,'09-nov-1982','10-
may-2006','null','n

1 row created.

SQL> /
Enter value for pros_no: 4
Enter value for s_name: sparsh
Enter value for address: calcutta
Enter value for phone: 240348023
Enter value for dob: 02-feb-1991
Enter value for doa: 10-oct-2010
Enter value for strng_pts: null
Enter value for weak_pts: null
Enter value for total: 1050
Enter value for amt_paid: 1050
Enter value for inst_full: null
Enter value for comments: null
old 1: insert into student
values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts',
new 1: insert into student values(4,'sparsh','calcutta',240348023,'02-feb-1991','10-
oct-2010','nul

1 row created.

SQL> /
Enter value for pros_no: 5
Enter value for s_name: harsh
Enter value for address: delhi
Enter value for phone: 428205
Enter value for dob: 13-mar-1995
Enter value for doa: 19-jan-2002
Enter value for strng_pts: null
Enter value for weak_pts: null
Enter value for total: 425
Enter value for amt_paid: 700
Enter value for inst_full: null
Enter value for comments: null
old 1: insert into student
values(&pros_no,'&s_name','&address',&phone,'&dob','&doa','&strng_pts',
new 1: insert into student values(5,'harsh','delhi',428205,'13-mar-1995','19-jan-
2002','null','nul

1 row created.

SQL> alter table student add primary key(pros_no);

Table altered.

7-Print all the tables.

SQL> select * from course;

COURSEID CNAME
-------------------- --------------------
ora101 oracle
ora102 oracle
ora105 oracle
uni101 unix
uni102 unix
sof101 se
c101 clang

7 rows selected.

SQL> select * from course_fee;


COURSEID CFEE
-------------------- ----------
ora101 500
ora102 550
ora105 500
uni101 1000
uni102 750
sof101 750
c101 725
c102 425
gra101 1050
gra102 300

10 rows selected.

SQL> select * from course_taken;


PROS_NO COURSEID START_DAT TIME PERFORMANCE
---------- -------------------- --------- --------- --------------------
CERTIFICATE
--------------------
1 ora101 02-SEP-05
bsc
rtificate

1 ora102 02-OCT-05
bsc
rtificate

2 uni102 08-SEP-01

PROS_NO COURSEID START_DAT TIME PERFORMANCE


---------- -------------------- --------- --------- --------------------
CERTIFICATE
--------------------
bca
rtificate

4 gra102 06-SEP-04
bcom
rtificate

5 c102 15-JUN-09
bca

PROS_NO COURSEID START_DAT TIME PERFORMANCE


---------- -------------------- --------- --------- --------------------
CERTIFICATE
--------------------
rtificate

3 uni102 20-JUL-08
bcom
rtificate

3 c102 22-JUL-08
bcom
rtificate

PROS_NO COURSEID START_DAT TIME PERFORMANCE


---------- -------------------- --------- --------- --------------------
CERTIFICATE
--------------------

7 rows selected.
SQL> select * from installment;

PROS_NO INST_AMT DUE_DATE PAID


---------- ---------- --------- ----------
4 200 26-SEP-09 100
5 225 30-SEP-09 200

SQL> select * from student;

PROS_NO S_NAME ADDRESS PHONE DOB


---------- -------------------- -------------------- ---------- ---------
DOA STRNG_PTS WEAK_PTS TOTAL AMT_PAID
--------- -------------------- -------------------- ---------- ----------
INST_FULL COMMENTS
---------- --------------------
1 asif delhi 17856865 16-AUG-98
01-AUG-10 null null 1050 1050
ak_pts
null

2 manali canada 789987 01-AUG-84


02-SEP-07 null null 750 750

PROS_NO S_NAME ADDRESS PHONE DOB


---------- -------------------- -------------------- ---------- ---------
DOA STRNG_PTS WEAK_PTS TOTAL AMT_PAID
--------- -------------------- -------------------- ---------- ----------
INST_FULL COMMENTS
---------- --------------------
ak_pts
null

3 meenal mumbai 9789 09-NOV-82


10-MAY-06 null null 300 100
ak_pts
null

PROS_NO S_NAME ADDRESS PHONE DOB


---------- -------------------- -------------------- ---------- ---------
DOA STRNG_PTS WEAK_PTS TOTAL AMT_PAID
--------- -------------------- -------------------- ---------- ----------
INST_FULL COMMENTS
---------- --------------------

4 sparsh calcutta 87990 02-FEB-91


10-OCT-01 null null 1050 1050
ak_pts
null

5 harsh delhi 6577 13-MAR-95

PROS_NO S_NAME ADDRESS PHONE DOB


---------- -------------------- -------------------- ---------- ---------
DOA STRNG_PTS WEAK_PTS TOTAL AMT_PAID
--------- -------------------- -------------------- ---------- ----------
INST_FULL COMMENTS
---------- --------------------
19-JAN-02 null null 425 700
ak_pts
null

8-Find out the names of all students.


SQL> select s_name from student;

S_NAME
--------------------
asif
manali
meenal
sparsh
harsh
9-Retrieve names and course_id of all students

SQL> select s.s_name,c.courseid


2 from student s,course_taken c
3 where s.pros_no=c.pros_no;

S_NAME COURSEID
-------------------- --------------------
asif ora101
asif ora102
manali uni102
sparsh gra102
harsh c102
meenal uni102
meenal c102

7 rows selected.

10) List the various courses available from course table.


SQL> select distinct cname from course;

CNAME
--------------------
unix
se
clang
oracle

11-Find out the names of students starting with 'a'.

SQL> select s_name from student


2 where s_name like 'a%';

S_NAME
--------------------
Asif

12- Print the names of students whose total amount is not equal to the amount
due.

SQL> select s_name from student


2 where total!=amt_paid;

S_NAME
--------------------
meenal
harsh
13) Count the number of students who have joined in the current year.

SQL> select count(*) from student


2 where doa like '%10';

COUNT(*)
----------
1

14- Print the details of course fee where course_name='ORACLE'.

SQL> select co.courseid,co.cname,c.cfee


2 from course co,course_fee c
3 where co.cname='oracle' and c.courseid=co.courseid;

COURSEID CNAME CFEE


-------------------- -------------------- ----------
ora101 oracle 500
ora102 oracle 550
ora105 oracle 500

15- Print the details of course whose fees is more than 500 but less than
10000.

SQL> select * from course_fee


2 where (cfee>500 and cfee<10000);

COURSEID CFEE
-------------------- ----------
ora102 550
uni101 1000
uni102 750
sof101 750
c101 725
gra101 1050

6 rows selected.
16- Rename course_fee table as cou_fee.
SQL> rename course_fee to cou_fee;

Table renamed.

SQL> select * from cou_fee;

COURSEID CFEE
-------------------- ----------
ora101 500
ora102 550
ora105 500
uni101 1000
uni102 750
sof101 750
c101 725
c102 425
gra101 1050
gra102 300

10 rows selected.

17- Select the students who have not yet paid the full amount.

SQL> select s_name from student


2 where amt_paid<total;

S_NAME
--------------------
Meenal

18-Determine the maximumand minimum course prices.Rename the title as


MAX_PRICE and MIN_PRICE respectively.

SQL> select max(cfee) as MAX_PRICE,min(cfee) as MIN_PRICE


2 from cou_fee;

MAX_PRICE MIN_PRICE
---------- ----------
1050 300

19-Count the number of students taken admission in 'ORACLE'.


SQL> select count(*) from student s,course_taken c,course co
2 where co.cname='oracle' and co.courseid=c.courseid and s.pros_no=c.pros_no;

COUNT(*)
----------
2
20- Get the sum of amount to be collected from student in AUGUST

SQL> select sum(amt_paid) from student


2 where substr(to_char(doa),4,3) ='AUG';

SUM(AMT_PAID)
-------------
1050

21-Insert two columns in the student table(no_of_installments and


no_of_instpaid).

SQL> alter table student add no_of_inst number;

Table altered.

SQL> alter table student add no_of_instpaid number;

Table altered.

SQL> describe student;


Name Null? Type
----------------------------------------- -------- ----------------------------
PROS_NO NUMBER
S_NAME VARCHAR2(20)
ADDRESS VARCHAR2(20)
PHONE NUMBER
DOB DATE
DOA DATE
STRNG_PTS VARCHAR2(20)
WEAK_PTS VARCHAR2(20)
TOTAL NUMBER
AMT_PAID NUMBER
INST_FULL NUMBER
COMMENTS VARCHAR2(20)

22- Display the admission date as 'DD-MONTH-YY' format.


SQL> select to_char(doa,'dd-month-yy') as date_admsn
2 from student;

DATE_ADMSN
---------------
01-august -10
02-september-07
10-may -06
10-october -01
19-january -02

23- Change the course "UNIX" as "U.O.S".

SQL> update course


2 set cname='U.O.S'
3 where cname='unix';

2 rows updated.

SQL> select * from course;

COURSEID CNAME
-------------------- --------------------
ora101 oracle
ora102 oracle
ora105 oracle
uni101 U.O.S
uni102 U.O.S
sof101 se
c101 clang
7 rows selected.

24-Increase the price of 'ORACLE'with fee+1000.

SQL> select cf.cfee+1000 as new_fee


2 from course c,course_fee cf
3 where cf.courseid=c.courseid
4 and c.cname='oracle';

NEW_FEE
----------
1500
1550
1500
26-Display the names of all students who have to pay installments within next
three months.

SQL> select s_name from student s,installment i


2 where i.pros_no=s.pros_no and months_between(s.doa,i.due_date)<=3
3 and substr(to_char(s.doa),8,2)=substr(to_char(i.due_date),8,2);

no rows selected
1. Design the following table:-
Employee(E_ID,ENAME,SAL,DEPTNO,MAN_NO,JOB_NO,DOJ,DOB,COMM).
Department(DEPT_NO,D_NAME).
JOB(JOB_TYPE,J_NO,J_PERFORMED).
Manager(M_NAME,M_NO).

SQL> create table employee


2 (
3 e_id number not null,
4 ename varchar(25),
5 sal number,
6 deptno number,
7 man_no number,
8 job_no number,
9 doj date,
10 dob date,
11 comm number);

Table created.

SQL> alter table employee


2 add primary key(e_id);

Table altered.

SQL> alter table employee


2 add foreign key(deptno) references department(deptno);

Table altered.

SQL> alter table employee


2 add foreign key(job_no) references job(j_no);

Table altered.

SQL> alter table employee


2 add foreign key(man_no) references manager(m_no);

Table altered.

SQL> insert into employee


values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&com
m)
;
Enter value for e_id: 7369
Enter value for ename: smith
Enter value for salary: 800
Enter value for deptno: 20
Enter value for man_no: 7902
Enter value for job_no: 2222
Enter value for dob:
Enter value for doj: 17-dec-1980
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7369,'smith',800,20,7902,2222,'','17-dec-
1980',null)

1 row created.

SQL> /
Enter value for e_id: 7499
Enter value for ename: allen
Enter value for salary: 1600
Enter value for deptno: 30
Enter value for man_no: 7698
Enter value for job_no: 1111
Enter value for dob:
Enter value for doj: 20-feb-1981
Enter value for comm: 300
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7499,'allen',1600,30,7698,1111,'','20-feb-
1981',300)

1 row created.

SQL> /
Enter value for e_id: 7521
Enter value for ename: ward
Enter value for salary: 1250
Enter value for deptno: 30
Enter value for man_no: 7698
Enter value for job_no: 1111
Enter value for dob:
Enter value for doj: 22-feb-1981
Enter value for comm: 500
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7521,'ward',1250,30,7698,1111,'','22-feb-
1981',500)

1 row created.

SQL> /
Enter value for e_id: 7666
Enter value for ename: jones
Enter value for salary: 2975
Enter value for deptno: 20
Enter value for man_no: 7839
Enter value for job_no: 4444
Enter value for dob:
Enter value for doj: 02-apr-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7666,'jones',2975,20,7839,4444,'','02-apr-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7654
Enter value for ename: martin
Enter value for salary: 1250
Enter value for deptno: 30
Enter value for man_no: 7698
Enter value for job_no: 1111
Enter value for dob:
Enter value for doj: 28-sep-1981
Enter value for comm: 1400
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7654,'martin',1250,30,7698,1111,'','28-sep-
1981',1400)

1 row created.

SQL> /
Enter value for e_id: 7698
Enter value for ename: blake
Enter value for salary: 2850
Enter value for deptno: 30
Enter value for man_no: 7839
Enter value for job_no: 4444
Enter value for dob:
Enter value for doj: 01-may-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7698,'blake',2850,30,7839,4444,'','01-may-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7782
Enter value for ename: clark
Enter value for salary: 2450
Enter value for deptno: 10
Enter value for man_no: 7839
Enter value for job_no: 4444
Enter value for dob:
Enter value for doj: 09-jun-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7782,'clark',2450,10,7839,4444,'','09-jun-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7788
Enter value for ename: scott
Enter value for salary: 3000
Enter value for deptno: 20
Enter value for man_no: 7566
Enter value for job_no: 3333
Enter value for dob:
Enter value for doj: 19-apr-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7788,'scott',3000,20,7566,3333,'','19-apr-
1981',null)

1 row created.
SQL> /
Enter value for e_id: 7839
Enter value for ename: king
Enter value for salary: 5000
Enter value for deptno: 10
Enter value for man_no: 7698
Enter value for job_no: 5555
Enter value for dob:
Enter value for doj: 17-nov-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7839,'king',5000,10,7698,5555,'','17-nov-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7844
Enter value for ename: turner
Enter value for salary: 1500
Enter value for deptno: 30
Enter value for man_no: 7788
Enter value for job_no: 1111
Enter value for dob:
Enter value for doj: 08-sep-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7844,'turner',1500,30,7788,1111,'','08-sep-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7876
Enter value for ename: adams
Enter value for salary: 1100
Enter value for deptno: 20
Enter value for man_no: 7698
Enter value for job_no: 2222
Enter value for dob:
Enter value for doj: 23-may-1987
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7876,'adams',1100,20,7698,2222,'','23-may-
1987',null)

1 row created.
SQL> /
Enter value for e_id: 7900
Enter value for ename: james
Enter value for salary: 950
Enter value for deptno: 30
Enter value for man_no: 7698
Enter value for job_no: 2222
Enter value for dob:
Enter value for doj: 12-mar-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7900,'james',950,30,7698,2222,'','12-mar-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7902
Enter value for ename: ford
Enter value for salary: 3000
Enter value for deptno: 20
Enter value for man_no: 7566
Enter value for job_no: 3333
Enter value for dob:
Enter value for doj: 12-mar-1981
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7902,'ford',3000,20,7566,3333,'','12-mar-
1981',null)

1 row created.

SQL> /
Enter value for e_id: 7934
Enter value for ename: miller
Enter value for salary: 1300
Enter value for deptno: 10
Enter value for man_no: 7782
Enter value for job_no: 2222
Enter value for dob:
Enter value for doj: 23-jan-1982
Enter value for comm: null
old 1: insert into employee
values(&e_id,'&ename',&salary,&deptno,&man_no,&job_no,'&dob','&doj',&c
new 1: insert into employee values(7934,'miller',1300,10,7782,2222,'','23-jan-
1982',null)
1 row created.
b) Department(DEPTNO,DNAME).

SQL> create table department


2 (
3 deptno number not null,
4 dname varchar(25));

Table created.

SQL> alter table department


2 add primary key(deptno);

Table altered.

SQL> insert into department values(&deptno,'&dname');


Enter value for deptno: 10
Enter value for dname: accounting
old 1: insert into department values(&deptno,'&dname')
new 1: insert into department values(10,'accounting')

1 row created.

SQL> /
Enter value for deptno: 20
Enter value for dname: research
old 1: insert into department values(&deptno,'&dname')
new 1: insert into department values(20,'research')

1 row created.
SQL> /
Enter value for deptno: 30
Enter value for dname: sales
old 1: insert into department values(&deptno,'&dname')
new 1: insert into department values(30,'sales')

1 row created.

SQL> /
Enter value for deptno: 40
Enter value for dname: operations
old 1: insert into department values(&deptno,'&dname')
new 1: insert into department values(40,'operations')

1 row created.

SQL> select * from department;

DEPTNO DNAME
---------- -------------------------
10 accounting
20 research
30 sales
40 operations

c) JOB(JOB_TYPE,J_NO,J_PERFORMED).

SQL> create table job


2 (
3 job_type varchar(25),
4 j_no number not null,
5 j_performed varchar(25));

Table created.

SQL> alter table job


2 add primary key(j_no);

Table altered.

SQL> insert into job values('&job_type',&j_no,'&j_performed');


Enter value for job_type: clerk
Enter value for j_no: 2222
Enter value for j_performed:
old 1: insert into job values('&job_type',&j_no,'&j_performed')
new 1: insert into job values('clerk',2222,'')

1 row created.

SQL> /
Enter value for job_type: salesman
Enter value for j_no: 1111
Enter value for j_performed:
old 1: insert into job values('&job_type',&j_no,'&j_performed')
new 1: insert into job values('salesman',1111,'')

1 row created.

SQL> /
Enter value for job_type: analyst
Enter value for j_no: 4444
Enter value for j_performed:
old 1: insert into job values('&job_type',&j_no,'&j_performed')
new 1: insert into job values('analyst',4444,'')

1 row created.

SQL> /
Enter value for job_type: accountant
Enter value for j_no: 3333
Enter value for j_performed:
old 1: insert into job values('&job_type',&j_no,'&j_performed')
new 1: insert into job values('accountant',3333,'')

1 row created.

SQL> /
Enter value for job_type: developer
Enter value for j_no: 5555
Enter value for j_performed:
old 1: insert into job values('&job_type',&j_no,'&j_performed')
new 1: insert into job values('developer',5555,'')

1 row created.

SQL> select * from job;

JOB_TYPE J_NO J_PERFORMED


------------------------- ---------- -------------------------
clerk 2222
salesman 1111
analyst 4444
accountant 3333
developer 5555

d) Manager(M_NAME,M_NO).

SQL> create table manager


2 (
3 m_name varchar(25),
4 m_no number not null);

Table created.

SQL> alter table manager


2 add primary key(m_no);

Table altered.

SQL> insert into manager values('&m_name',&m_no);


Enter value for m_name: ford
Enter value for m_no: 7902
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('ford',7902)

1 row created.
SQL> /
Enter value for m_name: blake
Enter value for m_no: 7698
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('blake',7698)

1 row created.

SQL> /
Enter value for m_name: king
Enter value for m_no: 7839
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('king',7839)

1 row created.

SQL> /
Enter value for m_name: jones
Enter value for m_no: 7566
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('jones',7566)

1 row created.

SQL> /
Enter value for m_name: scott
Enter value for m_no: 7788
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('scott',7788)

1 row created.

SQL> /
Enter value for m_name: clark
Enter value for m_no: 7782
old 1: insert into manager values('&m_name',&m_no)
new 1: insert into manager values('clark',7782)

1 row created.

SQL> select * from manager;

M_NAME M_NO
------------------------- ----------
ford 7902
blake 7698
king 7839
jones 7566
scott 7788
clark 7782

6 rows selected.

2) Describe the table employee and department.

SQL> describe employee;


Name Null? Type
----------------------------------------- -------- ----------------------------
E_ID NOT NULL NUMBER
ENAME VARCHAR2(25)
SAL NUMBER
DEPTNO NUMBER
MAN_NO NUMBER
JOB_NO NUMBER
DOJ DATE
DOB DATE
COMM NUMBER

SQL> describe department;


Name Null? Type
----------------------------------------- -------- ----------------------------
DEPTNO NOT NULL NUMBER
DNAME VARCHAR2(25)

3) Select all information from employee table.

SQL> select * from employee;

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7369 smith 800 20 7902 2222
17-DEC-80

7499 allen 1600 30 7698 1111


20-FEB-81 300

7521 ward 1250 30 7698 1111


22-FEB-81 500

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7666 jones 2975 20 7839 4444
02-APR-81

7654 martin 1250 30 7698 1111


28-SEP-81 1400

7698 blake 2850 30 7839 4444


01-MAY-81

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7782 clark 2450 10 7839 4444
09-JUN-81

7788 scott 3000 20 7566 3333


19-APR-81

7839 king 5000 10 5555


17-NOV-81

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7844 turner 1500 30 7788 1111
08-SEP-81

7876 adams 1100 20 7698 2222


23-MAY-87

7900 james 950 30 7698 2222


12-MAR-81

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7902 ford 3000 20 7566 3333
12-MAR-81

7934 miller 1300 10 7782 2222


23-JAN-82
14 rows selected.

4) List the detail of employee having salary between 1000 and 2000.

SQL> select * from employee


2 where sal between 1000 and 2000;

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7499 allen 1600 30 7698 1111
20-FEB-81 300

7521 ward 1250 30 7698 1111


22-FEB-81 500

7654 martin 1250 30 7698 1111


28-SEP-81 1400

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7844 turner 1500 30 7788 1111
08-SEP-81

7876 adams 1100 20 7698 2222


23-MAY-87

7934 miller 1300 10 7782 2222


23-JAN-82

6 rows selected.

5) List department number and department name in department table.

SQL> select deptno,dname


2 from department;
DEPTNO DNAME
---------- -------------------------
10 accounting
20 research
30 sales
40 operations

6) Display different job type

SQL> select distinct job_type


2 from job;

JOB_TYPE
-------------------------
salesman
developer
clerk
accountant
analyst

7) List the employee in department 10 and 20 in alphabetical order.

SQL> select * from employee


2 where deptno=10 or deptno=20
3 order by ename;

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7876 adams 1100 20 7698 2222
23-MAY-87

7782 clark 2450 10 7839 4444


09-JUN-81

7902 ford 3000 20 7566 3333


12-MAR-81
E_ID ENAME SAL DEPTNO MAN_NO JOB_NO
---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7666 jones 2975 20 7839 4444
02-APR-81

7839 king 5000 10 7698 5555


17-NOV-81

7934 miller 1300 10 7782 2222


23-JAN-82

E_ID ENAME SAL DEPTNO MAN_NO JOB_NO


---------- ------------------------- ---------- ---------- ---------- ----------
DOJ DOB COMM
--------- --------- ----------
7788 scott 3000 20 7566 3333
19-APR-81

7369 smith 800 20 7902 2222


17-DEC-80

8 rows selected.

8) List the name and job of all clerk in dept 20.

SQL> select ename,job_type


2 from employee,job
3 where deptno=20 and job_type='clerk'
4 and job_no=j_no;

ENAME JOB_TYPE
------------------------- -------------------------
smith clerk
adams clerk

9) Display all employees having 'th' or '||' in their name.


SQL> select ename from employee
2 where ename like '%th%' or ename like '%ll%';

ENAME
-------------------------
smith
allen
miller
10) List name,job number and salary of all employess who have a manager.

SQL> select ename,sal,job_no


2 from employee
3 where man_no is not null;

ENAME SAL JOB_NO


------------------------- ---------- ----------
smith 800 2222
allen 1600 1111
ward 1250 1111
jones 2975 4444
martin 1250 1111
blake 2850 4444
clark 2450 4444
scott 3000 3333
turner 1500 1111
adams 1100 2222
james 950 2222

ENAME SAL JOB_NO


------------------------- ---------- ----------
ford 3000 3333
miller 1300 2222

13 rows selected.

11) List name and total salary of employees.


SQL> select ename,sal
2 from employee;

ENAME SAL
------------------------- ----------
smith 800
allen 1600
ward 1250
jones 2975
martin 1250
blake 2850
clark 2450
scott 3000
king 5000
turner 1500
adams 1100

ENAME SAL
------------------------- ----------
james 950
ford 3000
miller 1300
14 rows selected.

12) Display all employees hired during 1981

SQL> select ename from employee


2 where doj like '_______81';

ENAME
-------------------------
allen
ward
jones
martin
blake
clark
scott
king
turner
james
ford
11 rows selected.

13) Display name, salary and commissiom of all employees whose monthly
salay is greater than commission.

SQL> select ename,sal,comm


2 from employee
3 where sal>comm;

ENAME SAL COMM


------------------------- ---------- ----------
allen 1600 300
ward 1250 500

14) Select data as Smith has worked in the position of clerk in department 20.

SQL> select ename,deptno,job_type


2 from employee,job
3 where ename='smith'
4 and job_no=j_no;

ENAME DEPTNO JOB_TYPE


------------------------- ---------- -------------------------
smith 20 clerk

15) List employee name and salary increased by 15% and express as whole
number.
SQL> select ename,round(sal+0.15*sal) as inc_sal
2 from employee;

ENAME INC_SAL
------------------------- ----------
smith 920
allen 1840
ward 1438
jones 3421
martin 1438
blake 3278
clark 2818
scott 3450
king 5750
turner 1725
adams 1265

ENAME INC_SAL
------------------------- ----------
james 1093
ford 3450
miller 1495

14 rows selected.

16) Produce the following output


Employee_and_job
Smith Clerk
Allen salesman

SQL> select ename||' '||job_type as employee_and_job


2 from employee,job
3 where job_no=j_no
4 and ename in('allen','smith');

EMPLOYEE_AND_JOB
---------------------------------------------------
smith clerk
allen salesman

17) Produce the following output


Employee
Smith(clerk)
Allen(Salesman)
SQL> select ename||'('||job_type||')' as employee
2 from employee,job
3 where job_no=j_no
4 and ename in('smith','allen');

EMPLOYEE
----------------------------------------------------
smith(clerk)
allen(salesman)

18) It has been discovered that sales people in department 30 are not all
males.
Please produce the following output
Ename deptno job
Allen 30 salesman

SQL> select ename,deptno,job_type as job


2 from employee,job
3 where job_no=j_no
4 and ename = 'allen';

ENAME DEPTNO JOB


------------------------- ---------- -------------------------
allen 30 salesman

19) Display each employee name and hired date of dept 20.
SQL> select ename,doj from employee
2 where deptno=20;

ENAME DOJ
------------------------- ---------
smith 17-DEC-80
jones 02-APR-81
scott 19-APR-81
adams 23-MAY-87
ford 12-MAR-81

20) Display each employee name, hired date and salary review date.Assume
that salary review date is 1 year from hired date.Output should be in ascending
review date.

SQL> select ename,doj,add_months(doj,12) as sal_review


2 from employee;
ENAME DOJ SAL_REVIE
------------------------- --------- ---------
smith 17-DEC-80 17-DEC-81
allen 20-FEB-81 20-FEB-82
ward 22-FEB-81 22-FEB-82
jones 02-APR-81 02-APR-82
martin 28-SEP-81 28-SEP-82
blake 01-MAY-81 01-MAY-82
clark 09-JUN-81 09-JUN-82
scott 19-APR-81 19-APR-82
king 17-NOV-81 17-NOV-82
turner 08-SEP-81 08-SEP-82
adams 23-MAY-87 23-MAY-88

ENAME DOJ SAL_REVIE


------------------------- --------- ---------
james 12-MAR-81 12-MAR-82
ford 12-MAR-81 12-MAR-82
miller 23-JAN-82 23-JAN-83

14 rows selected.

21- Write query which return the day of the week(i.e. next Monday) for any date
in the date of joining field.

SQL> select next_day('22-feb-1981','saturday') from employee


2 where e_id=7521;

NEXT_DAY(
---------
28-FEB-81
1-Design the following table:-

emp(Eno,Name,Addr,Qual,courseid,dept,design,dob,doj).
Accounts (Eno, Basic_sal, DA, HRA, PF, Gross_sal).
Training (Courseid, Course_name).

(a) emp(Eno,Name,Addr,Qual,courseid,dept,design,dob,doj).

SQL> create table emp


2 (eno number not null,
3 name varchar(25),
4 addr varchar(25),
5 qual varchar(25),
6 courseid varchar(25),
7 dept varchar(25),
8 design varchar(25),
9 dob date,
10 doj date);

Table created.

SQL> insert into emp


values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
doj'
);

Enter value for eno: 1


Enter value for name: richa
Enter value for addr: india
Enter value for qual: MCA
Enter value for courseid: c1
Enter value for dept: system
Enter value for design: manager
Enter value for dob: 01-jan-1960
Enter value for doj: 02-feb-1986
old 1: insert into emp
values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
new 1: insert into emp values(1,'richa','india','MCA','c1','system','manager','01-jan-1960','02-
fe

1 row created.

SQL> /
Enter value for eno: 2
Enter value for name: alex
Enter value for addr: canada
Enter value for qual: MBA
Enter value for courseid: c2
Enter value for dept: marketing
Enter value for design: trainee
Enter value for dob: 02-jun-1965
Enter value for doj: 03-mar-1985
old 1: insert into emp
values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
new 1: insert into emp values(2,'alex','canada','MBA','c2','marketing','trainee','02-jun-
1965','03

1 row created.

SQL> /
Enter value for eno: 3
Enter value for name: allen
Enter value for addr: usa
Enter value for qual: MBA
Enter value for courseid: c3
Enter value for dept: accounts
Enter value for design: manager
Enter value for dob: 17-jul-1975
Enter value for doj: 23-oct-1995
old 1: insert into emp
values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
new 1: insert into emp values(3,'allen','usa','MBA','c3','accounts','manager','17-jul-1975','23-
oc

1 row created.

SQL> /
Enter value for eno: 4
Enter value for name: smith
Enter value for addr: austria
Enter value for qual: MPHIL
Enter value for courseid: c4
Enter value for dept: system
Enter value for design: exec
Enter value for dob: 05-apr-1972
Enter value for doj: 12-jan-1995
old 1: insert into emp
values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
new 1: insert into emp values(4,'smith','austria','MPHIL','c4','system','exec','05-apr-1972','12-
j

1 row created.
SQL> /
Enter value for eno: 5
Enter value for name: miller
Enter value for addr: uk
Enter value for qual: MCA
Enter value for courseid: c5
Enter value for dept: research
Enter value for design: trainee
Enter value for dob: 25-nov-1955
Enter value for doj: 01-feb-1982
old 1: insert into emp
values(&eno,'&name','&addr','&qual','&courseid','&dept','&design','&dob','&
new 1: insert into emp values(5,'miller','uk','MCA','c5','research','trainee','25-nov-1955','01-
fe

1 row created.

SQL> alter table emp


2 add primary key(eno);

Table altered.
SQL> alter table emp
2 add foreign key(courseid) references training(courseid);

Table altered.

SQL> select * from emp;

ENO NAME ADDR


---------- ------------------------- -------------------------
QUAL COURSEID DEPT
------------------------- ------------------------- -------------------------
DESIGN DOB DOJ
------------------------- --------- ---------
1 richa india
MCA c1 system
manager 01-JAN-60 02-FEB-86

2 alex canada
MBA c2 marketing
trainee 02-JUN-65 03-MAR-85
ENO NAME ADDR
---------- ------------------------- -------------------------
QUAL COURSEID DEPT
------------------------- ------------------------- -------------------------
DESIGN DOB DOJ
------------------------- --------- ---------

3 allen usa
MBA c3 accounts
manager 17-JUL-75 23-OCT-95

4 smith austria
MPHIL c4 system

ENO NAME ADDR


---------- ------------------------- -------------------------
QUAL COURSEID DEPT
------------------------- ------------------------- -------------------------
DESIGN DOB DOJ
------------------------- --------- ---------
exec 05-APR-72 12-JAN-95

5 miller uk
MCA c5 research
trainee 25-NOV-55 01-FEB-82

(b)Accounts (Eno, Basic_sal, DA, HRA, PF, Gross_sal).

SQL> create table accounts


2 (eno number,
3 basic_sal number,
4 da number,
5 hra number,
6 pf number,
7 gross_sal number);

Table created.
SQL> insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal);
Enter value for eno: 1
Enter value for basic_sal: 3000
Enter value for da: 800
Enter value for hra: 800
Enter value for pf: 800
Enter value for gross_sal: 5400
old 1: insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal)
new 1: insert into accounts values(1,3000,800,800,800,5400)

1 row created
SQL> /
Enter value for eno: 2
Enter value for basic_sal: 1000
Enter value for da: 100
Enter value for hra: 200
Enter value for pf: 200
Enter value for gross_sal: 1500
old 1: insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal)
new 1: insert into accounts values(2,1000,100,200,200,1500)

1 row created.

SQL> /
Enter value for eno: 3
Enter value for basic_sal: 3500
Enter value for da: 100
Enter value for hra: 500
Enter value for pf: 400
Enter value for gross_sal: 4500
old 1: insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal)
new 1: insert into accounts values(3,3500,100,500,400,4500)

1 row created.

SQL> /
Enter value for eno: 4
Enter value for basic_sal: 5000
Enter value for da: 100
Enter value for hra: 200
Enter value for pf: 200
Enter value for gross_sal: 5500
old 1: insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal)
new 1: insert into accounts values(4,5000,100,200,200,5500)

1 row created.

SQL> /
Enter value for eno: 5
Enter value for basic_sal: 4500
Enter value for da: 0
Enter value for hra: 500
Enter value for pf: 500
Enter value for gross_sal: 5500
old 1: insert into accounts values(&eno,&basic_sal,&da,&hra,&pf,&gross_sal)
new 1: insert into accounts values(5,4500,0,500,500,5500)
1 row created.
SQL> alter table accounts
2 add foreign key(eno) references emp(eno);

Table altered.

SQL> select * from accounts;

ENO BASIC_SAL DA HRA PF GROSS_SAL


---------- ---------- ---------- ---------- ---------- ----------
1 3000 800 800 800 5400
2 1000 100 200 200 1500
3 3500 100 500 400 4500
4 5000 100 200 200 5500
5 4500 0 500 500 5500

(c) Training(Courseid,Course_name).
SQL> create table training
2 (
3 courseid varchar(25) not null,
4 course_name varchar(25));

Table created.

SQL> insert into training values('&courseid','&c_name');


Enter value for courseid: c1
Enter value for c_name: oracle
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c1','oracle')

1 row created.

SQL> /
Enter value for courseid: c2
Enter value for c_name: unix
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c2','unix')

1 row created.

SQL> /
Enter value for courseid: c3
Enter value for c_name: sql
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c3','sql')
1 row created.
SQL> /
Enter value for courseid: c4
Enter value for c_name: c++
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c4','c++')

1 row created.

SQL> /
Enter value for courseid: c5
Enter value for c_name: c
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c5','c')

1 row created.

SQL> /
Enter value for courseid: c6
Enter value for c_name: graphics
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c6','graphics')

1 row created.

SQL> /
Enter value for courseid: c7
Enter value for c_name: java
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c7','java')

1 row created.

SQL> /
Enter value for courseid: c8
Enter value for c_name: networking
old 1: insert into training values('&courseid','&c_name')
new 1: insert into training values('c8','networking')

1 row created.

SQL> alter table training


2 add primary key(courseid);

Table altered.
SQL> select * from training;

COURSEID COURSE_NAME
------------------------- -------------------------
c1 oracle
c2 unix
c3 sql
c4 c++
c5 c
c6 graphics
c7 java
c8 networking

8 rows selected.

2-Select name of all employees in system department

SQL> select name from emp


2 where dept='system';

NAME
-------------------------
richa
smith

3-Select employee number and qualification of all employees in marketing department


and those whose name start with A.

SQL> select eno,qual


2 from emp
3 where dept='marketing' and
4 name like 'a%';

ENO QUAL
---------- -------------------------
2 MBA
4-Select EMP No. of all employees whose basic range of 3000 to 5000.

SQL> select e.eno


2 from emp e,accounts a
3 where a.basic_sal between 3000 and 5000
4 and e.eno=a.eno;

ENO
----------
1
3
4
5

5-Select employees no of all employees who do not belongs to accounts department.

SQL> select eno from emp


2 where dept <> 'accounts';

ENO
----------
1
2
4
5

6-Select employee no of all those employees whose gross pay is greaster than 5000
and basic is less than 4000

SQL> select eno from accounts


2 where gross_sal>5000 and basic_sal<4000;

ENO
----------
1
7-Select that employee whose designation is either manager , executive, sr. executive
and belongs to system department.

SQL> select name from emp


2 where design='manager' or design='exec' or design='sr_exec'
3 and dept='system';

NAME
-------------------------
richa
allen
smith

8-Find out the names of the existing departments in this office.

SQL> select distinct(dept) from emp;

DEPT
-------------------------
accounts
system
marketing
research

9-Extract names of those employees who got appointed after completion of 25 years
of age.

SQL> select name from emp


2 where doj> add_months(dob,300);

NAME
-------------------------
richa
miller
10-"Extract names, date of birth, date of joining of all employees with columns as :
NAME DATE_OF_BIRTH DATE_OF_JOINING"

SQL> select name as NAME,


2 dob as DATE_OF_BIRTH,
3 doj as DATE_OF_JOINING
4 from emp;

NAME DATE_OF_B DATE_OF_J


------------------------- --------- ---------
richa 01-JAN-60 02-FEB-86
alex 02-JUN-65 03-MAR-85
allen 17-JUL-75 23-OCT-95
smith 05-APR-72 12-JAN-95
miller 25-NOV-55 01-FEB-82

11-Extract the names, department and designation of all employees sorted according
to the names in descending order within departments in ascending order.

SQL> select name,dept,design


2 from emp
3 order by name DESC,dept;

NAME DEPT DESIGN


------------------------- ------------------------- -------------------------
smith system exec
richa system manager
miller research trainee
allen accounts manager
alex marketing trainee

12-All the employees have been given a phone number,so to keep records of phone
number a new field needs to get added .Modify the structure of the Table.

SQL> alter table emp


2 add phone_no number;

Table altered.
13-Annual increments of all employees were 10% of basic. Update appropriate table.

SQL> update accounts


2 set gross_sal= basic_sal*1.1;

5 rows updated.

SQL> select gross_sal from accounts;

GROSS_SAL
----------
3300
1100
3850
5500
4950

14-Employee relation needs to be renamed as personal.Alter the name of the table.

SQL> alter table emp


2 rename to personal;

Table altered.

15 Count total number of employees , max salary, min salary, total salary and avg
salary paid to employees

SQL> select
count(e.name),max(a.gross_sal),min(a.gross_sal),sum(a.gross_sal),avg(a.gross_sal)
2 from personal e,accounts a
3 where e.eno=a.eno;

COUNT(E.NAME) MAX(A.GROSS_SAL) MIN(A.GROSS_SAL) SUM(A.GROSS_SAL)


------------- ---------------- ---------------- ----------------
AVG(A.GROSS_SAL)
----------------
5 5500 1100 18700
3740

Vous aimerez peut-être aussi