0% found this document useful (0 votes)
3 views6 pages

Assn 4

The document contains a series of SQL queries executed in Oracle SQL*Plus, showcasing various database operations such as selecting employee details, calculating dates, and performing mathematical functions. It includes commands to retrieve employee names, salaries, and tax rates, as well as aggregate functions like average, maximum, and minimum. The output also highlights specific employee records based on conditions like salary and job type.

Uploaded by

shivachaudhry101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Assn 4

The document contains a series of SQL queries executed in Oracle SQL*Plus, showcasing various database operations such as selecting employee details, calculating dates, and performing mathematical functions. It includes commands to retrieve employee names, salaries, and tax rates, as well as aggregate functions like average, maximum, and minimum. The output also highlights specific employee records based on conditions like salary and job type.

Uploaded by

shivachaudhry101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL*Plus: Release 19.0.0.0.

0 - Production on Wed Feb 9 16:24:00 2022


Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle. All rights reserved.

Enter user-name: kasis


Enter password:
Last Successful login time: Wed Feb 09 2022 16:20:55 +05:30

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> set lin 200;


SQL> select sysdate from dual;

SYSDATE
---------
09-FEB-22

SQL> select f_name,l_name,doj,add_months(doj,6) as permanent_date from employee;

F_NAME L_NAME DOJ PERMANENT


---------- ---------- --------- ---------
arun khan 04-JAN-98 04-JUL-98
barun kumar 09-FEB-98 09-AUG-98
chitra kapoor 08-JAN-98 08-JUL-98
dheeraj mishra 27-DEC-01 27-JUN-02
emma dutt 20-MAR-02 20-SEP-02
floki dutt 01-JUL-16 01-JAN-17
dheeraj kumar 01-JUL-16 01-JAN-17
saul good 06-SEP-14 06-MAR-15
sunny deol 31-MAR-01 30-SEP-01
bobby deol 17-OCT-17 17-APR-18
anand patil 31-JAN-17 31-JUL-17

F_NAME L_NAME DOJ PERMANENT


---------- ---------- --------- ---------
anandi patel 01-APR-17 01-OCT-17

12 rows selected.

SQL> select last_day(sysdate) from dual;

LAST_DAY(
---------
28-FEB-22

SQL> select emp_id,f_name,months_between(sysdate,doj) from employee;

EMP_ID F_NAME MONTHS_BETWEEN(SYSDATE,DOJ)


---------- ---------- ---------------------------
1 arun 289.183381
2 barun 288
3 chitra 289.054348
4 dheeraj 241.441445
5 emma 238.667252
6 floki 67.2801549
7 dheeraj 67.2801549
8 saul 89.1188646
10 sunny 250.312413
11 bobby 51.7640259
13 anand 60.312413

EMP_ID F_NAME MONTHS_BETWEEN(SYSDATE,DOJ)


---------- ---------- ---------------------------
14 anandi 58.2801549

12 rows selected.

SQL> select next_day(sysdate,'tuesday')from dual;

NEXT_DAY(
---------
15-FEB-22

SQL> select extract(month from sysdate) from dual;

EXTRACT(MONTHFROMSYSDATE)
-------------------------
2

SQL> select extract(year from sysdate) from dual;

EXTRACT(YEARFROMSYSDATE)
------------------------
2022

SQL> select abs(-505) from dual;

ABS(-505)
----------
505

SQL> select ceil(10.44),ceil(10.50),ceil(10.65) from dual;

CEIL(10.44) CEIL(10.50) CEIL(10.65)


----------- ----------- -----------
11 11 11

SQL> select floor(10.44),floor(10.50),floor(10.65) from dual;

FLOOR(10.44) FLOOR(10.50) FLOOR(10.65)


------------ ------------ ------------
10 10 10

SQL> select log(2,10) from dual;

LOG(2,10)
----------
3.32192809

SQL> select mod(594,7) from dual;

MOD(594,7)
----------
6
SQL> select power(8,3) from dual;

POWER(8,3)
----------
512

SQL> select sqrt(3481) from dual;

SQRT(3481)
----------
59

SQL> select round(45.923,2), round(45.923,0), round(45.923,-1), round(45.923,2),


round(45.923,0), round(45.923,-2) from dual;

ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-1) ROUND(45.923,2) ROUND(45.923,0)


ROUND(45.923,-2)
--------------- --------------- ---------------- --------------- ---------------
----------------
45.92 46 50 45.92 46
0

SQL> select trunc(45.888,2), trunc(56.758,0), trunc(49.245,-2), trunc(45.888,2),


round(45.888,2) from dual;

TRUNC(45.888,2) TRUNC(56.758,0) TRUNC(49.245,-2) TRUNC(45.888,2) ROUND(45.888,2)


--------------- --------------- ---------------- --------------- ---------------
45.88 56 0 45.88 45.89

SQL> select sign(20),sign(-67.60),sign(0) from dual;

SIGN(20) SIGN(-67.60) SIGN(0)


---------- ------------ ----------
1 -1 0

SQL> select cos(45),sin(45),tan(45) from dual;

COS(45) SIN(45) TAN(45)


---------- ---------- ----------
.525321989 .850903525 1.61977519

SQL> select char(79);


select char(79)
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select ASCII(79) from dual ;

ASCII(79)
----------
55

SQL> select chr(79) from dual;

C
-
O

SQL> select concat(f_name,l_name) from employee;

CONCAT(F_NAME,L_NAME
--------------------
arunkhan
barun kumar
chitra kapoor
dheerajmishra
emmadutt
flokidutt
dheerajkumar
saulgood
sunnydeol
bobbydeol
anandpatil

CONCAT(F_NAME,L_NAME
--------------------
anandipatel

12 rows selected.

SQL> select upper(f_name) from employee;

UPPER(F_NA
----------
ARUN
BARUN
CHITRA
DHEERAJ
EMMA
FLOKI
DHEERAJ
SAUL
SUNNY
BOBBY
ANAND

UPPER(F_NA
----------
ANANDI

12 rows selected.

SQL> select length(f_name),length(l_name) from employee where dept='sales';

LENGTH(F_NAME) LENGTH(L_NAME)
-------------- --------------
7 6

SQL> SELECT emp_id, f_name, l_name, salary,CASE WHEN salary < 20000 THEN 0
WHEN salary >= 20000 AND salary < 40000 THEN 9 WHEN salary >= 40000 AND salary <
60000 THEN 20 WHEN salary >= 60000 AND salary < 80000 THEN 30 WHEN salary >=
80000 THEN 45END AS "Tax Rate %"FROM employee;

EMP_ID F_NAME L_NAME SALARY Tax Rate %


---------- ---------- ---------- ---------- ----------
1 arun khan 90000 45
2 barun kumar 80000 45
3 chitra kapoor 60000 30
4 dheeraj mishra 75000 30
5 emma dutt 55000 20
6 floki dutt 70000 30
7 dheeraj kumar 40000 20
8 saul good 60000 30
10 sunny deol 20000 9
11 bobby deol 35000 9
13 anand patil 28000 9

EMP_ID F_NAME L_NAME SALARY Tax Rate %


---------- ---------- ---------- ---------- ----------
14 anandi patel 12000 0

12 rows selected.

SQL> SELECT f_name,salary FROM employee where salary = (select min(salary) from
employee) ;

F_NAME SALARY
---------- ----------
anandi 12000

SQL> SELECT f_name,salary FROM employee where salary = (select max(salary) from
employee) ;

F_NAME SALARY
---------- ----------
arun 90000

SQL> SELECT f_name,salary FROM employee where salary = (select avg(salary) from
employee) ;

no rows selected

SQL> SELECT f_name,salary FROM employee where salary = (select average(salary)


from employee) ;
SELECT f_name,salary FROM employee where salary = (select average(salary) from
employee)
*
ERROR at line 1:
ORA-00904: "AVERAGE": invalid identifier

SQL> SELECT f_name,salary FROM employee where salary = (select sum(salary) from
employee) ;

no rows selected

SQL> select avg(salary),max(salary),min(salary),sum(salary) from employee where


dept='sales';

AVG(SALARY) MAX(SALARY) MIN(SALARY) SUM(SALARY)


----------- ----------- ----------- -----------
75000 75000 75000 75000

SQL> select min(doj),max(doj) from employee;


MIN(DOJ) MAX(DOJ)
--------- ---------
04-JAN-98 17-OCT-17

SQL> select avg(salary),max(salary),min(salary),sum(salary) from employee;

AVG(SALARY) MAX(SALARY) MIN(SALARY) SUM(SALARY)


----------- ----------- ----------- -----------
52083.3333 90000 12000 625000

SQL> select f_name from employee where l_name in(select max(l_name) from
employee);

F_NAME
----------
anand

SQL> select f_name from employee where l_name in(select min(l_name) from
employee);

F_NAME
----------
sunny
bobby

SQL> select count(*) from employee where job_type='engineer';

COUNT(*)
----------
5

SQL> select count(dept) from employee;

COUNT(DEPT)
-----------
11

SQL> select avg(commision) from employee;

AVG(COMMISION)
--------------
4166.66667

You might also like