Skip to main content

Section 3 Quiz Oracle Database Programming with SQL

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 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 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 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 > 25000 OR salary < 100000)
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id, salary;

            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;

2.         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
            Remove the table aliases in the WHERE clause.
            Reorder the clauses in the query. (*)
            Include a HAVING clause.
            Remove the table aliases in the ORDER BY clause.

3.         Will the following statement return one row?
SELECT MAX(salary), MIN(Salary), AVG(SALARY)
FROM employees;

 Mark for Review
(1) Points
            No, it is illegal. You cannot use more than one multi-row function in a SELECT statement.
            Yes, it will return the highest salary, the lowest salary, and the average salary from all employees. (*)
            Yes, it will return the highest salary from each employee.
            Yes, it will return the average salary from the employees table.

4.         The function COUNT is a single row function. True or False?            Mark for Review
(1) Points
            True
            False (*)

5.         The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9) PK
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
Compare these two SQL statements:

1.
SELECT DISTINCT department_id DEPT, last_name, first_name
FROM employees
ORDER BY department_id;

2.
SELECT department_id DEPT, last_name, first_name
FROM employees
ORDER BY DEPT;

How will the results differ?

 Mark for Review
(1) Points

            One of the statements will return a syntax error.
            One of the statements will eliminate all duplicate DEPARTMENT_ID values.
            There is no difference in the result between the two statements.
            The statements will sort on different column values. (*)

6.         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
                                                         
                                    (Choose all correct answers)  
                                                         
            last_name, first_name (*)
            Any column in the EMPLOYEES table, any expression in the SELECT list or any ALIAS in the SELECT list (*)
            All the columns in the database
            All columns in the EMPLOYEES table (*)
            The table name, EMPLOYEES, which would then automatically sort by all columns in the table

7.         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
GROUP BY price < 50;

            SELECT product_id, product_name
FROM products
HAVING price < 50;

            SELECT product_id, product_name
FROM products
WHERE price < 50;
(*)

            SELECT product_id, product_name
FROM products
WHERE price < 50.00
GROUP BY price;

            SELECT product_id, product_name
FROM products
WHERE price <= 50;

8.         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 alphabetically and then numerically. (*)
            The results are sorted numerically only.
            The results are sorted numerically and then alphabetically.
            The results are sorted alphabetically only.

9.         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 results will be sorted ascending by LAST_NAME and FIRST_NAME only.
            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 the LAST_NAME column only.
            The results will be sorted ascending by LAST_NAME, FIRST_NAME, and SALARY.

10.       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

11.       From left to right, what is the correct order of Precedence?     Mark for Review
(1) Points
                                 
            Arithmetic, Concatenation, Comparison, OR (*)
            Arithmetic, NOT, Logical, Comparison
            NOT, AND, OR, Arithmetic
            Arithmetic, NOT, Concatenation, Logical

12.       What will be the results of the following selection?
SELECT *
FROM employees
WHERE last_name NOT LIKE 'A%' AND last_name NOT LIKE 'B%'

 Mark for Review
(1) Points
                                 
            No rows will be returned. There is a syntax error
            All last names that do not begin with A or B (*)
            All rows will be returned
            All last names that begin with A or B

13.       The ORDER BY clause always comes last. True or False?      Mark for Review
(1) Points

            True (*)
            False

14.       Which symbol in the WHERE clause means "Not Equal To"? (Choose Two)  Mark for Review
(1) Points
                                    (Choose all correct answers)  
            =+
            <> (*)
            ><
            NOT IN (..) (*)

15.       Which comparison condition means "Less Than or Equal To"?           Mark for Review
(1) Points

            ">="
            "+<"
            "<=" (*)
            "=)"

1.         You attempt to query the database with this SQL statement:
SELECT product_id "Product Number", category_id "Category", price "Price"
FROM products
WHERE "Category" = 5570
ORDER BY "Product Number";

This statement fails when executed. Which clause contains a syntax error?

 Mark for Review
(1) Points

            WHERE "Category" = 5570 (*)
            SELECT product_id "Product Number", category_id "Category", price "price"
            FROM products
            ORDER BY "Product Number";

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

            Displays the fetched rows in no particular order
            Must be the last clause of the SQL statement (*)
            Defaults to a descending order (DESC)
            Defaults to an ascending order (ASC) (*)

3.         Evaluate this SELECT statement:
SELECT first_name, last_name, email
FROM employees
ORDER BY last_name;

Which statement is true?

 Mark for Review
(1) Points

            The rows will be sorted alphabetically by the FIRST_NAME and then the LAST_NAME values
            The rows will be sorted in reverse alphabetical order by the LAST_NAME values.
            The rows will not be sorted.
            The rows will be sorted alphabetically by the LAST_NAME values. (*)

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

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

5.         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
                                    (Choose all correct answers)  
            All columns in the EMPLOYEES table (*)
            The table name, EMPLOYEES, which would then automatically sort by all columns in the table
            Any column in the EMPLOYEES table, any expression in the SELECT list or any ALIAS in the SELECT list (*)
            last_name, first_name (*)
            All the columns in the database

6.         The following statement represents a multi-row function. True or False?
SELECT MAX(salary)
FROM employees

 Mark for Review
(1) Points

            True (*)
            False

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 HAVING clause.
            Remove the table aliases in the WHERE clause.
            Reorder the clauses in the query. (*)
            Remove the table aliases in the ORDER BY clause.

8.         The conversion function TO_CHAR is a single row function. True or False? Mark for Review
(1) Points

            True (*)
            False

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

10.       The function COUNT is a single row function. True or False?            Mark for Review
(1) Points

            True
            False (*)

11.       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

12.       Which of the following best describes the meaning of the LIKE operator?     Mark for Review
(1) Points

            Match a character pattern. (*)
            To test for values in a list.
            Display rows based on a range of values.
            To find Null values.

13.       Which statement about the ORDER BY clause is true?            Mark for Review
(1) Points

            You can use a column alias in the ORDER BY clause. (*)
            The default sort order of the ORDER BY clause is descending.
            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

14.       From left to right, what is the correct order of Precedence?     Mark for Review
(1) Points

            Arithmetic, NOT, Concatenation, Logical
            Arithmetic, NOT, Logical, Comparison
            Arithmetic, Concatenation, Comparison, OR (*)
            NOT, AND, OR, Arithmetic

15.       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 <=90 and cd_id >=92;
            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; (*)

1.         The function COUNT is a single row function. True or False?            Mark for Review
(1) Points

            True
            False (*)

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 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, first_name;

            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;

3.         The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9) PK
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
Compare these two SQL statements:

1.
SELECT DISTINCT department_id DEPT, last_name, first_name
FROM employees
ORDER BY department_id;

2.
SELECT department_id DEPT, last_name, first_name
FROM employees
ORDER BY DEPT;

How will the results differ?

 Mark for Review
(1) Points

            One of the statements will return a syntax error.
            There is no difference in the result between the two statements.
            One of the statements will eliminate all duplicate DEPARTMENT_ID values.
            The statements will sort on different column values. (*)

4.         The following statement represents a multi-row function. True or False?
SELECT MAX(salary)
FROM employees

 Mark for Review
(1) Points

            True (*)
            False

5.         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 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 > 25000 OR salary < 100000)
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id, salary;

            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 24999.99 AND 100000.01
AND team_id BETWEEN 1200 AND 1500
ORDER BY team_id DESC, salary DESC;

6.         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.
            You can use a column alias in the ORDER BY clause. (*)
            The default sort order of the ORDER BY clause is descending.
            The ORDER BY clause should immediately precede the FROM clause in a SELECT statement

7.         Which of the following best describes the meaning of the LIKE operator?     Mark for Review
(1) Points

            To find Null values.
            Match a character pattern. (*)
            Display rows based on a range of values.
            To test for values in a list.

8.         Which of the following are TRUE regarding the logical AND operator?          Mark for Review
(1) Points

            TRUE AND FALSE return FALSE (*)
            TRUE AND TRUE return FALSE
            TRUE AND FALSE return TRUE
            FALSE AND TRUE return NULL

9.         Which statement about the default sort order is true?  Mark for Review
(1) Points

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

10.       What will be the results of the following selection?
SELECT *
FROM employees
WHERE last_name NOT LIKE 'A%' AND last_name NOT LIKE 'B%'

 Mark for Review
(1) Points

            All last names that begin with A or B
            All last names that do not begin with A or B (*)
            No rows will be returned. There is a syntax error
            All rows will be returned

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, 3;

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;

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

            Defaults to an ascending order (ASC) (*)
            Must be the last clause of the SQL statement (*)
            Defaults to a descending order (DESC)
            Displays the fetched rows in no particular order

13.       A column alias can be specified in an ORDER BY Clause. True or False?      Mark for Review
(1) Points

            True (*)
            False

14.       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

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

15.       You attempt to query the database with this SQL statement:
SELECT product_id "Product Number", category_id "Category", price "Price"
FROM products
WHERE "Category" = 5570
ORDER BY "Product Number";

This statement fails when executed. Which clause contains a syntax error?

 Mark for Review
(1) Points

            WHERE "Category" = 5570 (*)
            ORDER BY "Product Number";
            FROM products
            SELECT product_id "Product Number", category_id "Category", price "price"

Comments