marți, 26 februarie 2013

PROGRAMMING: Section 2

CONVERSION FUNCTIONS
You need to display the HIRE_DATE values in this format: 25th of July 2002. Which SELECT statement would you use?
SELECT TO_CHAR(hire_date, 'ddth "of" Month YYYY')
FROM employees;         

Which statement is true about SQL functions?
a, b and c are true.
          
A table has the following definition:
EMPLOYEES(
EMPLOYEE_ID NUMBER(6) NOT NULL,
NAME VARCHAR2(10) NOT NULL,
MANAGER_ID VARCHAR2(6))
and contains the following rows:
(1001, 'Bob Bevan', '200')
(200, 'Natacha Hansen', null)
Will the following query work?
SELECT *
FROM employees
WHERE employee_id = manager_id;
Yes, Oracle will perform implicit datatype conversion.
          
Which statement will return the salary of e.g. 6000 from the Employees table in the following format $6000.00?
SELECT TO_CHAR(salary, '$99999.00') SALARY
FROM employees         

The following script will run successfully. True or False?
SELECT TO_CHAR(TO_DATE("25-DEC-04" ,'dd-MON-yy'))
FROM dual
False
          
Sysdate is 12-MAY-2004.
You need to store the following date: 7-DEC-89
Which statement about the date format for this value is true?
The RR date format will interpret the year as 1989, and the YY date format will interpret the year as 2089


NULL FUNCTIONS
The following statement returns 0 (zero). True or False?
SELECT 121/NULL
FROM dual;
False          

Which function compares two expressions?
NULLIF
          
If quantity is a number datatype, what is the result of this statement?
SELECT NVL(200/quantity, 'zero') FROM inventory;
The statement fails      

With the following data in Employees (last_name, commission_pct, manager_id) what is the result of the following statement?
DATA:
King,null,null
Kochhar, null,100
Vargas, null, 124
Zlotkey,.2, 100
SELECT last_name, NVL2(commission_pct, manager_id, -1) comm
FROM employees ;
King, -1
Kochhar, -1
Vargas, -1
Zlotkey, 100          

Consider the following data in 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, -1
Kochhar, 100
Vargas, 124
Zlotkey, .2


CONDITIONAL EXPRESSIONS

CASE and DECODE evaluate expressions in a similar way to IF-THEN-ELSE logic. However, DECODE is specific to Oracle syntax. True or False?
True
          
Which statement will return a listing of last names, salaries and a rating of 'Low', 'Medium', 'Good' or 'Excellent' depending on the salary value?
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;

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, A N Other
Ernst, A N Other

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

Niciun comentariu:

Trimiteți un comentariu