Académique Documents
Professionnel Documents
Culture Documents
Course(course_id,c_name)
Table created.
course_fee(course_id,c_fee)
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)
Table created.
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.
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.
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.
Table altered.
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.
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.
Table altered.
COURSEID CNAME
-------------------- --------------------
ora101 oracle
ora102 oracle
ora105 oracle
uni101 unix
uni102 unix
sof101 se
c101 clang
7 rows selected.
10 rows selected.
1 ora102 02-OCT-05
bsc
rtificate
2 uni102 08-SEP-01
4 gra102 06-SEP-04
bcom
rtificate
5 c102 15-JUN-09
bca
3 uni102 20-JUL-08
bcom
rtificate
3 c102 22-JUL-08
bcom
rtificate
7 rows selected.
SQL> select * from installment;
S_NAME
--------------------
asif
manali
meenal
sparsh
harsh
9-Retrieve names and course_id of all students
S_NAME COURSEID
-------------------- --------------------
asif ora101
asif ora102
manali uni102
sparsh gra102
harsh c102
meenal uni102
meenal c102
7 rows selected.
CNAME
--------------------
unix
se
clang
oracle
S_NAME
--------------------
Asif
12- Print the names of students whose total amount is not equal to the amount
due.
S_NAME
--------------------
meenal
harsh
13) Count the number of students who have joined in the current year.
COUNT(*)
----------
1
15- Print the details of course whose fees is more than 500 but less than
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.
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.
S_NAME
--------------------
Meenal
MAX_PRICE MIN_PRICE
---------- ----------
1050 300
COUNT(*)
----------
2
20- Get the sum of amount to be collected from student in AUGUST
SUM(AMT_PAID)
-------------
1050
Table altered.
Table altered.
DATE_ADMSN
---------------
01-august -10
02-september-07
10-may -06
10-october -01
19-january -02
2 rows updated.
COURSEID CNAME
-------------------- --------------------
ora101 oracle
ora102 oracle
ora105 oracle
uni101 U.O.S
uni102 U.O.S
sof101 se
c101 clang
7 rows selected.
NEW_FEE
----------
1500
1550
1500
26-Display the names of all students who have to pay installments within next
three months.
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).
Table created.
Table altered.
Table altered.
Table altered.
Table altered.
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).
Table created.
Table altered.
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.
DEPTNO DNAME
---------- -------------------------
10 accounting
20 research
30 sales
40 operations
c) JOB(JOB_TYPE,J_NO,J_PERFORMED).
Table created.
Table altered.
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.
d) Manager(M_NAME,M_NO).
Table created.
Table altered.
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.
M_NAME M_NO
------------------------- ----------
ford 7902
blake 7698
king 7839
jones 7566
scott 7788
clark 7782
6 rows selected.
4) List the detail of employee having salary between 1000 and 2000.
6 rows selected.
JOB_TYPE
-------------------------
salesman
developer
clerk
accountant
analyst
8 rows selected.
ENAME JOB_TYPE
------------------------- -------------------------
smith clerk
adams clerk
ENAME
-------------------------
smith
allen
miller
10) List name,job number and salary of all employess who have a manager.
13 rows selected.
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.
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.
14) Select data as Smith has worked in the position of clerk in department 20.
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.
EMPLOYEE_AND_JOB
---------------------------------------------------
smith clerk
allen salesman
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
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.
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.
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).
Table created.
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.
Table altered.
SQL> alter table emp
2 add foreign key(courseid) references training(courseid);
Table altered.
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
5 miller uk
MCA c5 research
trainee 25-NOV-55 01-FEB-82
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.
(c) Training(Courseid,Course_name).
SQL> create table training
2 (
3 courseid varchar(25) not null,
4 course_name varchar(25));
Table created.
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.
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.
NAME
-------------------------
richa
smith
ENO QUAL
---------- -------------------------
2 MBA
4-Select EMP No. of all employees whose basic range of 3000 to 5000.
ENO
----------
1
3
4
5
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
ENO
----------
1
7-Select that employee whose designation is either manager , executive, sr. executive
and belongs to system department.
NAME
-------------------------
richa
allen
smith
DEPT
-------------------------
accounts
system
marketing
research
9-Extract names of those employees who got appointed after completion of 25 years
of age.
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"
11-Extract the names, department and designation of all employees sorted according
to the names in descending order within departments in ascending order.
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.
Table altered.
13-Annual increments of all employees were 10% of basic. Update appropriate table.
5 rows updated.
GROSS_SAL
----------
3300
1100
3850
5500
4950
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;