0% found this document useful (0 votes)
2K views4 pages

Practical - 6. To Study Single-Row Functions.: 1. Write A Query To Display The Current Date. Label The Column Date

The document contains examples of SQL queries that use single-row functions to retrieve and format data from employee tables. The queries display the current date, calculate salaries with a 15% increase expressed as whole numbers, subtract old from new salaries, capitalize the first letter of names that start with J, A, or M along with name lengths, concatenate employee last names with earnings statements, display hire dates and time worked in months and days of the week, format hire dates to include month names and AM/PM, and calculate total annual compensation from salary and commission.

Uploaded by

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

Practical - 6. To Study Single-Row Functions.: 1. Write A Query To Display The Current Date. Label The Column Date

The document contains examples of SQL queries that use single-row functions to retrieve and format data from employee tables. The queries display the current date, calculate salaries with a 15% increase expressed as whole numbers, subtract old from new salaries, capitalize the first letter of names that start with J, A, or M along with name lengths, concatenate employee last names with earnings statements, display hire dates and time worked in months and days of the week, format hire dates to include month names and AM/PM, and calculate total annual compensation from salary and commission.

Uploaded by

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

PRACTICAL_6.

To study Single-row functions.


1. Write a query to display the current date. Label the
column Date .
ANS. SELECT TO_CHAR
(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') AS "NOW"
FROM DUAL;

2. For each employee, display the employee number, job,


salary, and salary increased by 15% and expressed as a
whole number. Label the column New Salary
ANS. SELECT EMP_NO,EMP_NAME,EMP_SAL,EMP_SAL+(EMP_SAL *15/100)
AS "NEW_SALARY" FROM EMPLOYEE_540;
3. Modify your query no 4.(2) to add a column that
subtracts the old salary from the new salary. Label the
column Increase .
ANS. SELECT EMP_NO,EMP_NAME,EMP_SAL,EMP_SAL+(EMP_SAL *15/100)
AS "NEW_SALARY",(EMP_SAL+(EMP_SAL*15/100))-EMP_SAL AS "INCREMENT"
FROM EMPLOYEE_540;

4. Write a query that displays the employee’s names with


the first letter capitalized and all other letters lowercase,
and the length of the names, for all employees whose name
starts with J, A, or M. Give each column an appropriate
label. Sort the results by the
a. employees’ last names.
ANS. SELECT INITCAP(EMP_NAME) AS "NAME" ,LENGTH (EMP_NAME) AS
"LENGTH OF NAME" FROM EMPLOYEE_540 WHERE EMP_NAME LIKE 'J%' OR
EMP_NAME LIKE 'M%' OR EMP_NAME LIKE 'A%' ORDER BY LNAME DESC;
5. Write a query that produces the following for each
employee: <employee last name> earns <salary> monthly .
ANS. SELECT LNAME ||' '|| 'EARNS'||' '||EMP_SAL||' '||'MONTHLY' AS
"MONTHLY_STATEMENT" FROM EMPLOYEE_540;

6. Display the name, hire date, number of months employed


and day of the week on which the employee has started.
Order the results by the day of the week starting with
Monday.
ANS. SELECT EMP_NAME,H_DATE, TO_CHAR(H_DATE,'DAY') AS
"DAY_OF_HIRING",ROUND(MONTHS_BETWEEN(SYSDATE,H_DATE)) AS
"NUMBER_OF_MONTHS_EMPLOYED" FROM EMPLOYEE_540 ORDER BY
TO_CHAR(H_DATE,'d');
7. Display the hiredate of emp in a format that appears as
Seventh of June 1994 12:00:00 AM.
ANS. SELECT TO_CHAR(H_DATE,'DDSPTH "OF" MONTH YYYY HH:MI:SS AM')
"INFORMATION" FROM EMPLOYEE_540;

8. Write a query to calculate the annual compensation of all


employees (sal+comm.).
ANS. SELECT EMP_SAL+COALESCE(EMP_COMM,0)
"ANNUAL_COMPENSATION" FROM EMPLOYEE_540;

You might also like