You are on page 1of 7

Section 5

(Answer all questions in this section)


1. You need to display the HIRE_DATE values in this format: 25th of July
2002. Which SELECT statement would you use?
Mark for Review

(1) Points
SELECT TO_CHAR(hire_date, 'DDspth 'of' Month RRRR')
FROM employees;
SELECT TO_CHAR(hire_date, 'DDTH "of" Month YYYY')
FROM employees;
SELECT TO_CHAR(hire_date, 'ddth "of" Month YYYY')
FROM employees; (*)
SELECT enroll_date(hire_date, 'DDspth "of" Month YYYY')
FROM employees;
Correct

2. Which functions allow you to perform explicit data type conversions?


Mark for Review

(1) Points
LENGTH, SUBSTR, LPAD, TRIM
ROUND, TRUNC, ADD_MONTHS
TO_CHAR, TO_DATE, TO_NUMBER (*)
NVL, NVL2, NULLIF
Correct

3. You have been asked to create a report that lists all customers who have
placed orders of at least $2,500. The report's date should be displayed using
this format:
Day, Date Month, Year (For example, Tuesday, 13 April, 2004 ).
Which statement should you issue?
Mark for Review

(1) Points
SELECT companyname, TO_DATE (sysdate, 'dd, dy month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_CHAR (sysdate, 'fmDay, dd Month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500; (*)
SELECT companyname, TO_DATE (date, 'day, dd month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_CHAR (sysdate, 'fmdd, dy month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
Correct

4. Which statement concerning single row functions is true?


Mark for Review

(1) Points
Single row functions can accept only one argument, but can return multiple
values.
Single row functions return one or more results per row.
Single row functions can be nested. (*)
Single row functions cannot modify a data type.
Correct

5. Which statement will return the salary (for example, the salary of 6000)
from the Employees table in the following format?   $6000.00
Mark for Review

(1) Points
SELECT TO_CHAR(salary, '$99999') SALARY
FROM employees

SELECT TO_CHAR(salary, '99999.00') SALARY


FROM employees

SELECT TO_CHAR(salary, '$99999.00') SALARY


FROM employees
(*)
SELECT TO_CHAR(sal, '$99999.00') SALARY
FROM employees

Correct
6. If you use the RR format when writing a query using the date 27-Oct-17
and the year is 2001, what year would be the result?
Mark for Review

(1) Points
1917
2017 (*)
1901
2001
Incorrect. Refer to Section 5 Lesson 1.

7. The PRODUCT table contains this column: PRICE NUMBER(7,2)


Evaluate this statement:
SELECT NVL(10 / price, '0')
FROM PRODUCT;

What would happen if the PRICE column contains null values?

Mark for Review

(1) Points
A value of 0 would be displayed. (*)
The statement would fail because values cannot be divided by 0.
A value of 10 would be displayed.
The statement would fail because values cannot be divided by null.
Correct

8. Consider the following data in the Employees table: (last_name,


commission_pct, manager_id)
DATA:
King, null, null
Kochhar, null, 100
Vargas, null, 124
Zlotkey, .2, 100
What is the result of the following statement:
SELECT last_name, COALESCE(commission_pct, manager_id, -1) comm
FROM employees ;

Mark for Review

(1) Points
King, null
Kochhar, 100
Vargas, 124
Zlotkey, .2
Statement will fail
King, -1
Kochhar, 100
Vargas, 124
Zlotkey, 100
King, -1
Kochhar, 100
Vargas, 124
Zlotkey, .2 (*)
Correct

9. Which statement about group functions is true?


Mark for Review

(1) Points
NVL, NVL2, and COALESCE can be used with group functions to replace null
values. (*)
COALESCE, but not NVL and NVL2, can be used with group functions to
replace null values.
NVL and NVL2, but not COALESCE, can be used with group functions to
replace null values.
NVL and COALESCE, but not NVL2, can be used with group functions to
replace null values.
Correct

10. When executed, which statement displays a zero if the


TUITION_BALANCE value is zero and the HOUSING_BALANCE value is null?
Mark for Review

(1) Points
SELECT TO_NUMBER(tuition_balance, 0), TO_NUMBER (housing_balance, 0),
tutition_balance + housing_balance "Balance Due"
FROM student_accounts;
SELECT NVL(tuition_balance, 0), NVL (housing_balance), tuition_balance +
housing_balance "Balance Due"
FROM student_accounts;
SELECT NVL (tuition_balance + housing_balance, 0) "Balance Due"
FROM student_accounts; (*)
SELECT tuition_balance + housing_balance
FROM student_accounts;
Correct

11. The following statement returns 0 (zero). True or False?


SELECT 121/NULL
FROM dual;
Mark for Review

(1) Points
True
False (*)
Correct

12. If quantity is a number datatype, what is the result of this statement?


SELECT NVL(200/quantity, 'zero') FROM inventory;
Mark for Review

(1) Points
zero
Null
ZERO
The statement fails (*)
Correct

13. Which of the following is a conditional expression used in SQL?


Mark for Review

(1) Points
NULLIF
DESCRIBE
CASE (*)
WHERE
Correct
14. Which statement will return a listing of last names, salaries, and a rating
of 'Low', 'Medium', 'Good' or 'Excellent' depending on the salary value?
Mark for Review

(1) Points
SELECT last_name,sal,
(CASE WHEN sal<5000 THEN 'Low'
     WHEN sal<10000 THEN 'Medium'
     WHEN sal<20000 THEN 'Good'
     ELSE 'Excellent'
END) qualified_salary
FROM employees;
SELECT last_name,salary,
(CASE WHEN salary<5000 THEN 'Low'
     WHEN sal <10000 THEN 'Medium'
     WHEN sal <20000 THEN 'Good'
     ELSE 'Excellent'
END) qualified_salary
FROM employees;
SELECT last_name,salary,
(CASE WHEN salary<5000 THEN 'Low'
     WHEN salary<10000 THEN 'Medium'
     WHEN salary<20000 THEN 'Good'
     ELSE 'Excellent'
END) qualified_salary
FROM employees; (*)
SELECT last_name,salary,
(RATING WHEN salary<5000 THEN 'Low'
     WHEN salary<10000 THEN 'Medium'
     WHEN salary<20000 THEN 'Good'
     ELSE 'Excellent'
END) qualified_salary
FROM employees;
Incorrect. Refer to Section 5 Lesson 3.

15. CASE and DECODE evaluate expressions in a similar way to IF-THEN-


ELSE logic. However, DECODE is specific to Oracle syntax. True or False?
Mark for Review

(1) Points
True (*)
False
Correct

You might also like