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

Lab Practice 3

1. The document provides examples of SQL queries to retrieve and manipulate data from database tables. 2. The queries demonstrate functions for retrieving current date, calculating percentages and rounding numbers, comparing dates, concatenating strings, and formatting values. 3. The goal is to practice basic SQL operations like selects, calculations, conversions, and ordering of results.

Uploaded by

Nicholas Wilson
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Lab Practice 3

1. The document provides examples of SQL queries to retrieve and manipulate data from database tables. 2. The queries demonstrate functions for retrieving current date, calculating percentages and rounding numbers, comparing dates, concatenating strings, and formatting values. 3. The goal is to practice basic SQL operations like selects, calculations, conversions, and ordering of results.

Uploaded by

Nicholas Wilson
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Lab Practice 3, Functions 1. Write a query to display the current date. Label the column Date.

SQL> SELECT sysdate FROM dual;

2. Display the employee number, name, salary and salary increase by 15% expressed as a whole number. Label the column New Salary. SQL> select EMPNO,ENAME,SAL,round(SAL+0.15*SAL) as "NEW SAL" from emp; 3. Modify above to add a column that will subtract old salary from new one. Label the column Increment. SQL> select EMPNO,ENAME,SAL,round(SAL+0.15*SAL) as "NEW_SAL",((SAL+0.15*SAL)SAL) as "Increment" from emp; 4. Displat the employees name, hiredate and salary review date, which is the first Monday after six months of service. Label the column Review. SQL> Select ENAME,HIREDATE,Next_Day(Add_Months(HIREDATE,6),'MONDAY') as "Review" from emp; 5. For each employee display the name and calculate the number of months between today and the date the employee was hired. Label the column MONTHS_WORKED. Order your result by the number of months employed. Round the number of months up to the closest whole number. SQL> Select ENAME,round(Months_Between(SysDate,HIREDATE)) as "Months_Worked" from emp; 6. Write a query that produces the following for each employee: <employee name> earns <salary> monthly but wants <3 times salary>. Label the column Dream Salaries. Sort the rows in descending of Dream Salary. select ename||' earns '||sal||' monthly but wants '||sal*3 as "Dream salary from emp order by sal DESC 7. Create a query to display name and salary for all employees. Format the salary to be 15 characters long, left-padded with $. Label the column salary. SQL> SELECT ename, LPAD(sal,15,'$') AS salary FROM emp ;

From Introduction to Oracle: SQL and PL/SQL

You might also like