PS
PS
Roll No : 21BCE312
Sub. Code & Name : 2CS402 – Database & Management System
Practical No. : 3
Date : 08/03/2023
Aim : Functions
1. Numeric
2. Date
3. String
4. Conversion
Do as directed:
1) Print the incremented salary of all employee with 10% increment.
2) Find the (salary + Commission) as Total salary of all employees.
3) Find the gross salary of employee by following formula:
Gross_Salary= Basic Salary+DA+HRA+TA+MA
DA=110% of Basic Salary
HRA=30% of Basic Salary
TA= 1500
MA= 1000
4) 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.
5) 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 first name,
concatenated with the three first letters of last name, concatenated
with @oracle.com.
b) For each employee, display the first name, last name, and email address.
The email address will be composed from the first letter of first name,
concatenated with the three last letters of last name, concatenated
with @oracle.com.
6) For each employee, display the first name concatenated with the last
name, concatenated with hire date.
7) Display the last name for all employees where last name’s length is greater
than 8 characters.
8) 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.
9) For each employee, display first name, salary, salary after a raise of 12%,
salary after a raise of 12%, expressed as a whole number, salary after a
raise of 12%, round down to the nearest whole number.
10) For each employee, display the first name, hire date, hire date minus 10
days, hire date plus one month, and the day difference between current
date and hire date.
11) For each employee, display the first name, last name, hire date, number
of months he works in the company, and number of years he works in
the company.
12) For each employee, display the first name, hire date, and hire date plus
one year.
13) 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.
14) For each employee, display the first name, the day of his hire date, and
the year of his hire date.
15) 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).
16) 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.
17) 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.
18) 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
19) Display the first name, salary and round the salary to thousands.
20) Display all the employees who joined in the month of May.
21) Display the first word in job title.
22) Display the length of first name for employees whose last name contains
character ‘b’ after the third position. (Without using like).
23) Display first name of the employees whose experience in more than 5
years.
1)Code : select employee_id,first_name,salary*1.1 as incremented_salary
from employees;
(9)
Code : select first_name, last_name,phone_number
,replace(phone_number,'515','815') as newPhoneNumber from employees;
SELECT first_name, salary, salary * 1.12 as salary_with_12_percent_raise,
FLOOR(salary * 1.12) as rounded_salary_with_12_percent_raise
FROM employees;
(10) Code :
SELECT first_name, hire_date,
DATE_SUB(hire_date, INTERVAL 10 DAY) as hire_date_minus_10_days,
DATE_ADD(hire_date, INTERVAL 1 MONTH) as hire_date_plus_1_month,
DATEDIFF(CURDATE(), hire_date) as days_since_hire
FROM employees;
(11) Code :
SELECT first_name, last_name, hire_date,
TIMESTAMPDIFF(MONTH, hire_date, NOW()) as months_worked,
TIMESTAMPDIFF(YEAR, hire_date, NOW()) as years_worked
FROM employees;
(12) Code :
SELECT first_name, hire_date, DATE_ADD(hire_date, INTERVAL 1 YEAR)
as hire_date_plus_one_year
FROM employees;
(13) Code :
SELECT first_name,hire_date,
DATE_ADD(DATE_FORMAT(hire_date, '%Y-01-01'),
INTERVAL CEILING(DATEDIFF(hire_date, DATE_FORMAT(hire_date,
'%Y-01-01'))/365) YEAR) AS hire_date_rounded_year,
DATE_ADD(DATE_FORMAT(hire_date, '%y-%m-01'),
INTERVAL CEILING(DATEDIFF(hire_date, DATE_FORMAT(hire_date,
'%Y-%m-01'))/30) MONTH) AS hire_date_rounded_month
FROM employees;
(14) Code :
SELECT first_name, DAY(hire_date) as hire_day, YEAR(hire_date) as
hire_year FROM employees;
(15) Code :
SELECT
UPPER(last_name) AS last_name,
FORMAT(ROUND(salary, 3), 3) AS salary,
DATE_FORMAT(hire_date, '%d/%m/%Y') AS hire_date
FROM employees
WHERE SUBSTR(last_name, 1, 1) IN ('D', 'K');
(16) Code :
SELECT
first_name,
last_name,
salary,
IFNULL(commission_pct, 0) AS commission_pct
FROM employees;
(17) Code :
SELECT
first_name,
last_name,
salary,
IFNULL(commission_pct, 'No Commission') AS commission_pct
FROM employees;
(18) Code :
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;
(19) Code :
select first_name,salary,round(salary,-3) from employees;
(20) Code :
SELECT * FROM employees WHERE MONTH(hire_date) = 5;
(21) Code :
SELECT
SUBSTRING_INDEX(job_id,' ', 1) AS first_word
FROM employees;
(22) Code :
SELECT
LENGTH(first_name) AS first_name_length
FROM employees
WHERE INSTR(SUBSTR(last_name, 4), 'b') > 0;
(23) Code :
SELECT
first_name
FROM employees
WHERE DATEDIFF(NOW(), hire_date) / 365 > 5;