Section 5 Quiz Oracle Database Programming with SQL-Answers



1. The following script will run successfully. True or False?

SELECT TO_CHAR(TO_DATE('25-Dec-2004','dd-Mon-yyyy'))

FROM dual



 Doğru (*)

 Yanlış





2. Which SQL Statement should you use to display the prices in this format: "$00.30"?



 SELECT TO_CHAR(price, '$99,999.99')

FROM product;



 SELECT TO_CHAR(price, '$99,900.99')

FROM product;

(*)



 SELECT TO_CHAR(price, '$99,990.99')

FROM product;



 SELECT TO_NUMBER(price, '$99,900.99')

FROM product;





3. Which three statements concerning explicit data type conversions are true? (Choose three.)



 Use the TO_NUMBER function to convert a number to a character string.

 Use the TO_CHAR function to convert a number or date value to a character string. (*)

 Use the TO_DATE function to convert a character string to a date value. (*)

 Use the TO_NUMBER function to convert a character string of digits to a number. (*)

 Use the TO_DATE function to convert a date value to a character string or number.





4. All Human Resources data is stored in a table named EMPLOYEES.

You have been asked to create a report that displays each employee's name and salary.

 Each employee's salary must be displayed in the following format: $000,000.00. Which function should you include in a SELECT statement to achieve the desired result?



 TO_DATE

 TO_NUMBER

 TO_CHAR (*)

 CHARTOROWID





5.Which arithmetic operation will return a numeric value?



 NEXT_DAY(hire_date) + 5

 SYSDATE - 6

 SYSDATE + 30 / 24

 TO_DATE('01-Jun-2004') - TO_DATE('01-Oct-2004') (*)


6. A table has the following definition: EMPLOYEES(
EMPLOYEE_ID NUMBER(6) NOT NULL,
NAME VARCHAR2(20) NOT NULL,
MANAGER_ID VARCHAR2(6))

and contains the following rows:

(1001, 'Bob Bevan', '200')
(200, 'Natacha Hansen', null)

Will the folloiwng query work?

SELECT *
FROM employees
WHERE employee_id = manager_id;

Yes, Oracle will perform implicit datatype conversion, but the WHERE clause will not find any matching data. (*)

Yes, Oracle will perform implicit dataype conversion, and the query will return one row of data.

No.ᅠ You will have to re-wirte the statement and perform explicit datatype conversion.

No, because the datatypes of EMPLOYEE_ID and MANAGER_ID are different.


7. For the given data from Employees (last_name, manager_id) what is the result of the following statement:
DATA:( King, null
Kochhar, 100
De Haan, 100
Hunold, 102
Ernst, 103)
SELECT last_name,
DECODE(manager_id, 100, 'King', 'A N Other') "Works For?"
FROM employees


King, A N Other
Kochhar, King
De Haan, King
Hunold, Kochhar
Ernst, De Haan


King, A N Other
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other
(*)


Invalid statement.

King, Null
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other



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

WHERE
CASE (*)
NULLIF
DESCRIBE


9. CASE and DECODE evaluate expressions in a similar way to IF-THEN-ELSE logic. However, DECODE is specific to Oracle syntax. True or False?

Doğru (*)
Yanlış


10. Which function compares two expressions?

NULL
NVL2
NVL
NULLIF (*)


11. The STYLES table contains this data:
STYLE_ID STYLE_NAME CATEGORY COST
895840 SANDAL 85940 12.00
968950 SANDAL 85909 10.00
869506 SANDAL 89690 15.00
809090 LOAFER 89098 10.00
890890 LOAFER 89789 14.00
857689 HEEL 85940 11.00
758960 SANDAL 86979
Evaluate this SELECT statement:

SELECT style_id, style_name, category, cost
FROM styles
WHERE style_name LIKE 'SANDAL' AND NVL(cost, 0) < 15.00
ORDER BY category, cost;

Which result will the query provide?


STYLE_ID STYLE_NAME CATEGORY COST
895840 SANDAL 85909 12.00
968950 SANDAL 85909 10.00
758960 SANDAL 86979
869506 SANDAL 89690 15.00



STYLE_ID STYLE_NAME CATEGORY COST
895840 SANDAL 85909 12.00
968950 SANDAL 85909 10.00
869506 SANDAL 89690 15.00
758960 SANDAL 86979



STYLE_ID STYLE_NAME CATEGORY COST
968950 SANDAL 85909 10.00
895840 SANDAL 85940 12.00
758960 SANDAL 86979
(*)




STYLE_ID STYLE_NAME CATEGORY COST
895840 SANDAL 85940 12.00
968950 SANDAL 85909 10.00
758960 SANDAL 86979





12. You need to replace null values in the DEPT_ID column with the text N/A. Which functions should you use?
TO_CHAR and NULL

TO_NUMBER and NULLIF

TO_CHAR and NULLIF

TO_CHAR and NVL (*)



13. When executed, which statement displays a zero if the TUITION_BALANCE value is zero and the HOUSING_BALANCE value is null?

SELECT tuition_balance + housing_balance
FROM student_accounts;


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;
(*)



14. Which statement about group functions is true?

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, NVL2, and 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.




15. 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 ;



King, null
Kochhar, 100
Vargas, 124
Zlotkey, .2


King, -1
Kochhar, 100
Vargas, 124
Zlotkey, 100


King, -1
Kochhar, 100
Vargas, 124
Zlotkey, .2
(*)


Statement will fail

Yorumlar