0% found this document useful (0 votes)
92 views14 pages

Harsharan Kaur Section 4-2 October 10, 2020

This document contains SQL queries and their outputs related to retrieving and manipulating data from Oracle databases. It includes queries that select, calculate, convert, and format data for columns like names, salaries, dates and more. The queries use functions like ROUND, MOD, MONTHS_BETWEEN, TO_CHAR, LOWER, UPPER, CONCAT and more to perform calculations and transformations on the data.

Uploaded by

Sonia Kaur
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)
92 views14 pages

Harsharan Kaur Section 4-2 October 10, 2020

This document contains SQL queries and their outputs related to retrieving and manipulating data from Oracle databases. It includes queries that select, calculate, convert, and format data for columns like names, salaries, dates and more. The queries use functions like ROUND, MOD, MONTHS_BETWEEN, TO_CHAR, LOWER, UPPER, CONCAT and more to perform calculations and transformations on the data.

Uploaded by

Sonia Kaur
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/ 14

Harsharan Kaur

Section 4-2
October 10, 2020

Section 4-2 # 1, 6

1. Display Oracle database employee last_name and salary for employee_ids


between100 and 102. Include a third column that divides each salary by 1.55 and
rounds the result to two decimal places.

SELECT last_name, salary, ROUND(salary/1.55, 2) "Calculated Salary"


FROM employees
WHERE employee_id BETWEEN 100 AND 102;

6. Divide 34 by 8.Show only the remainder of the division. Name the output as
EXAMPLE.

SELECT MOD(34, 8) as EXAMPLE


FROM dual;
Section 4-3 # 2, 8, 9

2. Display the days between the start of last summer’s school vacation break and
the day school started this year. Assume 30.5 days per month. Name the output
“Days.”

SELECT ROUND(MONTHS_BETWEEN('05/SEP/2004', '15/JUN/2004')*30.5) AS DAYS


FROM dual;
8. The teacher said you have until the last day of this month to turn in your
research paper. What day will this be? Name the output, “Deadline.”

SELECT LAST_DAY(SYSDATE) AS Deadline


FROM DUAL;
9. How many months between your birthday this year and January 1 next year?

SELECT ROUND(MONTHS_BETWEEN('01/JAN/2005', '19/JUN/2004'))


FROM DUAL;
Section 4-3 Extension # 1, 2, 3, 7, 9, 13

1. Using DUAL, write a statement that will convert 86.678 to 86.68.

SELECT ROUND(86.678, 2)
FROM DUAL;
2. Write a statement that will display the DJs on Demand CD titles for cd_numbers
90 and 91 in up- percase in a column headed “DJs on Demand Collections.”

SELECT UPPER(title) AS "DJs on Demand Collections"


FROM d_cds
WHERE cd_number IN (90, 91);
3. Write a statement that will create computer usernames for the DJs on Demand
partners. The usernames will be the lowercase letters of the last name + the
uppercase first letter in the first name. Title the column “User Passwords.” For
example, Mary Smythers would be smythersM.

SELECT CONCAT(LOWER(last_name),UPPER(SUBSTR(first_name, 1,1))) AS "User


Passwords"
FROM d_partners;
7. Using DUAL, convert 5332.342 to 5300.

SELECT ROUND(5332.342, -2)


FROM DUAL;
9. Using DUAL, convert 73.892 to 73.8.

SELECT TRUNC(73.892, 1)
FROM DUAL;

13. Write a statement that will find any of the DJs on Demand CD themes that
have an “ie” in their names.

SELECT description
FROM d_themes
WHERE description LIKE '%ie%';
Section 5-1 # 6

6. Ellen Abel is an employee who has received a $2,000 raise .Display her first
name and last name, her current salary, and her new salary. Display both salaries
with a $ and two decimal places. Label her new salary column AS New Salary.

SELECT first_name, last_name, salary, TO_CHAR(salary+2000, '$99999.99') as "New


Salary"
FROM employees
WHERE last_name = 'Abel';
Section 5-2 # 2, 7 a-b

2. Not all Global Fast Foods staff members receive overtime pay. Instead of
displaying a null value for these employees, replace null with zero. Include the
employee’s last name and overtime rate in the output. Label the overtime rate as
“Overtime Status”.

SELECT last_name, NVL(overtime_rate, 0) as "Overtime Status"


FROM f_staffs;
7. a. Create a report listing the first and last names and month of hire for all
employees in the EMPLOYEES table (use TO_CHAR to convert hire_date to
display the month).

SELECT NVL(first_name,'FNU'), last_name, TO_CHAR(hire_date, 'Month') as "month


of hire"
FROM employees;
7. b. Modify the report to display null if the month of hire is September. Use the
NULLIF function.

SELECT NVL(first_name,'FNU'), last_name, NULLIF(TO_CHAR(hire_date, 'Month'),


'September') as "month of hire"
FROM employees;

You might also like