Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1K views

Oracle Database Programming - Section 3

1. The document contains questions and answers about SQL clauses like SELECT, WHERE, ORDER BY, and GROUP BY. 2. It tests knowledge of how these clauses can be used including sorting order, column usage, function types, operator precedence and more. 3. Correct answers are marked and feedback is provided to explain why some answers are incorrect.

Uploaded by

Angga Wijaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Oracle Database Programming - Section 3

1. The document contains questions and answers about SQL clauses like SELECT, WHERE, ORDER BY, and GROUP BY. 2. It tests knowledge of how these clauses can be used including sorting order, column usage, function types, operator precedence and more. 3. Correct answers are marked and feedback is provided to explain why some answers are incorrect.

Uploaded by

Angga Wijaya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Section 3

(Answer all questions in this section)


1. Which of the following is true of the ORDER BY clause:? (Choose Two)
Mark for Review

(1) Points
Defaults to an ascending order (ASC)(*)

Must be the last clause of the SQL statement(*)

Displays the fetched rows in no particular order


Defaults to a descending order (DESC)
Correct

2. Which columns can be added to the ORDER BY clause in the following


SELECT statement? (Choose Three)
SELECT first_name, last_name, salary, hire_date
FROM employees
WHERE department_id = 50
ORDER BY ?????;

Mark for Review

(1) Points
The table name, EMPLOYEES, which would then automatically sort by all columns in the table
All columns in the EMPLOYEES table(*)

last_name, first_name(*)

All the columns in the database


Any column in the EMPLOYEES table, any expression in the SELECT list or any ALIAS in the SELECT
list(*)
Correct

3. Evaluate this SELECT statement:


SELECT last_name, first_name, salary
FROM employees;

How will the results of this query be sorted?

Mark for Review

(1) Points
The database will display the rows in whatever order it finds it in the
database, so no particular order. (*)
The results will be sorted ascending by LAST_NAME and FIRST_NAME only.

The results will be sorted ascending by LAST_NAME, FIRST_NAME, and


SALARY.
The results will be sorted ascending by the LAST_NAME column only.
Correct.

4. Evaluate this SELECT statement:


SELECT last_name, first_name, email
FROM employees
ORDER BY email;

If the EMAIL column contains null values, which statement is true?

Mark for Review

(1) Points
The result will not be sorted.
Null email values will not be displayed in the result.
Null email values will be displayed last in the result. (*)
Null email values will be displayed first in the result.
Correct.

5. Evaluate this SELECT statement:


SELECT *
FROM employees
WHERE salary > 30000
AND department_id = 10
OR email IS NOT NULL;

Which statement is true?

Mark for Review

(1) Points
The OR and AND conditions have the same precedence and will be evaluated
from left to right
The OR condition will be evaluated before the AND condition.
The OR and AND conditions have the same precedence and will be evaluated
from right to left
The AND condition will be evaluated before the OR condition. (*)
Correct.
6. The conversion function TO_CHAR is a single row function. True or False?
Mark for Review

(1) Points
True (*)
False
Correct

7. Evaluate this SQL statement:


SELECT e.employee_id, e.last_name, e.first_name, m.manager_id
FROM employees e, employees m
ORDER BY e.last_name, e.first_name
WHERE e.employee_id = m.manager_id;

This statement fails when executed. Which change will correct the problem?

Mark for Review

(1) Points
Include a SORT clause.
Remove the table aliases in the WHERE clause.
Reorder the clauses in the query. (*)
Remove the table aliases in the ORDER BY clause.
Correct.

8. The function COUNT is a single row function. True or False?


Mark for Review

(1) Points
True
False (*)
Correct

9. The following statement represents a multi-row function. True or False?


SELECT UPPER(last_name)
FROM employees;
Mark for Review

(1) Points
True
False (*)
Correct

10. The following statement represents a multi-row function. True or False?


SELECT MAX(salary)
FROM employees

Mark for Review

(1) Points
True (*)
False
Correct
11. Which symbol in the WHERE clause means "Not Equal To"? (Choose Two)
Mark for Review

(1) Points
<>(*)

=+
><
NOT IN (..)(*)
Incorrect. See Section 3 Lesson 1.

12. Which of the following statements best describes the rules of precedence


when using SQL?
Mark for Review

(1) Points
The order in which the columns are displayed
The order in which the expressions are sorted
The order in which the operators are returned
The order in which the expressions are evaluated and calculated (*)
All of the above
Correct
13. Which clause would you include in a SELECT statement to sort the rows
returned by the LAST_NAME column?
Mark for Review

(1) Points
HAVING
FROM
WHERE
ORDER BY (*)
Correct.

14. The ORDER BY clause always comes last. True or False?


Mark for Review

(1) Points
True (*)
False
Correct.

15. Which logical operator returns TRUE if either condition is true?


Mark for Review

(1) Points
BOTH
NOT
OR (*)
AND
Correct.

1. The PLAYERS table contains these columns:


PLAYERS TABLE:
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)
SALARY NUMBER(8,2)
TEAM_ID NUMBER(4)
MANAGER_ID NUMBER(9)
POSITION_ID NUMBER(4)

You want to display all players' names with position 6900 or greater.
You want the players names to be displayed alphabetically by last name and
then by first name.
Which statement should you use to achieve the required results?

Mark for Review

(1) Points
SELECT last_name, first_name
FROM players
WHERE position_id >= 6900
ORDER BY last_name DESC, first_name;
SELECT last_name, first_name
FROM players
WHERE position_id <= 6900
ORDER BY last_name, first_name;
SELECT last_name, first_name
FROM players
WHERE position_id >= 6900
ORDER BY last_name, first_name; (*)
SELECT last_name, first_name
FROM players
WHERE position_id > 6900
ORDER BY last_name, first_name;
Correct.

2. The PLAYERS table contains these columns:


PLAYERS TABLE:
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)
SALARY NUMBER(8,2)
TEAM_ID NUMBER(4)
MANAGER_ID NUMBER(9)
POSITION_ID NUMBER(4)

You must display the player name, team id, and salary for players whose
salary is in the range from 25000 through 100000 and whose team id is in
the range of 1200 through 1500. The results must be sorted by team id from
lowest to highest and then further sorted by salary from highest to lowest.
Which statement should you use to display the desired result?

Mark for Review

(1) Points
SELECT last_name, first_name, team_id, salary
FROM players
WHERE salary > 24999.99 AND salary < 100000
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id ASC, salary DESC;
SELECT last_name, first_name, team_id, salary
FROM players
WHERE salary BETWEEN 25000 AND 100000
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id, salary DESC; (*)
SELECT last_name, first_name, team_id, salary
FROM players
WHERE salary BETWEEN 24999.99 AND 100000.01
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id DESC, salary DESC;
SELECT last_name, first_name, team_id, salary
FROM players
WHERE (salary > 25000 OR salary < 100000)
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id, salary;
Correct.

3. The function COUNT is a single row function. True or False?


Mark for Review

(1) Points
True
False (*)
Correct

4. The following statement represents a multi-row function. True or False?


SELECT UPPER(last_name)
FROM employees;

Mark for Review


(1) Points
True
False (*)
Correct

5. The following statement represents a multi-row function. True or False?


SELECT MAX(salary)
FROM employees

Mark for Review

(1) Points
True (*)
False
Correct
6. Which statement about the default sort order is true?
Mark for Review

(1) Points
The earliest date values are displayed first. (*)
The lowest numeric values are displayed last.
Null values are displayed first.
Character values are displayed in reverse alphabetical order.
Correct.

7. Which of the following statements best describes the rules of precedence


when using SQL?
Mark for Review

(1) Points
The order in which the columns are displayed
The order in which the expressions are sorted
The order in which the operators are returned
The order in which the expressions are evaluated and calculated (*)
All of the above
Correct

8. Which statement about the ORDER BY clause is true?


Mark for Review

(1) Points
The ORDER BY clause can only contain columns that are included in the
SELECT list.
The ORDER BY clause should immediately precede the FROM clause in a
SELECT statement
You can use a column alias in the ORDER BY clause. (*)
The default sort order of the ORDER BY clause is descending.
Correct.

9. From left to right, what is the correct order of Precedence?


Mark for Review

(1) Points
Arithmetic, NOT, Concatenation, Logical
Arithmetic, Concatenation, Comparison, OR (*)
Arithmetic, NOT, Logical, Comparison
NOT, AND, OR, Arithmetic
Correct.

10. Find the clause that will give the same results as:
SELECT *
FROM d_cds
WHERE cd_id NOT IN(90, 91, 92);

Mark for Review

(1) Points
WHERE cd_id NOT LIKE (90, 91, 92);
WHERE cd_id != 90 or cd_id != 91 or cd_id!= 92;
WHERE cd_id != 90 and cd_id != 91 and cd_id != 92; (*)
WHERE cd_id <=90 and cd_id >=92;
Correct
11. Evaluate this SELECT statement:
SELECT employee_id, last_name, first_name, salary 'Yearly Salary'
FROM employees
WHERE salary IS NOT NULL
 ORDER BY last_name, first_name; 
Which clause contains an error?
Mark for Review

(1) Points
FROM employees
SELECT employee_id, last_name, first_name, salary 'Yearly Salary' (*)
WHERE salary IS NOT NULL
ORDER BY last_name, 3;
Correct.

12. Evaluate this SQL statement:


SELECT product_id, product_name, price
FROM products
ORDER BY product_name, price;

What occurs when the statement is executed?

Mark for Review

(1) Points
The results are sorted numerically only.
The results are sorted numerically and then alphabetically.
The results are sorted alphabetically and then numerically. (*)
The results are sorted alphabetically only.
Correct.

13. Which SELECT statement should you use to limit the display of product
information to those products with a price of less than 50?
Mark for Review

(1) Points
SELECT product_id, product_name
FROM products
WHERE price < 50.00
GROUP BY price;
SELECT product_id, product_name
FROM products
GROUP BY price < 50;
SELECT product_id, product_name
FROM products
WHERE price <= 50;
SELECT product_id, product_name
FROM products
HAVING price < 50;
SELECT product_id, product_name
FROM products
WHERE price < 50; (*)
Correct.

14. Evaluate this SELECT statement:


SELECT *
FROM employees
WHERE department_id = 34
OR department_id = 45
OR department_id = 67;

Which operator is the equivalent of the OR conditions used in this SELECT


statement?

Mark for Review

(1) Points
IN (*)
AND
BETWEEN AND ...
LIKE
Correct.

15. You query the database with this SQL statement:


SELECT price
FROM products
WHERE price IN(1, 25, 50, 250)
AND (price BETWEEN 25 AND 40 OR price > 50);

Which two values could the statement return? (Choose two.)

Mark for Review

(1) Points
250(*)

50
1
25(*)

10
Correct.

You might also like