Database Programming With SQL Section 4 Quiz

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Database Programming with SQL Section 4 Quiz

Section 4 Quiz
(Answer all questions in this section)

1. Which number function may be used to determine if a value is odd or even? Mark
for Review
(1) Points

TRUNC
MOD (*)
ROUND
BINARY

2. What is the result of the following SQL Statement:


SELECT ROUND(45.923,-1)
FROM DUAL; Mark for Review
(1) Points

46
45.9
50 (*)
None of the above

3. Which two functions can be used to manipulate number or date column values, but NOT character
column values? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)

CONCAT
INSTR
ROUND (*)
RPAD
TRUNC (*)

4. Evaluate this function: MOD (25, 2) Which value is returned? Mark for Review
(1) Points

0
25
1 (*)
2

5. Which script displays '01-May-2004' when the HIRE_DATE value is '20-May-2004'? Mark
for Review
(1) Points

SELECT ROUND(hire_date, 'MON')


FROM employees;

SELECT ROUND(hire_date, 'MONTH')


FROM employees;

SELECT TRUNC(hire_date, 'MI')


FROM employees;

SELECT TRUNC(hire_date, 'MONTH')


FROM employees;
(*)

6. You need to display the current year as a character value (for example: Two Thousand and One).
Which element would you use? Mark for Review
(1) Points

YY
YYYY
RR
YEAR (*)

7. What is the result of the following query?


SELECT ADD_YEARS ('11-Jan-1994',6)
FROM dual; Mark for Review
(1) Points

11-Jul-1995
11-Jan-2000
This in not a valid SQL statement. (*)
11-Jul-2000

8. You need to display the number of months between today's date and each employee's hiredate.
Which function should you use? Mark for Review
(1) Points

ROUND
ADD_MONTHS
BETWEEN
MONTHS_BETWEEN (*)

9. Which query would return a whole number if the sysdate is 26-May-2004? Mark for Review
(1) Points

SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;
(*)

SELECT TRUNC(YEARS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;

SELECT MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12


AS YEARS
FROM DUAL;

None of the above

10. Which SELECT statement will NOT return a date value? Mark for Review
(1) Points

SELECT (hire_date - SYSDATE) + TO_DATE('25-Jun-2002')


FROM employees;

SELECT (30 + hire_date) + 1440/24


FROM employees;

SELECT SYSDATE - TO_DATE('25-Jun-2002') + hire_date


FROM employees;

SELECT (SYSDATE - hire_date) + 10*8


FROM employees;
(*)

11. You need to display each employee's name in all uppercase letters. Which function should you
use? Mark for Review
(1) Points

CASE
TOUPPER
UCASE
UPPER (*)

12. 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 12.00
You query the database and return the value 79. Which script did you use?

Mark for Review


(1) Points

SELECT SUBSTR(category, -2,2)


FROM styles
WHERE style_id = 758960;
(*)

SELECT SUBSTR(category, 2,2)


FROM styles
WHERE style_id = 895840;
SELECT INSTR(category, 2,2)
FROM styles
WHERE style_id = 895840;

SELECT INSTR(category, -2,2)


FROM styles
WHERE style_id = 895840;

13. What does the following SQL SELECT statement return?


SELECT UPPER( SUBSTR('Database Programming', INSTR('Database Programming','P'),20))
FROM dual;
Mark for Review
(1) Points

Programming
Database
PROGRAMMING (*)
DATABASE

14. You issue this SQL statement:


SELECT INSTR ('organizational sales', 'al')
FROM dual;

Which value is returned by this command?

Mark for Review


(1) Points

1
2
17
13 (*)

15. Which of the following are types of SQL functions? (Choose two correct answers.) Mark for
Review
(1) Points
(Choose all correct answers)

Column-Row Functions
Multi-Row Functions (*)
Single-Row Functions (*)
Many-to-Many Functions

1. The answer to the following script is 456. True or False?


SELECT TRUNC(ROUND(456.98))
FROM dual;

Mark for Review


(1) Points
True
False (*)

2. You issue this SQL statement:


SELECT ROUND (1282.248, -2) FROM dual;
What value does this statement produce?

Mark for Review


(1) Points

1200
1300 (*)
1282.25
1282

3. You issue this SQL statement:


SELECT TRUNC(751.367,-1) FROM dual;
Which value does this statement display?

Mark for Review


(1) Points
700
750 (*)
751.3
751

4. What is the result of the following SQL Statement:


SELECT ROUND(45.923,-1)
FROM DUAL; Mark for Review
(1) Points

46
45.9
50 (*)
None of the above

5. Which number function may be used to determine if a value is odd or even? Mark for Review
(1) Points

BINARY
MOD (*)
TRUNC
ROUND

6. If hire_date has a value of '03-Jul-2003', then what is the output from this code?
SELECT ROUND(hire_date, 'Year') FROM employees; Mark for Review
(1) Points

01-Jul-2003
01-Jan-2003
01-Jan-2004 (*)
01-Aug-2003

7. Which SELECT statement will return a numeric value? Mark for Review
(1) Points

SELECT ROUND(hire_date, DAY)


FROM employees;

SELECT (SYSDATE - hire_date) / 7


FROM employees;
(*)

SELECT SYSDATE + 600 / 24


FROM employees;

SELECT SYSDATE - 7
FROM employees;

8. Which query would return a whole number if the sysdate is 26-May-2004? Mark for Review
(1) Points

SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;
(*)

SELECT TRUNC(YEARS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;
SELECT MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12
AS YEARS
FROM DUAL;

None of the above

9. You need to subtract three months from the current date. Which function should you use? Mark
for Review
(1) Points

ROUND
MONTHS_BETWEEN
ADD_MONTHS (*)
TO_DATE

10. What is the result of the following query?


SELECT ADD_MONTHS ('11-Jan-1994',6)
FROM dual; Mark for Review
(1) Points

17-Jul-1994
11-Jul-1994 (*)
17-Jan-1994
11-Jan-1995

11. You issue this SQL statement:


SELECT INSTR ('organizational sales', 'al')
FROM dual;

Which value is returned by this command?

Mark for Review


(1) Points

17
1
2
13 (*)

12. The PRICE table contains this data:


PRODUCT_ID MANUFACTURER_ID
86950 59604

You query the database and return the value 95. Which script did you use?

Mark for Review


(1) Points

SELECT TRIM(product_id, -3, 2)


FROM price
WHERE manufacturer_id = 59604;

SELECT SUBSTR(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;
(*)

SELECT LENGTH(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;

SELECT SUBSTR(product_id, -1, 3)


FROM price
WHERE manufacturer_id = 59604;

13. You need to display the number of characters in each customer's last name. Which function should
you use? Mark for Review
(1) Points

SUBSTR
COUNT
LENGTH (*)
LPAD
14. Identify the output from the following SQL statement:
SELECT RPAD('SQL',6, '*')
FROM DUAL;

Mark for Review


(1) Points

SQL*** (*)
******SQL
***SQL
SQL******

15. What does the following SQL SELECT statement return?


SELECT UPPER( SUBSTR('Database Programming', INSTR('Database Programming','P'),20))
FROM dual;

Mark for Review


(1) Points

Database
Programming
DATABASE
PROGRAMMING (*)

1. The EMPLOYEES table contains these columns:


LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
HIRE_DATE DATE
EVAL_MONTHS NUMBER(3)

Evaluate this SELECT statement:

SELECT hire_date + eval_months


FROM employees;

The values returned by this SELECT statement will be of which data type?

Mark for Review


(1) Points

DATE (*)
INTEGER
NUMBER
DATETIME

2. If hire_date has a value of '03-Jul-2003', then what is the output from this code?
SELECT ROUND(hire_date, 'Year') FROM employees; Mark for Review
(1) Points

01-Jan-2004 (*)
01-Aug-2003
01-Jan-2003
01-Jul-2003

3. Which query would return a whole number if the sysdate is 26-May-2004? Mark for Review
(1) Points

SELECT TRUNC(MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;
(*)

SELECT TRUNC(YEARS_BETWEEN(SYSDATE,'19-Mar-1979') /12)


AS YEARS
FROM DUAL;

SELECT MONTHS_BETWEEN(SYSDATE,'19-Mar-1979') /12


AS YEARS
FROM DUAL;

None of the above

4. What is the result of the following query?


SELECT ADD_YEARS ('11-Jan-1994',6)
FROM dual; Mark for Review
(1) Points

11-Jul-2000
11-Jan-2000
This in not a valid SQL statement. (*)
11-Jul-1995

5. What is the result of the following query?


SELECT ADD_MONTHS ('11-Jan-1994',6)
FROM dual; Mark for Review
(1) Points

11-Jan-1995
11-Jul-1994 (*)
17-Jan-1994
17-Jul-1994

6. Which script displays '01-May-2004' when the HIRE_DATE value is '20-May-2004'? Mark
for Review
(1) Points

SELECT ROUND(hire_date, 'MONTH')


FROM employees;

SELECT ROUND(hire_date, 'MON')


FROM employees;
SELECT TRUNC(hire_date, 'MI')
FROM employees;

SELECT TRUNC(hire_date, 'MONTH')


FROM employees;
(*)

7. What is the result of the following SQL Statement:


SELECT ROUND(45.923,-1)
FROM DUAL; Mark for Review
(1) Points

46
45.9
50 (*)
None of the above

8. Which comparison operator retrieves a list of values? Mark for Review


(1) Points

IS NULL
BETWEEN IN
LIKE
IN (*)

9. Which number function may be used to determine if a value is odd or even? Mark for Review
(1) Points

TRUNC
ROUND
MOD (*)
BINARY

10. Evaluate this function: MOD (25, 2) Which value is returned? Mark for Review
(1) Points

2
25
1 (*)
0

11. Which of the following are types of SQL functions? (Choose two correct answers.) Mark for
Review
(1) Points
(Choose all correct answers)

Multi-Row Functions (*)


Single-Row Functions (*)
Column-Row Functions
Many-to-Many Functions
12. Which SQL function is used to return the position where a specific character string begins within a
larger character string? Mark for Review
(1) Points

INSTR (*)
SUBSTR
CONCAT
LENGTH

13. You issue this SQL statement:


SELECT INSTR ('organizational sales', 'al')
FROM dual;

Which value is returned by this command?

Mark for Review


(1) Points

13 (*)
1
2
17

14. You query the database with this SQL statement:


SELECT CONCAT(last_name, (SUBSTR(LOWER(first_name), 4))) "Default Password"
FROM employees;

Which function will be evaluated first?

Mark for Review


(1) Points

CONCAT
SUBSTR
LOWER (*)
All three will be evaluated simultaneously.

15. You need to display the number of characters in each customer's last name. Which function should
you use? Mark for Review
(1) Points

SUBSTR
LENGTH (*)
LPAD
COUNT

You might also like