Practical 1: Describe Deposit, Branch. Query: Describe Deposit Output

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

PRACTICAL 1

 DESCRIBE DEPOSIT,BRANCH.

Query:
DESCRIBE DEPOSIT
Output:

Lengt Precisio Scal Primary Nullabl Defaul Commen


Table Column Data Type h n e Key e t t

VARCHAR
DEPOSIT ACTNO 5 - - - - -
2

VARCHAR
  CNAME 18 - - - - -
2

VARCHAR
  BNAME 18 - - - - -
2

AMOUN
  NUMBER - 8 2 - - -
T

  ADATE DATE 7 - - - - -

1-5

Query:

SELECT *FROM DEPOSIT

Output:

AM
OUN ADA
ACTNO CNAME BNAME T TE
01/03
100 ANIL VRCE 1000
/0095
04/01
101 SUNIL AJNI 5000
/0096
11/17
102 MEHUL KAROLBAGH 3500
/0095
12/17
104 MADHURI CHANDI 1200
/0095
03/27
105 PRMOD M.G.ROAD 3000
/0096
03/31
106 SANDIP ANDHERI 2000
/0096
107 SHIVANI VIRAR 1000 09/05
/0095
07/02
108 KRANTI NEHRU PLACE 5000
/0095
08/10
109 MINU POWAI 7000
/0095
9 rows returned in 0.01 seconds

Query:
DESCRIBE BRANCH

Output:

Colu Data Len Preci Sc Primar Null Def Com


Table mn Type gth sion ale y Key able ault ment

BNA VARC
BRANCH 18 - - - - -
ME HAR2

VARC
  CITY 18 - - - - -
HAR2

1-2

2.DESCRIBE BORROW,CUSTOMERS.
Query:

DESCRIBE BORROW

Output:

Colu Data Len Preci Sc Primar Null Def Com


Table mn Type gth sion ale y Key able ault ment

LOA VARC
BORROW 5 - - - - -
NNO HAR2

CNA VARC
  19 - - - - -
ME HAR2

BNA VARC
  18 - - - - -
ME HAR2

AMO NUM
  - 8 2 - - -
UNT BER

1-4

Query:
DESCRIBE CUSTOMERS

Output:

Sc
Data Len Preci al Primar Null Def Com
Table Type gth sion e y Key able ault ment

VARC
CUSTOMERS 19 - - - - -
HAR2

VARC
  18 - - - - -
HAR2

1-2

3.List all data from table DEPOSIT

Query:

SELECT *FROM DEPOSIT

Output:

ACTNO CNAME BNAME AMOUNT ADATE


100 ANIL VRCE 1000 01/03/0095
101 SUNIL AJNI 5000 04/01/0096
102 MEHUL KAROLBAGH 3500 11/17/0095
104 MADHURI CHANDI 1200 12/17/0095
105 PRMOD M.G.ROAD 3000 03/27/0096
106 SANDIP ANDHERI 2000 03/31/0096
107 SHIVANI VIRAR 1000 09/05/0095
108 KRANTI NEHRU PLACE 5000 07/02/0095
109 MINU POWAI 7000 08/10/0095

9 rows returned in 0.07 seconds

4.List all data from table BORROW

Query:

SELECT *FROM BORROW

Output:

LOANNO CNAME BNAME AMOUNT


201 ANIL VRCE 1000
206 MEHUL AJNI 5000
311 SUNIL DHARAMPETH 3000
321 MADHURI ANDHERI 2000
375 PRMOD VIRAR 8000
481 KRANTI NEHRU PLACE 3000

6 rows returned in 0.03 seconds 

5.List all data from table CUSTOMERS

Query:

SELECT *FROM CUSTOMERS:

Output:

CNAME CITY
ANIL CALCUTTA
SUNIL DELHI
MEHUL BARODA
MANDAR PATNA
MADHURI NAGPUR
PRMOD NAGPUR
SANDIP SURAT
SHIVANI BOMBAY
KRANTI BOMBAY
NAREN BOMBAY

10 rows returned in 0.05 seconds

6.List all data from table BRANCH.

Query:

SELECT *FROM BRANCH

Output:

BNAME CITY

VRCE NAGPUR

AJNI NAGPUR
KAROLBAGH DELHI

CHANDI DELHI

DHARAMPETH NAGPUR

M.G.ROAD BANGLARE

ANDHERI BOMBAY

VIRAR BOMBAY

NEHRU PLACE DELHI

POWAI BOMBAY

10 rows returned in 0.00 seconds    


7.Give account no and amount of deositors.

Query:

SELECT ACTNO,AMOUNT FROM DEPOSIT

Output:

ACTNO AMOUNT
100 1000
101 5000
102 3500
104 1200
105 3000
106 2000
107 1000
108 5000
109 7000
9 rows returned in 0.01 seconds

8.Give name of depositors having amount greater than 4000.

Query:
SELECT CNAME FROM DEPOSIT WHERE AMOUNT>4000

Output:

CNAME
SUNIL
KRANTI
MINU
9.Give name of customers who opened account after date ‘1-12-96’.

Query:

SELECT CNAME FROM DEPOSIT WHERE ADATE>'01-12-96'

Output:

CNAME
SUNIL
PRMOD
SANDIP
3 rows
returned in
0.01
seconds
PRACTICAL : 2

Query:
SELECT *FROM Job

Output:

JOB_ID JOB_TITLE MIN_SAL MAX_SAL


IT_PROG Programmer 4000 10000
MK_MGR Marketing manager 9000 15000
FI_MGR Finance manager 8200 12000
FI_ACC Account 4200 9000
LEC Lecturer 6000 17000
COMP_OP Computer Operator 1500 3000
6 rows returned in 0.00 seconds

Query:
SELECT *FROM Employee

Output:
EMP_NAM EMP_SA EMP_COM DEPT_N EMP_LASTNAM
EMP_NO E L M O E HIRE_DATE
101 Smith 800 - 10 sharma 05/21/0096
102 Jenita 1600 300 25 John 03/30/0095
103 John 1100 0 20 John -
104 Jenita 3000 - 10 John 07/12/0097
105 Anita 5000 50000 10 John 01/27/0095
106 Sneha 2450 24500 10 sharma 07/27/0095
107 Anamika 2975 - 30 John 07/07/0095
7 rows returned in 0.05
seconds

Query:
SELECT *FROM deposit1
Output:
A_NO CNAME BNAME AMOUNT A_DATE
101 Anil andheri 7000 01/01/0006
102 sunil virar 5000 07/15/0006
103 jay villeparle 6500 03/12/0006
104 vijay andheri 8000 09/17/0006
105 keyur dadar 7500 11/17/0006
106 mayur borivali 5500 12/21/0006

6 rows returned in 0.02 seconds

2.Give details of account no. and deposited rupees of customers having accout opened between
dates 01-01-06 and 25-07-06.
Query:
select A_no, amount from deposit1 where a_date between '01-01-06' and '07-25-06'
Output:

A_NO AMOUNT

101 7000

102 5000

103 6500

3 rows returned in 0.00 seconds  

3.Display all jobs with miimum salary is greater than 4000.


Qury:
select job_title from JOb where min_sal>4000
Output:

JOB_TITLE
Marketing manager
Finance manager
Account
Lecturer
4 rows returned in 0.09 seconds

4.Display employee no,name and department details of those employee whose department lies in
(10,20).
Query:
select emp_no,emp_name,dept_no from employee where dept_no in (10,20)

Output:
EMP_NO EMP_NAME DEPT_NO
101 Smith 10
103 John 20
104 Jenita 10
105 Anita 10
106 Sneha 10
5.Display name and salary of employees whose department no. is 20.
Query:
select emp_name, emp_sal from employee where dept_no='20'

Output:

EMP_NAME EMP_SAL
John 1100
To study various options of LIKE predicate.

1.Display all employee whose name start with ‘A’ and third character is ‘a’.

Query:

select emp_name from employee where emp_name like 'A_a%'

Output:

EMP_NAME
Anamika
1 rows returned in 0.00 seconds

2.Display name ,number and salary of those employees whose name is 5 characters long and first
three characters are ‘Ani’.

Query:

select emp_name,emp_no,emp_sal from employee where emp_name like 'Ani__'

Output:

EMP_NAME EMP_NO EMP_SAL


Anita 105 5000

3.Display the non null values of employees and also employee name second character should be ‘n’
and string should be 5 characters long.

Query:

select *from employee where emp_name like '_n___' and emp_no is not null and emp_name is not
null and emp_comm is not null and dept_no is not null
Output:

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME HIRE_DATE


105 Anita 5000 50000 10 John 01/27/0095
106 Sneha 2450 24500 10 sharma 07/27/0095
2 rows returned in 0.01
seconds

4.Display the null values of employee and also employee name’s third character should be ‘a’.

Query:

select *from employee where emp_no is null or emp_name is null or emp_sal is null or emp_comm
is null or dept_no is null and emp_name like '__a%'

Output:

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME HIRE_DATE


101 Smith 800 - 10 sharma 05/21/0096
104 Jenita 3000 - 10 John 07/12/0097
107 Anamika 2975 - 30 John 07/07/0095
3 rows returned in 0.00
seconds

5.What will be output if you are giving LIKE predicate as ‘%\_%’ESCAPE’\’

Query:

select *from employee where emp_name like '%\_%'ESCAPE'\'

Output:

no data found

PRACTICAL 3: To perform various data manipulation commands , aggregate functions and sorting
concept on all created tables.

1.List all total deposit from deposit.

Query:

select sum(amount) from deposit1

Output:

SUM(AMOUNT)
39500
1 rows returned in 0.00 seconds

2.List all loan from karolbagh branch.


Query:

select sum(amount) from borrow where bname ='KAROLBAGH'

Output:

SUM(AMOUNT)

1 rows returned in 0.00 seconds  

3.Give maximum loan from branch vrce.

Query:

select max(amount) from borrow where bname ='VRCE'

Output:

MAX(AMOUNT)

1000

1 rows returned in 0.00 seconds  

4.Count total numbers of customers .

Query:

select count(distinct cname) from customers

Output:

COUNT(DISTINCTCNAME)
10
1 rows returned in 0.00 seconds

5.Count total number of customers cities.

Query:

select count(distinct city) from customers

Output:

COUNT(DISTINCTCITY)
7
1 rows returned in 0.00 seconds
6. Create table supplier from employee with all the columns .

Query:

create table supplier1(sup_no,sup_name,sup_sal,sup_comm,status_no)as select *from employee

7. Create table sup1 from employee with first two columns.

Query:

create table sup1(cust_no,cust_name)as select emp_no,emp_name from employee

8. Create table sup2 from employee with no data.

Query:

create table sup2 as select *from employee

9.Create table sup2 from employee whose second chsracter should be ‘n’ and string should be 5 characters long
in employee name field.

Query:

select emp_name from employee where emp_name like '_n___'

Output:

EMP_NAME
Anita
Sneha
Query:

insert into sup2 (select *from employee where emp_name like '_n___')

Output:

2 row(s) inserted.
10.Delete all the rows from sup1
delete from sup1

7 row(s) deleted.

11.Delete the detail of supplier whose sup_no is 103.

Query:

delete from supplier1 where sup_no=103

Output:

1 row(s) deleted.

0.06 seconds
12.Rename the table sup1 with all the data.
Query:
rename sup2 to supplier2
Output:
Statement processed.

0.11 seconds
13.Destroy table sup1 with all the data.
drop table sup1

Output:

Table dropped.

0.32 seconds

14.Update the value dept_no to 10 where second character of emp.name is ‘m’.

update employee set dept_no =10 where emp_name like '_m%'

Output:

2 row(s) updated.

0.00 seconds
15.Update the value of employee name whose employee number is 103.

Query:

update employee set emp_name ='John' where emp_no=103

Output:

1 row(s) updated.

0.01 seconds
PRACTICAL 4: To study Single row functions.

1.Write a query to display the current date .Lable the column date.

Query:

select sysdate "Date" from dual

Output:

Date
10/05/2018

Query:

alter table employee add (emp_lastname varchar(23))

Output:

Table altered.
0.13 seconds
Query:

select *from employee

Output:

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME


101 Smith 800 - 10 -
102 Snehal 1600 300 25 -
103 John 1100 0 20 -
104 Amaan 3000 - 10 -
105 Anita 5000 50000 10 -
106 Sneha 2450 24500 10 -
107 Anamika 2975 - 30 -

7 rows returned in 0.01 seconds  

Query:

update employee set emp_lastname ='sharma' where emp_name like 'S%'

Output:

3 row(s) updated.

Query:

select *from employee

Output:

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME


101 Smith 800 - 10 sharma
102 Snehal 1600 300 25 sharma
103 John 1100 0 20 -
104 Amaan 3000 - 10 -
105 Anita 5000 50000 10 -
106 Sneha 2450 24500 10 sharma
107 Anamika 2975 - 30 -
update employee set emp_lastname ='John' where emp_name like 'A%'

3 row(s) updated.
select *from employee

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME


101 Smith 800 - 10 sharma
102 Snehal 1600 300 25 sharma
103 John 1100 0 20 -
104 Amaan 3000 - 10 John
105 Anita 5000 50000 10 John
106 Sneha 2450 24500 10 sharma
107 Anamika 2975 - 30 John
alter table employee add(hire_date date)

Table altered.
select *from employee

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME HIRE_DATE


101 Smith 800 - 10 sharma -
102 Snehal 1600 300 25 sharma -
103 John 1100 0 20 - -
104 Amaan 3000 - 10 John -
105 Anita 5000 50000 10 John -
106 Sneha 2450 24500 10 sharma -
107 Anamika 2975 - 30 John -
update employee set hire_date='07-12-97' where emp_no=104

1 row(s) updated.

0.01 seconds
update employee set hire_date='06-12-96' where emp_no=101

1 row(s) updated.

0.00 seconds
update employee set hire_date='05-21-96' where emp_no=101

1 row(s) updated.

0.00 seconds
update employee set hire_date='03-30-95' where emp_no=102

1 row(s) updated.

0.00 seconds
update employee set hire_date='01-27-95' where emp_no=105

1 row(s) updated.

0.00 seconds
update employee set hire_date='08-27-95' where emp_no=106

1 row(s) updated.

0.00 seconds

update employee set hire_date='07-07-95' where emp_no=107

1 row(s) updated.
0.00 seconds
select *from employee

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME HIRE_DATE


101 Smith 800 - 10 sharma 05/21/0096
102 Snehal 1600 300 25 sharma 03/30/0095
103 John 1100 0 20 - -
104 Amaan 3000 - 10 John 07/12/0097
105 Anita 5000 50000 10 John 01/27/0095
106 Sneha 2450 24500 10 sharma 08/27/0095
107 Anamika 2975 - 30 John 07/07/0095
7 rows returned in 0.00
 
seconds
2.For each employee ,display the employee number, job salary and salary increased by 15% and
expressed as a whole number.

Query:

select emp_no,emp_name,emp_sal,round(emp_sal*1.15,0)"new salary" from employee

EMP_NO EMP_NAME EMP_SAL new salary


101 Smith 800 920
102 Snehal 1600 1840
103 John 1100 1265
104 Amaan 3000 3450
105 Anita 5000 5750
106 Sneha 2450 2818
107 Anamika 2975 3421

Query:

select emp_no,emp_name,emp_sal,round(emp_sal+(emp_sal*15/100))"new salary" from employee

Output:

EMP_NO EMP_NAME EMP_SAL new salary


101 Smith 800 920
102 Snehal 1600 1840
103 John 1100 1265
104 Amaan 3000 3450
105 Anita 5000 5750
106 Sneha 2450 2818
107 Anamika 2975 3421
3.Modify your query no4.(2) to add a column that subtracts the old salary from the new salary .

Query:
select emp_no,emp_name,emp_sal,round(emp_sal*1.5,0)"New Salary",round (emp_sal*1.15,0)-
emp_sal "Increase" from employee

Output:

New
EMP_NO EMP_NAME EMP_SAL Salary Increase
101 Smith 800 1200 120
102 Snehal 1600 2400 240
103 John 1100 1650 165
104 Amaan 3000 4500 450
105 Anita 5000 7500 750
106 Sneha 2450 3675 368
107 Anamika 2975 4463 446

7 rows returned in 0.00 seconds      


Query:

select emp_no,emp_name,emp_sal,round(emp_sal+(emp_sal*15)/100)"New Salary",round


(emp_sal+(emp_sal*15/100))-emp_sal "Increase" from employee

Output:

New
EMP_NO EMP_NAME EMP_SAL Salary Increase
101 Smith 800 920 120
102 Snehal 1600 1840 240
103 John 1100 1265 165
104 Amaan 3000 3450 450
105 Anita 5000 5750 750
106 Sneha 2450 2818 368
107 Anamika 2975 3421 446
4. Write a query that displays the employee’s name with the first letter capitalized and all other
letters lower case and the length of the names for all employees whose name start with J,A or M.

Query:

select initcap(emp_name)"Name",length(emp_name)"Length"from employee where emp_name like


'A%'or emp_name like 'M%' or emp_name like 'J%'

Output:

Name Length
John 4
Amaan 5
Anita 5
Anamika 7
update employee set emp_name ='Jenita' where emp_no=102
1 row(s) updated.
update employee set emp_name ='Jenita' where emp_no=104

1 row(s) updated.
select *from employee

EMP_NO EMP_NAME EMP_SAL EMP_COMM DEPT_NO EMP_LASTNAME HIRE_DATE


101 Smith 800 - 10 sharma 05/21/0096
102 Jenita 1600 300 25 sharma 03/30/0095
103 John 1100 0 20 - -
104 Jenita 3000 - 10 John 07/12/0097
105 Anita 5000 50000 10 John 01/27/0095
106 Sneha 2450 24500 10 sharma 08/27/0095
107 Anamika 2975 - 30 John 07/07/0095
7 rows returned in 0.01
seconds
5. Write a query that produces the following for each employee : <employee last name >earns
<salary>monthly

Query:

select emp_lastname||'eams '||emp_sal||' monthly' from employee

EMP_LASTNAME||'EAMS'||EMP_SAL||'MONTHLY'
sharmaeams 800 monthly
sharmaeams 1600 monthly
eams 1100 monthly
Johneams 3000 monthly
Johneams 5000 monthly
sharmaeams 2450 monthly
Johneams 2975 monthly
7.Display the hire date of employee ina format that appears as seventh of june 1994 12:00:00 AM.

Query:

select emp_name,to_char(hire_date,'ddspth "of" month yyyy hh:mi:ss A.M.')from employee

Output:

EMP_NAME TO_CHAR(HIRE_DATE,'DDSPTH"OF"MONTHYYYYHH:MI:SSA.M.')
Smith twenty-first of may 0096 12:00:00 A.M.
Jenita thirtieth of march 0095 12:00:00 A.M.
John -
Jenita twelfth of july 0097 12:00:00 A.M.
Anita twenty-seventh of january 0095 12:00:00 A.M.
Sneha twenty-seventh of august 0095 12:00:00 A.M.
Anamika seventh of july 0095 12:00:00 A.M
Query:

select emp_name,to_char(hire_date,'ddspth "of" month yyyy hh:mi:ss P.M.')from employee

EMP_NAME TO_CHAR(HIRE_DATE,'DDSPTH"OF"MONTHYYYYHH:MI:SSP.M.')
Smith twenty-first of may 0096 12:00:00 A.M.
Jenita thirtieth of march 0095 12:00:00 A.M.
John -
Jenita twelfth of july 0097 12:00:00 A.M.
Anita twenty-seventh of january 0095 12:00:00 A.M.
Sneha twenty-seventh of august 0095 12:00:00 A.M.
Anamika seventh of july 0095 12:00:00 A.M.
select emp_name,to_char(hire_date,'ddspth "of" month yyyy hh:mi:ss P.M.')"Hire Date and Time
"from employee

EMP_NAME Hire Date and Time


Smith twenty-first of may 0096 12:00:00 A.M.
Jenita thirtieth of march 0095 12:00:00 A.M.
John -
Jenita twelfth of july 0097 12:00:00 A.M.
Anita twenty-seventh of january 0095 12:00:00 A.M.
Sneha twenty-seventh of august 0095 12:00:00 A.M.
Anamika seventh of july 0095 12:00:00 A.M.

PRACTICAL 5:

Display data from multiple tables(join)

2.Give name of customer who are borrowers and depositors and having living city Nagpur.

Query:

select c.cname from customers c,deposit d,borrow b where c.city='NAGPUR' and c.cname=d.cname
and d.cname=b.cname;

Output:

CNAME
MADHURI
PRMOD
3.Give city as their city name of cusomers having same living branch.

Query:

select c.cname from customers c,deposit d,branch b where c.city=b.city and d.cname=c.cname and
d.bname =b.bname
Output:

CNAME
SHIVANI
update employee set emp_lastname ='sharma' where emp_name like 'S%'

2 row(s) updated.

0.00 seconds

update employee set emp_lastname ='John' where emp_name like 'A%'

2 row(s) updated.

0.01 seconds

update employee set hire_date ='07-12-97' where emp_no=1041 row(s) updated.

0.01 seconds
update employee set hire_date ='06-12-96' where emp_no=101

1 row(s) updated.

0.01 seconds
update employee set hire_date ='05-21-96' where emp_no=101

1 row(s) updated.

0.00 seconds
update employee set hire_date ='03-30-95' where emp_no=102

1 row(s) updated.

0.00 seconds
update employee set hire_date ='01-27-95' where emp_no=105

1 row(s) updated.

0.00 seconds

update employee set hire_date ='07-27-95' where emp_no=106

1 row(s) updated.

0.00 seconds
update employee set hire_date ='07-07-95' where emp_no=107

1 row(s) updated.

0.00 seconds
alter table employee modify(emp_name varchar(15))

Table altered.

0.07 seconds
alter table employee modify(emp_lastname varchar(10))

Table altered.
0.01 seconds
select *from employee

EMP_NAM EMP_SA EMP_COM DEPT_N EMP_LASTNAM


EMP_NO E L M O E HIRE_DATE
101 Smith 800 - 10 Sharma 05/21/0096
102 Jenita 1600 300 25 John 03/30/0095
103 John 1100 0 20 John -
104 Jenita 3000 - 10 John 07/12/0097
105 Anita 5000 50000 10 John 01/27/0095
106 Sneha 2450 24500 10 Sharma 07/27/0095
107 Anamika 2975 - 30 John 07/07/0095
7 rows returned in 0.00
         Download
seconds
select *from Job

JOB_ID JOB_TITLE MIN_SAL MAX_SAL


IT_PROG Programmer 4000 10000
Marketing
MK_MGR 9000 15000
manager
FI_MGR Finance manager 8200 12000
FI_ACC Account 4200 9000
LEC Lecturer 6000 17000
Computer
COMP_OP 1500 3000
Operator
create table department(deptid number ,deptname varchar(10))

Table created.

0.06 seconds
insert into department values('10','IT')

1 row(s) inserted.

0.00 seconds
insert into department values('15','CIVIL')

1 row(s) inserted.

0.00 seconds

insert into department values('11','CE')

1 row(s) inserted.

0.01 seconds
insert into department values('20','CSE')

1 row(s) inserted.

0.01 seconds
select *from department
DEPTID DEPTNAME
10 IT
11 CE
11 CE
20 CSE
30 ME
15 CIVIL
25 CE
31 EEE
4.Write a query to display the last name, department number and department name for all
employees.

Query:

select e.emp_lastname , e.dept_no, d.deptname from employee e, department d where e.dept_no =


d.deptid

Output:

EMP_LASTNAME DEPT_NO DEPTNAME


Sharma 10 IT
John 10 IT
John 10 IT
Sharma 10 IT
John 20 CSE
John 30 ME
John 25 CE

7 rows returned in 0.07 seconds


Query:

create table employee1(emp_id number ,emp_name varchar(10),emp_sal number , job_id number)

Output:

Table created.

0.05 seconds

insert into employee1 values('1','John','20000','3')


1 row(s) inserted.

0.00 seconds

Query:

select distinct employee1.job_id,job1.loc_id from employee1,job1 where


employee1.job_id=job1.job_id and employee1.job_id=3
Output:

JOB_ID LOC_ID

3 5

1 rows returned in 0.07 seconds 


select sum(deposit.amount) from deposit,customer where deposit.c_name=customer.c_name and
customer.city='Nagpur';

o/p:

SUM(DEPOSIT.AMOUNT)
-

3. List maximum deposit of customers living in bombay.

select max(deposit.amount) from deposit, customer where deposit.c_name=customer.c_name and


customer.city='Bombay';

o/p:

MAX(DEPOSIT.AMOUNT)
-

4. Display the highest, lowest, sum, and average salary of all employees. Label the columns
Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest whole
number.

select round(MAX (emp_sal), 0) "Maximum",

round(MIN (emp_sal), 0) "Minimum",

round(SUM (emp_sal), 0) "Sum",

round(AVG (emp_sal), 0) "Average" from employee;

o/p:

Maximum Minimum Sum Average


5000 800 16925 2418

5. Write a query that displays the difference between the highest and lowest salaries. Label the
column DIFFERENCE.
select max(emp_sal) - min(emp_sal) difference from employee;

o/p:

DIFFERENCE
4200

6. Create a query that will display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998

SELECT COUNT(*) total,

SUM (DECODE (TO_CHAR (hire_date, 'YYYY'), 1995,1,0) ) "1995",

SUM (DECODE (TO_CHAR (hire_date, 'YYYY'), 1996,1,0) ) "1996",

SUM (DECODE (TO_CHAR (hire_date, 'YYYY'), 1997,1,0) ) "1997",

SUM (DECODE (TO_CHAR (hire_date, 'YYYY'), 1998,1,0) ) "1998" FROM employee;

o/p:

TOTAL 1995 1996 1997 1998


7 1 6 0 0

7. Find the average salaries for each department without displaying the respective department
numbers.

select avg(emp_sal) from employee group by dept_no;

o/p:

AVG(EMP_SAL)
1600
2975
950
3725
3000

8. Write a query to display the total salary being paid to each job title, within each department.

select dept_no,sum(emp_sal) from employee group by dept_no;

o/p:
DEPT_NO SUM(EMP_SAL)
25 1600
30 2975
20 1100
10 11250

9. Find the average salaries > 2000 for each department without displaying the respective
department numbers.

select round(avg(emp_sal)) from employee group by dept_no having round(avg(emp_sal))>2000;

o/p:

ROUND(AVG(EMP_SAL))
2975
2813

10. Display the job and total salary for each job with a total salary amount exceeding 3000, in which
excludes president and sorts the list by the total salary.

select dept_no,sum(emp_sal) from employee group by dept_no having sum(emp_sal)>3000 order


by sum(emp_sal);

o/p:

DEPT_NO SUM(EMP_SAL)
10 11250

11. List the branches having sum of deposit more than 5000 and located in city bombay.

select d.b_name from deposit d,branchh b where d.b_name=b.b_name and b.city='BOMBAY' group
by d.b_name having sum(d.amount)>5000;

o/p:

B_NAME
POWAI

PRACTICAL 7:

To solve queries using the concept of sub query:


1. Write a query to display the last name and hire date of any employee in the same department as
SCOTT. Exclude SCOTT

select ename, hiredate from emp where deptno = (SELECT deptno from emp where ename =
'SCOTT') and ename!= 'SCOTT' ;

o/p:

ENAME HIREDATE
JONES 04/02/1981
FORD 12/03/1981
SMITH 12/17/1980
ADAMS 01/12/1983

3. Give deposit details and loan details of customer in same city where pramod is living.

select d.c_name,d.act_no,d.b_name,d.amount,d.a_date,b.amount,b.b_name from deposit


d,borrow b, customer c where c.c_name=d.c_name and c.c_name=b.c_name and c.city=(select city
from customer where c_name='PRMOD');

o/p:

ACT_N AMOUN
C_NAME O B_NAME T A_DATE AMOUNT B_NAME
MADHURI 104 CHANDI 1200 12/17/1995 2000 ANDHERI
PRMOD 105 M.G.ROAD 3000 03/27/1996 8000 VIRAR

4. Create a query to display the employee numbers and last names of all employees who earn more
than the average salary. Sort the results in ascending order of salary.

select emp_id, lastname from employ where emp_sal>(select AVG(emp_sal)from employ) order by
emp_sal;

o/p:

EMP_ID LASTNAME
5 Tiger
3 NIKK
2 MEET

6. Display the last name and salary of every employee who reports to ford.
select ename,sal from emp where mgr=(select empno from emp where ename='FORD');

o/p:

ENAME SAL
SMITH 800

7. Display the department number, name, and job for every employee in the Accounting
department.

select emp_id, lastname, job_id from employ where emp_id in (select dept_id from dept_ment
where dept_name='Accounting');

o/p:

no data found

PRACTICAL 8:

Manipulating data:

1.Give 10% interest to all depositors.

update deposit set amount=amount+(amount*0.1);

o/p:

9 row(s) updated.

2. Give 10% interest to all depositors having branch vrce.

update deposit set amount=amount+(amount*0.1) where b_name='VRCE';

o/p:

1 row(s) updated.

3.Give 10% interest to all depositors living in Nagpur having branch city bombay.

update deposit set amount=amount+(amount*0.1) where c_name in(select c_name from customer
where city='NAGPUR') and b_name=(select b_name from branchh where city='BOMBAY');

0 row(s) updated.

Practical 9:

SQL Security and Privileges:


  

The schema owner can grant privileges to the following data objects in the schema:
 Tables
 Columns
 SQL Procedures and Functions

Table 1 describes the privileges that the schema owner can grant users for tables and columns:

Table 1 : User Privileges for Tables and Columns


Privilege Privilege
Statements Description
DELETE Allows a user to delete rows from tables within the schema
INSERT Allows a user to insert rows of data into tables within the schema
REFERENCES Allows a user to set up references to primary keys within the schema
SELECT Allows a user to select rows from tables within the schema
TRIGGER Allows a user to create triggers on tables within the schema
UPDATE Allows a user to update rows in tables within the schema
EXECUTE Allows users to execute functions or stored procedures within the schema

Granting and Revoking Privileges


 When a PointBase database is first created the only user is the default user PUBLIC with a
password of PUBLIC. The PUBLIC user owns the default PUBLIC schema. For security reasons,
PointBase does not recommend using this schema to store sensitive data. Like any PointBase
user, PUBLIC must be granted the appropriate privileges to access data objects in schema
owned by other users.
 The PUBLIC user can be used initially to create new users and new schema. The PUBLIC user
will own any new schema that it creates unless otherwise specified during schema creation.
New users are then able to create their own new schema and users, and grant appropriate
privileges on schema that they own. All new users must be granted privileges to use the
PUBLIC schema if this is required.
 To grant the ability for a user to pass a privilege on to other users once granted, you must
specify the optional WITH GRANT OPTION qualifier when granting the privilege.

GRANT Statement Syntax

GRANT privilege-list
ON object
TO user-list [ WITH GRANT OPTION ]

Use the GRANT statement to grant privileges on a data object. The following describes the GRANT
statement syntax.

Privilege-list Syntax

privilege [ , privilege [ , privilege ]...] | ALL PRIVILEGES

Privilege Syntax

SELECT [ ( column-name [ , column-name ]...)]


| DELETE
| INSERT [ ( column-name [ , column-name ]...)]
| UPDATE [ ( column-name [ , column-name ]...)]
| REFERENCES [ ( column-name [ , column-name ]...)]
| TRIGGER [ ( column-name [ , column-name ]...)]
| EXECUTE

Object Syntax

[ TABLE ] table-name
|SPECIFIC routine_type specific_routine-name
|routine_type routine_name (parameter_types_list)
[ TRIGGER ] trigger-name

User-list Syntax

user [ , user ]... [WITH GRANT OPTION] | PUBLIC


Examples

 The following statement grants the SELECT privilege on the CUSTOMER_TBL table to the user
MARKETING_MGR.

GRANT SELECT
ON customer_tbl
TO marketing_mgr;

 The following GRANT statement allows the user FINANCIAL_MGR to delete, insert and
update rows from the DISCOUNT_CODE_TBL table; it also allows this user to grant the same
privileges to others.

GRANT DELETE,INSERT,UPDATE
ON discount_code_tbl
TO financial_mgr
WITH GRANT OPTION;

 The following GRANT statement allows the user HR_MGR to have ALL PRIVILEGES on the
table SALES_REP_DATA_TBL. However, the user HR_MGR will only be granted privileges that
the user granting the privileges has the right to grant. For example, if the user granting the
privileges does not have the right to grant DELETE privileges, the HR_MGR will not have the
delete privilege.

GRANT ALL PRIVILEGES


ON sales_rep_data_tbl
TO hr_mgr

REVOKE Statement Syntax

REVOKE [ GRANT OPTION FOR ] privilege_list


ON object
FROM user_name [ RESTRICT | CASCADE ]

The REVOKE statement takes privileges away from users. The arguments are similar to the GRANT
statement. The major difference is the additional RESTRICT or CASCADE keyword and the GRANT
OPTION FOR clause. The following describes the optional clauses GRANT OPTION FOR and RESTRICT
or CASCADE.
RESTRICT | CASCADE

 If you use RESTRICT keyword, the privilege will be revoked only from the specified user. If
the specified user granted had the WITH GRANT OPTION and granted the same privilege to
other users, they will retain the privilege.
 If you use CASCADE, it will revoke the privilege and any dependent privileges as a result of
your grant. A dependent privilege is one that could exist, if you granted the privilege that
you're trying to revoke, which is what you are trying to achieve as a result of your REVOKE
statement.
 If the optional RESTRICT or CASCADE keywords are not used, PointBase uses RESTRICT by
default.

GRANT OPTION FOR

 If he optional GRANT OPTION FOR clause is used, the WITH GRANT OPTION right is revoked.
The actual privilege itself is not revoked. the GRANT OPTION is revoked. CASCADE and
RESTRICT may be used in the same way as a normal REVOKE statement.

You might also like