0% found this document useful (0 votes)
14 views

p3[1]

The document contains a report on various SQL queries related to employee data in a database management system (DBMS) course. It includes tasks such as displaying employee names in different formats, generating email addresses, calculating salary adjustments, and filtering employees based on specific criteria. Each query is accompanied by the corresponding SQL code to execute the desired operation.

Uploaded by

23bce089
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)
14 views

p3[1]

The document contains a report on various SQL queries related to employee data in a database management system (DBMS) course. It includes tasks such as displaying employee names in different formats, generating email addresses, calculating salary adjustments, and filtering employees based on specific criteria. Each query is accompanied by the corresponding SQL code to execute the desired operation.

Uploaded by

23bce089
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/ 12

Institute of Technology, Nirma University

Semester III

Course Code & Name: DBMS

Report on Topic: Practical-3

Prepared & submitted by:


HARSH SHAH 23BCE089
1. Display the first name in lower case and last name in upper case, for all
employees whose employee number is in the range between 80 and 150.

SELECT LOWER(first_name) AS "First Name", UPPER(last_name) AS "Last Name" FROM


employees WHERE employee_id BETWEEN 80 AND 150;

2. Generating new email address

a) For each employee, display the first name, last name, and email address. The email
address will be composed from the first letter of the first name, concatenated with the
first three letters of the last name, concatenated with @oracle.com.

SELECT first_name, last_name, SUBSTR(first_name, 1, 1) || SUBSTR(last_name, 1, 3) ||


'@oracle.com' AS "Email" FROM employees;
b) For each employee, display the first name, last name, and email address. The email
address will be composed from the first letter of the first name, concatenated with the
last three letters of the last name, concatenated with @oracle.com.

SELECT first_name, last_name, SUBSTR(first_name, 1, 1) || SUBSTR(last_name, -3) ||


'@oracle.com' AS "Email" FROM employees;

3. For each employee, display the first name concatenated with the last name,
concatenated with the hire date.

SELECT first_name || ' ' || last_name || ' - ' || TO_CHAR(hire_date, 'DD-MON-YYYY') AS


"Employee Info" FROM employees;

4. Display the last name for all employees where the last name's length is greater
than 8 characters.

SELECT last_name FROM employees WHERE LENGTH(last_name) > 8;


5. For each employee, display the first name, last name, phone number, and a new
phone number. In the new phone number, replace all occurrences of 515 with
815.

SELECT first_name, last_name, phone_number, REPLACE(phone_number, '515',


'815') AS "New Phone Number" FROM employees;
6. For each employee, display the first name, salary, salary after a raise of 12%,
salary after a raise of 12% expressed as a whole number, and salary after a raise
of 12% rounded down to the nearest whole number.

SELECT first_name, salary,


salary * 1.12 AS "Salary +12%", ROUND(salary * 1.12) AS "Rounded Salary",
FLOOR(salary * 1.12) AS "Floor Salary"
FROM employees;

7. For each employee, display the first name, hire date, hire date minus 10 days,
hire date plus one month, and the day difference between the current date and
the hire date.

SELECT first_name, hire_date, hire_date - 10 AS "Hire Date - 10 Days",


ADD_MONTHS(hire_date, 1) AS "Hire Date + 1 Month", SYSDATE -
hire_date AS "Days Worked" FROM employees;
8. For each employee, display the first name, last name, hire date, the number of
months he works in the company, and the number of years he works in the
company.

SELECT first_name, last_name, hire_date, MONTHS_BETWEEN(SYSDATE,


hire_date) AS "Months Worked", FLOOR(MONTHS_BETWEEN(SYSDATE,
hire_date) / 12) AS "Years Worked" FROM employees;

9. For each employee, display the first name, hire date, and hire date plus one year.

SELECT first_name, hire_date, ADD_MONTHS(hire_date, 12) AS "Hire Date + 1


Year" FROM employees;
10. For each employee, display the first name, hire date, hire date rounded up to the
nearest year, and hire date rounded up to the nearest month.

SELECT first_name, hire_date, TRUNC(hire_date, 'YYYY') AS "Rounded to Year",


TRUNC(hire_date, 'MM') AS "Rounded to Month" FROM employees;

11. For each employee, display the first name, the day of his hire date, and the year
of his hire date.

SELECT first_name, TO_CHAR(hire_date, 'DD') AS "Day", TO_CHAR(hire_date,


'YYYY') AS "Year" FROM employees;
12. Display the last name in upper case, the salary in format model '9,999.999', and
hire date in format model 'DD/MM/YYYY' for all employees whose last name
begins with the letter D or K (without using LIKE).

SELECT UPPER(last_name) AS "Last Name", TO_CHAR(salary, '9,999.999') AS


"Salary", TO_CHAR(hire_date, 'DD/MM/YYYY') AS "Hire Date" FROM employees
WHERE SUBSTR(last_name, 1, 1) IN ('D', 'K');

13. For each employee, display the first name, last name, salary, and commission
percentage. If an employee doesn't earn a commission, display 0 instead of
NULL.

SELECT first_name, last_name, salary, NVL(commission_pct, 0) AS


"Commission" FROM employees;
14. For each employee, display the first name, last name, salary, and commission
percentage. If an employee doesn't earn a commission, display "No
Commission" instead of NULL.

SELECT first_name, last_name, salary, NVL(TO_CHAR(commission_pct), 'No


Commission') AS "Commission" FROM employees;

15. For each employee, display the first name, last name, salary, and a salary grade
based on these conditions:
a) If the salary is between 0 and 5000 - salary grade level is A
b) If the salary is between 5001 and 15000 - salary grade level is B

c) If the salary is between 15001 and 20000 - salary grade level is C

d) For any other range - salary grade level is D

SELECT first_name, last_name, salary, CASE WHEN salary BETWEEN 0 AND 5000 THEN
'A' WHEN salary BETWEEN 5001 AND 15000 THEN 'B' WHEN salary BETWEEN 15001
AND 20000 THEN 'C' ELSE 'D' END AS "Salary Grade" FROM employees;

16. Display the first name, salary, and round the salary to thousands.

SELECT first_name, salary, ROUND(salary, -3) AS "Rounded Salary" FROM


employees;

17. Display all the employees who joined in the month of May.
SELECT first_name, last_name, hire_date FROM employees WHERE
TO_CHAR(hire_date, 'MM') = '05';

18. Display the first word in the job title.

SELECT job_title, SUBSTR(job_title, 1, INSTR(job_title, ' ') - 1) AS "First Word"


FROM jobs WHERE INSTR(job_title, ' ') > 0;

19. Display the length of the first name for employees whose last name contains the
character 'b' after the third position (without using LIKE).

SELECT first_name, LENGTH(first_name) AS "First Name Length" FROM


employees WHERE INSTR(last_name, 'b', 4) > 0;
20. Display the first name of the employees whose experience is more than 5 years.

SELECT first_name, last_name FROM employees WHERE


MONTHS_BETWEEN(SYSDATE, hire_date) / 12 > 5;

You might also like