0% found this document useful (0 votes)
11 views4 pages

Akashh 2

The document outlines SQL commands for creating and managing an employee table named 'akash_emp', including inserting data and querying employee information. It provides examples of various SQL queries to extract specific data such as employee names, job categories, and salary details. Additionally, it demonstrates functions for string manipulation and date calculations related to employee hire dates.

Uploaded by

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

Akashh 2

The document outlines SQL commands for creating and managing an employee table named 'akash_emp', including inserting data and querying employee information. It provides examples of various SQL queries to extract specific data such as employee names, job categories, and salary details. Additionally, it demonstrates functions for string manipulation and date calculations related to employee hire dates.

Uploaded by

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

SQL> conn

Enter user-name:system
Enter password:
Connected.
set autocommit on;

SQL> create table akash_emp (EMPNO number, ENAME varchar2(10), JOB


varchar2(10),MGR number,HIREDATE date, SAL number,COM number,DEPTNO number);
Table created.

SQL> insert into akash_emp


values(&empno,'&ename','&job',&mgr,'&hiredate',&sal,&comm,&deptno);
Enter values for EMPNO : 7369
Enter values for ENAME : smith
Enter values for JOB : clerk
Enter values for MGR :7902
Enter values for HIREDATE :17-dec-80
Enter values for SAL :800
Enter values for COM :NULL
Enter values for DEPTNO :20
1 row created.
SQL> select * from akash_emp;

EMPNO ENAME JOB MGR HIREDATE SAL COM DEPTNO


----- ---------- ---------- ---------- ---------- ---------- ---------- --------
--
7369 smith clerk 7902 17-dec-80 800 NULL 20
7499 allen salesman 7698 20-feb-81 1600 300 30
7521 ward salesman 7698 22-feb-81 1250 500 30
7566 jones manager 7839 02-apr-81 2975 NULL 20
7654 martin salesman 7698 28-sep-81 1250 1400 30
7698 blake maanager 7839 01-may-81 2850 NULL 30
7782 clark manager 7839 09-jun-81 2450 NULL 10
7788 scott analyst 7566 09-dec-82 3000 NULL 20

1. There are a few employees who get commissions.


List their names
SQL> select com,ename from akash_emp where comm is not NULL;

COM ENAME
---------- ----------
300 allen
500 ward
1400 martin

2. Write a query to display a message, like, “Smith


is working as a Manager in the
Department 20 and his salary is 800”.
ENAME||'ISWORKINGAS'||JOB||'INTHEDEPARTMENT'||DEPTNO||'ANDHISSALARYIS'||SAL
--------------------------------------------------------------------------------
-------------------------------------------------------------------------
smith is working as clerk in the department 20 and his salary is 800
allen is working as salesman in the department 30 and his salary is 1600
ward is working as salesman in the department 30 and his salary is 1250
jones is working as manager in the department 20 and his salary is 2975
martin is working as salesman in the department 30 and his salary is 1250
blake is working as manager in the department 30 and his salary is 2850
clark is working as manager in the department 10 and his salary is 2450
3. List the different categories of the jobs
available in the company
SQL> select distinct job from akash_emp;

JOB
----------
salesman
clerk
manager
4. Find out the length of the empno for the workers
who work as a salesman.
JOB EMPNLENGTH
---------- ----------
salesman 4
salesman 4
salesman 4
5. Show employee name, grade and salary, in the order
of their salary.
SQL> select ename,sal from akash_emp order by sal asc;
ENAME SAL
---------- ----------
smith 800
ward 1250
martin 1250
allen 1600
clark 2450
blake 2850
jones 2975
6. How many employees are getting salary more than
1000?
SQL> select ename,sal from akash_emp where sal>1000;

ENAME SAL
---------- ----------
allen 1600
ward 1250
jones 2975
martin 1250
blake 2850
clark 2450
7. Select only those employees who are a clerk and a
manager.
SQL> select ename,job from akash_emp where job in ('clerk','manager');

ENAME JOB
---------- ----------
smith clerk
jones manager
blake manager
clark manager
8. How many employees are there whose names start
with „A‟?
SQL> select ename from akash_emp where ename like 'a%';
ENAME
----------
allen
9. Find the location of the letter „K‟ in the name
Blake.
SQL> select ename,instr(ename, 'k') from akash_emp where ename='blake';

ENAME INSTR(ENAME,'K')
---------- ----------------
blake 4
10. Select those employees, who have joined on or
before 31st December 1982 and is a clerk.
SQL> select ename,job,hiredate from akash_emp where hiredate<='31-dec-82';
ENAME JOB HIREDATE
---------- ---------- ---------
smith clerk 17-DEC-80
allen salesman 20-FEB-81
ward salesman 22-FEB-81
jones manager 02-APR-81
martin salesman 28-SEP-81
blake manager 01-MAY-81
clark manager 09-JUN-81
11. In which location the letter R is present in
MARTIN?
SQL> select instr('martin', 'r') from dual;
INSTR('MARTIN','R')
-------------------
3
12. Replace the name KING with KONG (use replace
function).
SQL> select replace('kingdom','king','kong') from dual;

REPLACE
-------
kongdom
13. Display the name of the employees in a manner, so
that they are right aligned and the
title, ‘Mr.’ is added at the beginning of their names.

SQL> select 'Mr. '||ename from akash_emp;

'MR.'||ENAME
--------------
Mr. smith
Mr. allen
Mr. ward
Mr. jones
Mr. martin
Mr. blake
Mr. clark
14. Find the first letter of the name of the employee
who is getting salary 800
SQL> select substr(ename,1,1) from akash_emp where sal=800;S-
s

15. Display the first name of the employees in small


letters and jobs of the employees in
CAPITAL letters.
SQL> select lower(ename),upper(job) from akash_emp;
LOWER(ENAM UPPER(JOB)
---------- ----------
smith CLERK
allen SALESMAN
ward SALESMAN
jones MANAGER
martin SALESMAN
blake MANAGER
clark MANAGER
16. For how many months Miller is working in the company? (Hint:
select
months_between(sysdate, doj))
SQL> select months_between(sysdate,hiredate) from akash_emp where
ename='martin';

MONTHS_BETWEEN(SYSDATE,HIREDATE)
--------------------------------
514.505855
17. What is the experience of the employee whose
empno is 7788?
SQL> select floor(months_between(sysdate,hiredate)/12) from akash_emp where
ename='martin';

FLOOR(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12)
------------------------------------------
42
18. Find out in which year Adams has joined the
company.
SQL> select floor(months_between(sysdate,hiredate)/12)||'years' from akash_emp
where empno=7782;

FLOOR(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12)||'
---------------------------------------------
43years
SQL> select extract(year from hiredate) from akash_emp where ename='allen';

EXTRACT(YEARFROMHIREDATE)
-------------------------
1981

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy