--> NOTES KOM: test oracle | Deskripsi Singkat Blog di Sini

Catatan tutorial dan berita tentang IT

Showing posts with label test oracle. Show all posts
Showing posts with label test oracle. Show all posts

Tuesday, 6 July 2021

no image

Quiz Oracle Database Programming with SQL Section 10

 

1. A multiple-row operator expects how many values? Mark for Review
(1) Points
One or more (*)
Only one
Two or more
None
2. The salary column of the f_staffs table contains the following values:
4000
5050
6000
11000
23000
Which of the following statements will return the last_name and fifirst_name of those
employees who earn more than 5000?
Mark for Review
(1) Points
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary IN
(SELECT last_name, fifirst_name FROM f_staffs WHERE salary <5000 o:p="">
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary = (SELECT salary FROM f_staffs WHERE salary < 5000);
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary IN (SELECT salary FROM f_staffs WHERE salary > 5000);
(*)
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary = (SELECT salary FROM f_staffs WHERE salary > 5000);
3. Examine the data in the PAYMENT table:
PAYMENT_ID CUSTOMER_ID PAYMENT_DATE PAYMENT_TYPE
PAYMENT_AMOUNT
86590586 8908090 10-Jun-2003 BASIC 859.00
89453485 8549038 15-Feb-2003 INTEREST 596.00
85490345 5489304 20-Mar-2003 BASIC 568.00
This statement fails when executed:
SELECT customer_id, payment_type
FROM payment
WHERE payment_id =
(SELECT payment_id
FROM payment
WHERE payment_amount = 596.00 OR payment_date = '20-Mar-2003');
Which change could correct the problem?
Mark for Review
(1) Points
Change the outer query WHERE clause to 'WHERE payment_id IN'. (*)
Remove the parentheses surrounding the nested SELECT statement.
Change the comparison operator to a single-row operator.
Remove the quotes surrounding the date value in the OR clause.
4. Which of the following statements contains a comparison operator that is used to
restrict rows based on a list of values returned from an inner query? Mark for Review
(1) Points
SELECT description
FROM d_types
WHERE code
IN (SELECT type_code FROM d_songs);
SELECT description
FROM d_types
WHERE code = ANY (SELECT type_code FROM d_songs);
SELECT description
FROM d_types
WHERE code <> ALL (SELECT type_code FROM d_songs);
All of the above. (*)
5. Group functions can be used in multiple-row subqueries in the HAVING and GROUP
BY clauses. True or False? Mark for Review
(1) Points
True (*)
False
6. The SQL multiple-row subquery extends the capability of the single-row syntax
through the use of which three comparison operators? Mark for Review
(1) Points
IN, ANY, and EVERY
IN, ALL, and EVERY
IN, ANY, and EQUAL
IN, ANY, and ALL (*)
7. Which statement about the <> operator is true? Mark for Review
(1) Points
The <> operator can be used when a single-row subquery returns only one row. (*)
The <> operator is NOT a valid SQL operator.
The <> operator CANNOT be used in a single-row subquery.
The <> operator returns the same result as the ANY operator in a subquery.
8. Single row subqueries may not include this operator: Mark for Review
(1) Points
>
<>
ALL (*)
=
9. Examine the structure of the EMPLOYEE, DEPARTMENT, and ORDERS tables.
EMPLOYEE:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
DEPARTMENT:
DEPARTMENT_ID NUMBER(9)
DEPARTMENT_NAME VARCHAR2(25)
CREATION_DATE DATE
ORDERS:
ORDER_ID NUMBER(9)
EMPLOYEE_ID NUMBER(9)
DATE DATE
CUSTOMER_ID NUMBER(9)
You want to display all employees who had an order after the Sales department was
established. Which of the following constructs would you use?
Mark for Review
(1) Points
The HAVING clause
A group function
A single-row subquery (*)
A MERGE statement
10. If you use the equality operator (=) with a subquery, how many values can the
subquery return? Mark for Review
(1) Points
Only 1 (*)
Up to 2
Up to 5
Unlimited
11. The TEACHERS and CLASS_ASSIGNMENTS tables contain these columns:
TEACHERS

TEACHER_ID NUMBER(5) Primary Key
NAME VARCHAR2 (25)
SUBJECT_ID NUMBER(5)
CLASS_ID NUMBER(5)
CLASS_ASSIGNMENTS
CLASS_ID NUMBER (5) Primary Key
TEACHER_ID NUMBER (5)
DATE
MAX_CAPACITY NUMBER (3)
All MAX_CAPACITY values are greater than 10. Which two SQL statements correctly use
subqueries? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
SELECT *
FROM teachers
WHERE teacher_id LIKE (SELECT teacher_id FROM class_assignments WHERE
max_capacity > 1000);
SELECT *
FROM teachers
WHERE teacher_id = (SELECT teacher_id FROM class_assignments WHERE class_id =
45963);
(*)
SELECT *
FROM class_assignments
max_capacity = (SELECT AVG(max_capacity) FROM class_assignments GROUP BY
teacher_id);
SELECT *
FROM teachers
WHERE teacher_id = (SELECT teacher_id, class_assignments WHERE max_capacity > 0);
SELECT *
FROM class_assignments
WHERE max_capacity = (SELECT AVG(max_capacity) FROM class_assignments);
(*)
12. Which operator can be used with a multiple-row subquery? Mark for Review
(1) Points
LIKE
IN (*)
=
<>
13. Which answer is INCORRECT? The parent statement of a correlated subquery can
be: Mark for Review
(1) Points
A SELECT statement
A DELETE statement
An UPDATE statement
An INSERT statement (*)
14. Oracle allows you to write named subqueries in one single statement, as long as you
start your statement with the keyword WITH. True or False? Mark for Review
(1) Points
True (*)
False
15. The Oracle server performs a correlated subquery when the subquery references a
column from a table referred to in the parent. True or False? Mark for Review
(1) Points
True (*)
False
1. In a non-correlated subquery, the outer query always executes prior to the inner
query's execution. True or False? Mark for Review
(1) Points
True
False (*)
2. Subqueries are limited to four per SQL transaction. True or False? Mark for
Review
(1) Points
True
False (*)

3. Which statement about the <> operator is true? Mark for Review
(1) Points
The <> operator can be used when a single-row subquery returns only one row. (*)
The <> operator is NOT a valid SQL operator.
The <> operator CANNOT be used in a single-row subquery.
The <> operator returns the same result as the ANY operator in a subquery.
4. Which statement about subqueries is true? Mark for Review
(1) Points
Subqueries should be enclosed in double quotation marks.
Subqueries generally execute last, after the main or outer query executes.
Subqueries cannot contain group functions.
Subqueries are often used in a WHERE clause to return values for an unknown
conditional value. (*)
5. You need to create a report to display the names of products with a cost value
greater than the average cost of all products. Which SELECT statement should you
use? Mark for Review
(1) Points
SELECT product_name
FROM products
WHERE cost > AVG(cost);
SELECT product_name
FROM products
WHERE cost > (SELECT AVG(cost)
FROM products);
(*)
SELECT AVG(cost), product_name
FROM products
WHERE cost > AVG(cost)
GROUP by product_name;
SELECT product_name
FROM (SELECT AVG(cost) FROM product)
WHERE cost > AVG(cost);
6. The TEACHERS and CLASS_ASSIGNMENTS tables contain these columns:
TEACHERS
TEACHER_ID NUMBER(5) Primary Key
NAME VARCHAR2 (25)
SUBJECT_ID NUMBER(5)
CLASS_ID NUMBER(5)
CLASS_ASSIGNMENTS
CLASS_ID NUMBER (5) Primary Key
TEACHER_ID NUMBER (5)
DATE
MAX_CAPACITY NUMBER (3)
All MAX_CAPACITY values are greater than 10. Which two SQL statements correctly use
subqueries? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
SELECT *
FROM class_assignments
max_capacity = (SELECT AVG(max_capacity) FROM class_assignments GROUP BY
teacher_id);
SELECT *
FROM teachers
WHERE teacher_id = (SELECT teacher_id FROM class_assignments WHERE class_id =
45963);
(*)
SELECT *
FROM teachers
WHERE teacher_id LIKE (SELECT teacher_id FROM class_assignments WHERE
max_capacity > 1000);
SELECT *
FROM class_assignments
WHERE max_capacity = (SELECT AVG(max_capacity) FROM class_assignments);
(*)
SELECT *
FROM teachers
WHERE teacher_id = (SELECT teacher_id, class_assignments WHERE max_capacity > 0);

7. When creating a report of all employees earning more than the average salary for
their department, a __________ ____________ can be used to fifirst calculate the average salary
of each department, and then compare the salary for each employee to the average salary
of that employeeοΎ’s department. Mark for Review
(1) Points
WITH CLAUSE
GROUP BY
CORRELATED SUBQUERY (*)
8. Which statement is false? Mark for Review
(1) Points
The WITH clause retrieves the results of one or more query blocks.
The WITH clause stores the results for the user who runs the query.
The WITH clause decreases performance. (*)
The WITH clause makes the query simple to read.
9. Correlated Subqueries must reference the same tables in both the inner and outer
queries. (True or False?) Mark for Review
(1) Points
True
False (*)
10. When a multiple-row subquery uses the NOT IN operator (equivalent to <>ALL), if
one of the values returned by the inner query is a null value, the entire query returns:
Mark for Review
(1) Points
All rows that were selected by the inner query including the null values
No rows returned (*)
All rows that were selected by the inner query minus the null values
A list of Nulls
11. Examine the structures of the PARTS and MANUFACTURERS tables:
PARTS:
PARTS_ID VARCHAR2(25) PK
PARTS_NAME VARCHAR2(50)
MANUFACTURERS_ID NUMBER
COST NUMBER(5,2)
PRICE NUMBER(5,2)
MANUFACTURERS:
ID NUMBER PK
NAME VARCHAR2(30)
LOCATION VARCHAR2(20)
Assume that the tables have been populated with data including 100 rows in the PARTS
table, and 20 rows in the MANUFACTURERS table. Which SQL statement correctly uses a
subquery?
Mark for Review
(1) Points
SELECT parts_name, price, cost
FROM parts
WHERE manufacturers_id !=
(SELECT id
FROM manufacturers
WHERE LOWER(name) = 'cost plus');
SELECT parts_name, price, cost
FROM parts
WHERE manufacturers_id IN
(SELECT id
FROM manufacturers m
JOIN parts p
ON (m.id = p.manufacturers_id));
(*)
UPDATE parts SET price = price * 1.15
WHERE manufacturers_id =
(SELECT id
FROM manufacturers
WHERE UPPER(location) IN("ATLANTA", "BOSTON", "DALLAS"));
SELECT parts_name
FROM (SELECT AVG(cost) FROM manufacturers)
WHERE cost > AVG(cost);
12. You need to create a SELECT statement that contains a multiple-row subquery.
Which comparison operator(s) can you use? Mark for Review
(1) Points
=, <, and >
IN, ANY, and ALL (*)
LIKE

BETWEENοΎ…ANDοΎ…
13. You are looking for Executive information using a subquery.
What will the following SQL statement display?
SELECT department_id, last_name, job_id
FROM employees
WHERE department_id IN
(SELECT department_id FROM departments WHERE department_name = 'Executive');
Mark for Review
(1) Points
The department ID, department name, and last name for every employee in the
Executive department
The department ID, last name, and department name for every Executive in the
employees table
The department ID, last name, and job ID from departments for Executive
employees
The department ID, last name, and job ID for every employee in the Executive
department (*)
14. Evaluate the structure of the EMPLOYEES and DEPART_HIST tables:
EMPLOYEES
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
MANAGER_ID NUMBER(9)
SALARY NUMBER(7,2)
DEPART_HIST:
EMPLOYEE_ID NUMBER(9)
OLD_DEPT_ID NUMBER(9)
NEW_DEPT_ID NUMBER(9)
CHANGE_DATE DATE
You want to generate a list of employees who are in department 10, but used to be in
department 15. Which query should you use?
Mark for Review
(1) Points
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) =
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE new_dept_id = 15);
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) IN
(SELECT employee_id, dept_id
FROM employees
WHERE old_dept_id = 15);
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id) IN
(SELECT employee_id
FROM employee_hist
WHERE old_dept_id = 15);
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) IN
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE old_dept_id = 15) AND new_dept_id = 10;
(*)
15. Which of the following best describes the meaning of the ANY operator? Mark
for Review
(1) Points
Equal to any member in the list
Equal to each value in the list
Compare value to the fifirst value returned by the subquery
Compare value to each value returned by the subquery (*)
1. Table aliases must be used when you are writing correlated subqueries. (True or
false?) Mark for Review
(1) Points

True
False (*)
2. Oracle allows you to write named subqueries in one single statement, as long as you
start your statement with the keyword WITH. True or False? Mark for Review
(1) Points
True (*)
False
3. Which statement is false? Mark for Review
(1) Points
The WITH clause decreases performance. (*)
The WITH clause makes the query simple to read.
The WITH clause stores the results for the user who runs the query.
The WITH clause retrieves the results of one or more query blocks.
4. Subqueries can only be placed in the WHERE clause. True or False? Mark for
Review
(1) Points
True
False (*)
5. Which operator can be used with a multiple-row subquery? Mark for Review
(1) Points
IN (*)
LIKE
<>
=
6. Using a subquery in which clause will return a syntax error? Mark for Review
(1) Points
WHERE
FROM
HAVING
You can use subqueries in all of the above clauses. (*)
7. Which comparison operator can only be used with a single-row subquery? Mark
for Review
(1) Points
IN
<> (*)
ANY
ALL
8. Subqueries are limited to four per SQL transaction. True or False? Mark for
Review
(1) Points
True
False (*)
9. You need to produce a report that contains all employee-related information for
those employees who have Brad Carter as a supervisor. However, you are not sure which
supervisor ID belongs to Brad Carter. Which query should you issue to accomplish this
task? Mark for Review
(1) Points
SELECT *
FROM employees
WHERE supervisor_id = (SELECT supervisor_id
FROM employees
WHERE last_name = 'Carter');
SELECT *
FROM supervisors
WHERE supervisor_id =
(SELECT supervisor_id
FROM employees
WHERE last_name = 'Carter');
SELECT *
FROM employees
WHERE supervisor_id =
(SELECT employee_id
FROM employees
WHERE last_name = 'Carter');
(*)
SELECT *
FROM supervisors
WHERE supervisor_id =
(SELECT employee_id
FROM supervisors
WHERE last_name = 'Carter');

10. Which operator or keyword cannot be used with a multiple-row subquery? Mark
for Review
(1) Points
>
= (*)
ANY
ALL
11. When a multiple-row subquery uses the NOT IN operator (equivalent to <>ALL), if
one of the values returned by the inner query is a null value, the entire query returns:
Mark for Review
(1) Points
A list of Nulls
No rows returned (*)
All rows that were selected by the inner query including the null values
All rows that were selected by the inner query minus the null values
12. Evaluate this SQL statement:
SELECT employee_id, last_name, salary
FROM employees
WHERE department_id IN
(SELECT department_id
FROM employees
WHERE salary > 30000 AND salary < 50000);
Which values will be displayed?
Mark for Review
(1) Points
Only employees who earn more than $30,000.
All employees who work in a department with employees who earn more than
$30,000 and more than $50,000.
All employees who work in a department with employees who earn more than
$30,000, but less than $50,000. (*)
Only employees who earn less than $50,000.
13. Group functions can be used in multiple-row subqueries in the HAVING and GROUP
BY clauses. True or False? Mark for Review
(1) Points
True (*)
False
14. The SQL multiple-row subquery extends the capability of the single-row syntax
through the use of which three comparison operators? Mark for Review
(1) Points
IN, ANY, and ALL (*)
IN, ANY, and EVERY
IN, ALL, and EVERY
IN, ANY, and EQUAL
15. Evaluate the structure of the EMPLOYEES and DEPART_HIST tables:
EMPLOYEES
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
MANAGER_ID NUMBER(9)
SALARY NUMBER(7,2)
DEPART_HIST:
EMPLOYEE_ID NUMBER(9)
OLD_DEPT_ID NUMBER(9)
NEW_DEPT_ID NUMBER(9)
CHANGE_DATE DATE
You want to generate a list of employees who are in department 10, but used to be in
department 15. Which query should you use?
Mark for Review
(1) Points
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) =
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE new_dept_id = 15);
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) IN

(SELECT employee_id, dept_id
FROM employees
WHERE old_dept_id = 15);
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id, department_id) IN
(SELECT employee_id, new_dept_id
FROM depart_hist
WHERE old_dept_id = 15) AND new_dept_id = 10;
(*)
SELECT employee_id, last_name, fifirst_name, department_id
FROM employees
WHERE (employee_id) IN
(SELECT employee_id
FROM employee_hist
WHERE old_dept_id = 15);
1. The Oracle server performs a correlated subquery when the subquery references a
column from a table referred to in the parent. True or False? Mark for Review
(1) Points
True (*)
False
2. The WITH clause is a way of creating extra tables in the database. (True or False?)
Mark for Review
(1) Points
True
False (*)
3. In a correlated subquery, the outer and inner queries are joined on one or more
columns. (True or False?) Mark for Review
(1) Points
True (*)
False
4. If a single-row subquery returns a null value and uses the equality comparison
operator, what will the outer query return? Mark for Review
(1) Points
All the rows in the table
No rows (*)
A null value
An error
5. Examine the structure of the EMPLOYEE, DEPARTMENT, and ORDERS tables.
EMPLOYEE:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
DEPARTMENT:
DEPARTMENT_ID NUMBER(9)
DEPARTMENT_NAME VARCHAR2(25)
CREATION_DATE DATE
ORDERS:
ORDER_ID NUMBER(9)
EMPLOYEE_ID NUMBER(9)
DATE DATE
CUSTOMER_ID NUMBER(9)
You want to display all employees who had an order after the Sales department was
established. Which of the following constructs would you use?
Mark for Review
(1) Points
A MERGE statement
A group function
The HAVING clause
A single-row subquery (*)
6. Single row subqueries may not include this operator: Mark for Review
(1) Points
=
>
<>
ALL (*)
7. The SQL multiple-row subquery extends the capability of the single-row syntax
through the use of which three comparison operators? Mark for Review
(1) Points

IN, ANY, and EQUAL
IN, ANY, and ALL (*)
IN, ALL, and EVERY
IN, ANY, and EVERY
8. Which of the following best describes the meaning of the ANY operator? Mark
for Review
(1) Points
Equal to each value in the list
Equal to any member in the list
Compare value to the fifirst value returned by the subquery
Compare value to each value returned by the subquery (*)
9. Which comparison operator would you use to compare a value to every value
returned by a subquery? Mark for Review
(1) Points
IN
ANY
SOME
ALL (*)
10. A multiple-row operator expects how many values? Mark for Review
(1) Points
One or more (*)
Only one
Two or more
None
11. Evaluate this SELECT statement:
SELECT player_id, name
FROM players
WHERE team_id IN
(SELECT team_id
FROM teams
WHERE team_id > 300 AND salary_cap > 400000);
What would happen if the inner query returned a NULL value?
Mark for Review
(1) Points
A syntax error in the outer query would be returned.
No rows would be returned by the outer query. (*)
A syntax error in the inner query would be returned.
All the rows in the PLAYER table would be returned by the outer query.
12. You need to create a SELECT statement that contains a multiple-row subquery.
Which comparison operator(s) can you use? Mark for Review
(1) Points
LIKE
BETWEENοΎ…ANDοΎ…
IN, ANY, and ALL (*)
=, <, and >
13. You need to display all the players whose salaries are greater than or equal to John
Brown's salary. Which comparison operator should you use? Mark for Review
(1) Points
=
<=
>= (*)
>
14. What will the following statement return:
SELECT last_name, salary
FROM employees
WHERE salary < (SELECT salary
FROM employees
WHERE employee_id = 103);
Mark for Review
(1) Points
A list of last_names and salaries of employees who make more than employee 103
A list of last_names and salaries of employees who make less than employee 103 (*)
A list of fifirst_names and salaries of employees making less than employee 103
Nothing. It is an invalid statement.
15. Which of the following is TRUE regarding the order of subquery execution? Mark
for Review
(1) Points
The subquery executes once after the main query.
The result of the main query is used with the subquery.
The subquery executes once before the main query. (*)
The outer query is executed fifirst.
1. Examine the structure of the EMPLOYEE, DEPARTMENT, and ORDERS tables.
EMPLOYEE:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
DEPARTMENT_ID NUMBER(9)
DEPARTMENT:
DEPARTMENT_ID NUMBER(9)
DEPARTMENT_NAME VARCHAR2(25)
CREATION_DATE DATE
ORDERS:
ORDER_ID NUMBER(9)
EMPLOYEE_ID NUMBER(9)
DATE DATE
CUSTOMER_ID NUMBER(9)
You want to display all employees who had an order after the Sales department was
established. Which of the following constructs would you use?
Mark for Review
(1) Points
A group function
The HAVING clause
A single-row subquery (*)
A MERGE statement
2. If a single-row subquery returns a null value and uses the equality comparison
operator, what will the outer query return? Mark for Review
(1) Points
No rows (*)
A null value
All the rows in the table
An error
3. The result of this statement will be:
SELECT last_name, job_id, salary, department_id
FROM employees
WHERE job_id =
(SELECT job_id
FROM employees
WHERE employee_id = 141) AND
department_id =
(SELECT department_id
FROM departments
WHERE location_id =1500);
Mark for Review
(1) Points
Only the employees whose job id matches employee 141 and who work in location
1500 (*)
All employees from Location 1500 will be displayed
All employees with the department id of 141
An error since you canοΎ’t get data from two tables in the same subquery
4. Which answer is INCORRECT? The parent statement of a correlated subquery can
be: Mark for Review
(1) Points
A SELECT statement
An UPDATE statement
A DELETE statement
An INSERT statement (*)
5. Table aliases must be used when you are writing correlated subqueries. (True or
false?) Mark for Review
(1) Points
True
False (*)
6. The WITH clause enables a SELECT statement to defifine the subquery block at the
start of the query, process the block just once, label the results, and then refer to the
results multiple times. True or False? Mark for Review
(1) Points
True (*)
False
7. Which of the following statements is a true guideline for using subqueries? Mark
for Review
(1) Points
The outer and inner queries can reference more than one table. They can get data
from different tables. (*)
Do not enclose the subquery in parentheses
Only one WHERE clause can be used for a SELECT statement, and if specifified, it
must be the outer query.
Place the subquery on the left side of the comparison condition.
8. You need to create a report to display the names of products with a cost value
greater than the average cost of all products. Which SELECT statement should you
use? Mark for Review
(1) Points
SELECT product_name
FROM (SELECT AVG(cost) FROM product)
WHERE cost > AVG(cost);
SELECT AVG(cost), product_name
FROM products
WHERE cost > AVG(cost)
GROUP by product_name;
SELECT product_name
FROM products
WHERE cost > (SELECT AVG(cost)
FROM products);
(*)
SELECT product_name
FROM products
WHERE cost > AVG(cost);
9. You need to display all the players whose salaries are greater than or equal to John
Brown's salary. Which comparison operator should you use? Mark for Review
(1) Points
>= (*)
=
<=
>
10. Evaluate this SELECT statement:
SELECT customer_id, name
FROM customer
WHERE customer_id IN
(SELECT customer_id
FROM customer
WHERE state_id = 'GA' AND credit_limit > 500.00);
What would happen if the inner query returned null?
Mark for Review
(1) Points
Only the rows with CUSTOMER_ID values equal to null would be selected.
No rows would be returned by the outer query. (*)
An error would be returned.
All the rows in the table would be selected.
11. Which statement about the ANY operator, when used with a multiple-row subquery,
is true? Mark for Review
(1) Points
The ANY operator is a synonym for the ALL operator.
The ANY operator can be used with the LIKE and IN operators.
The ANY operator compares every value returned by the subquery. (*)
The ANY operator can be used with the DISTINCT keyword.
12. Multiple-row subqueries must have NOT, IN, or ANY in the WHERE clause of the
inner query. True or False? Mark for Review
(1) Points
True
False (*)
13. Group functions can be used in multiple-row subqueries in the HAVING and GROUP
BY clauses. True or False? Mark for Review
(1) Points
True (*)
False
14. The salary column of the f_staffs table contains the following values:
4000
5050
6000
11000
23000
Which of the following statements will return the last_name and fifirst_name of those
employees who earn more than 5000?
Mark for Review
(1) Points

SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary = (SELECT salary FROM f_staffs WHERE salary < 5000);
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary = (SELECT salary FROM f_staffs WHERE salary > 5000);
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary IN (SELECT salary FROM f_staffs WHERE salary > 5000);
(*)
SELECT last_name, fifirst_name
FROM f_staffs
WHERE salary IN
(SELECT last_name, fifirst_name FROM f_staffs WHERE salary <5000 o:p="">
Correct Correct
15. You need to create a SELECT statement that contains a multiple-row
subquery. Which comparison operator(s) can you use? Mark for Review
(1) Points
LIKE
IN, ANY, and ALL (*)
=, <, and >
BETWEENοΎ…ANDοΎ…

Which of the following is a valid reason why the query below will not execute successfully?
SELECT employee_id, last_name, salary
FROM employees
WHERE department_id =
(SELECT department_id FROM employees WHERE last_name like '%u%');
Mark for Review
(1) Points
First subquery not enclosed in parentheses.
The greater than operator is not valid.*
A single, rather than a multiple value operator was used.
Second subquery found on the right instead of the left side of the operator.


A correlated subquery is evaluated _____ for each row processed by the parent statement. Mark
for Review
(1) Points
ONCE*
EVERY TIME
COMPLETELY


Which of the following is a valid reason why the query below will not execute successfully?
SELECT employee_id, last_name, salary
FROM employees
WHERE department_id =
(SELECT department_id FROM employees WHERE last_name like '%u%');
The greater than operator is not valid.
Second subquery found on the right instead of the left side of the operator.
First subquery not enclosed in parentheses.
A single, rather than a multiple value operator was used.


using candidate row value, and _______ values from the inner query to qualify or disqualify the
candidate row.
ROLLUP; GRANT; DROP
DELETE; UPDATE; INSERT
GET; EXECUTE; USE (*)
CREATE; EXECUTE; USE


2- Which operator can be used with subqueries that return only one row?
ANY
ALL
IN
LIKE (*)
3- Subqueries can only be placed in the WHERE clause. True or False?
True
False (*) 
no image

Quiz Oracle Database Programming with SQL Section 9

 

1. If you want to include subtotals and grand totals for all columns mentioned in a
GROUP BY clause, you should use which of the following extensions to the GROUP BY
clause? Mark for Review
(1) Points
HAVING
ROLLUP
CUBE (*)
GROUP BY ALL COLUMNS
2. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY GROUPING SETS((department_id, manager_id), (department_id, job_id))
What data will this query generate?
Mark for Review
(1) Points
Sum of salaries for (department_id, job_id) and (department_id, manager_id) (*)
Sum of salaries for (department_id, job_id, manager_id)
Subtotals for (job_id, manager_id)
The statement will fail.
3. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY ROLLUP(department_id, manager_id)
What extra data will this query generate?
Mark for Review
(1) Points
Subtotals for department_id, and grand totals for salary
Subtotals for department_id, job_id and grand totals for salary
Subtotals for department_id, job_id, manager_id and grand totals for salary
The statement will fail. (*)
4. You use ROLLUP to: Mark for Review
(1) Points
produce subtotal values (*)
cross-tabulate values
produce a single result set
5. CUBE will cross-reference the columns listed in the ______ clause to create a superset
of groups. Mark for Review
(1) Points
GROUP BY (*)
WHERE
SELECT
6. CUBE can be applied to all aggregate functions including AVG, SUM, MIN, MAX, and
COUNT. True or False? Mark for Review
(1) Points
True (*)
False

7. Which of the following are correct SET operators? (choose two) Mark for
Review
(1) Points
(Choose all correct answers)
MINUS, PLUS
UNION, MINUS (*)
UNION ALL, PLUS ALL
UNION ALL, INTERSECT (*)
8. The ___________ operator returns all rows from both tables, after eliminating
duplicates. Mark for Review
(1) Points
UNION ALL
UNION (*)
MINUS
INTERSECT
9. To control the order of rows returned using SET operators, the ORDER BY clause is
used ______ and is placed in the _____ SELECT statement of the query. Mark for Review
(1) Points
ONCE; LAST (*)
IN ALL; LAST
ONCE; FIRST
TWICE; FIRST
10. If a select list contains both a column as well as a group function then what clause is
required? Mark for Review
(1) Points
HAVING clause
GROUP BY clause (*)
ORDER BY clause
JOIN clause
11. Is the following statement correct?
SELECT fifirst_name, last_name, salary, department_id, COUNT(employee_id)
FROM employees
WHERE department_id = 50
GROUP BY last_name, fifirst_name, department_id;
Mark for Review
(1) Points
Yes
No, because the statement is missing salary in the GROUP BY clause (*)
Yes, because Oracle will correct any mistakes in the statement itself
No, beause you cannot have a WHERE-clause when you use group functions.
12. What will the following SQL Statement do?
SELECT job_id, COUNT(*)
FROM employees
GROUP BY job_id;
Mark for Review
(1) Points
Displays each job id and the number of people assigned to that job id (*)
Displays all the jobs with as many people as there are jobs
Displays only the number of job_ids
Displays all the employees and groups them by job
13. The PLAYERS table contains these columns:
PLAYER_ID NUMBER PK
PLAYER_NAME VARCHAR2 (30)
TEAM_ID NUMBER
HIRE_DATE DATE
SALARY NUMBER (8,2)
Which clauses represent valid uses of aggregate functions? (Choose three.)
Mark for Review
(1) Points
(Choose all correct answers)
SELECT AVG(NVL(salary, 0)) (*)
GROUP BY MAX(salary)
ORDER BY AVG(salary) (*)
WHERE hire_date > AVG(hire_date)
HAVING MAX(salary) > 10000 (*)
14. Evaluate this SELECT statement:
SELECT MIN(hire_date), department_id
FROM employees
GROUP BY department_id;
Which values are displayed?

Mark for Review
(1) Points
The hire dates in the EMPLOYEES table that contain NULL values
The latest hire date in the EMPLOYEES table
The earliest hire date in each department (*)
The earliest hire date in the EMPLOYEES table
15. The EMPLOYEES table contains these columns:
ID_NUMBER NUMBER Primary Key
NAME VARCHAR2 (30)
DEPARTMENT_ID NUMBER
SALARY NUMBER (7,2)
HIRE_DATE DATE
Evaluate this SQL statement:
SELECT id_number, name, department_id, SUM(salary)
FROM employees
WHERE salary > 25000
GROUP BY department_id, id_number, name
ORDER BY hire_date;
Why will this statement cause an error?
Mark for Review
(1) Points
The HAVING clause is missing.
The SALARY column is NOT included in the GROUP BY clause.
The WHERE clause contains a syntax error.
The HIRE_DATE column is NOT included in the GROUP BY clause. (*)
1. Which statement about group functions is true? Mark for Review
(1) Points
Group functions can only be used in a SELECT list.
A query that includes a group function in the SELECT list must include a GROUP BY
clause.
Group functions ignore null values. (*)
Group functions can be used in a WHERE clause.
2. What is the best explanation as to why this SQL statement will NOT execute?
SELECT department_id "Department", AVG (salary)"Average"
FROM employees
GROUP BY Department;
Mark for Review
(1) Points
The GROUP BY clause must have something to GROUP.
Salaries cannot be averaged as not all the numbers will divide evenly.
You cannot use a column alias in the GROUP BY clause. (*)
The department id is not listed in the departments table.
3. The PRODUCTS table contains these columns:
PROD_ID NUMBER(4)
PROD_NAME VARCHAR(20)
PROD_CAT VARCHAR2(15)
PROD_PRICE NUMBER(5)
PROD_QTY NUMBER(4)
You need to identify the minimum product price in each product category.
Which statement could you use to accomplish this task?
Mark for Review
(1) Points
SELECT prod_price, MIN (prod_cat)
FROM products
GROUP BY prod_cat;
SELECT prod_cat, MIN (prod_price)
FROM products
GROUP BY prod_price;
SELECT prod_cat, MIN (prod_price)
FROM products
GROUP BY prod_cat;
(*)
SELECT MIN (prod_price), prod_cat
FROM products
GROUP BY MIN (prod_price), prod_cat;
4. Evaluate this statement:

SELECT department_id, AVG(salary)
FROM employees
WHERE job_id <> 69879
GROUP BY job_id, department_id
HAVING AVG(salary) > 35000
ORDER BY department_id;
Which clauses restricts the result? Choose two.
Mark for Review
(1) Points
(Choose all correct answers)
GROUP BY job_id, department_id
WHERE job_id <> 69879 (*)
SELECT department_id, AVG(salary)
HAVING AVG(salary) > 35000 (*)
5. The PRODUCTS table contains these columns:
PRODUCT_ID NUMBER(9) PK
CATEGORY_ID VARCHAR2(10)
LOCATION_ID NUMBER(9)
DESCRIPTION VARCHAR2(30)
COST NUMBER(7,2)
PRICE NUMBER(7,2)
QUANTITY NUMBER
You display the total of the extended costs for each product category by location.
You need to include only the products that have a price less than $25.00.
The extended cost of each item equals the quantity value multiplied by the cost value.
Which SQL statement will display the desired result?
Mark for Review
(1) Points
SELECT SUM(cost * quantity) TOTAL
FROM products
WHERE price < 25.00;
SELECT category_id, SUM(cost * quantity) TOTAL,location_id
FROM products
WHERE price > 25.00
GROUP BY category_id, location_id;
SELECT SUM(cost * quantity) TOTAL, location_id
FROM products
WHERE price < 25.00
GROUP BY location_id;
SELECT category_id, SUM(cost * quantity) TOTAL, location_id
FROM products
WHERE price < 25.00
GROUP BY category_id, location_id;
(*)
6. Evaluate this SELECT statement:
SELECT COUNT(employee_id), department_id
FROM employees
GROUP BY department_id;
You only want to include employees who earn more than 15000.
Which clause should you include in the SELECT statement?
Mark for Review
(1) Points
HAVING salary > 15000
HAVING SUM(salary) > 15000
WHERE salary > 15000 (*)
WHERE SUM(salary) > 15000
7. You use GROUPING functions to: Mark for Review
(1) Points
Produce subtotal and cross-tabulated values
Identify the extra row values created by either a ROLLUP or CUBE operation (*)
Aggregate rows using SUM, MIN, MAX, and COUNT
8. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY GROUPING SETS((department_id, manager_id), (department_id, job_id)) 

What data will this query generate?
Mark for Review
(1) Points
Sum of salaries for (department_id, job_id) and (department_id, manager_id) (*)
Sum of salaries for (department_id, job_id, manager_id)
Subtotals for (job_id, manager_id)
The statement will fail.
9. CUBE will cross-reference the columns listed in the ______ clause to create a superset
of groups. Mark for Review
(1) Points
SELECT
GROUP BY (*)
WHERE
10. You use ROLLUP to: Mark for Review
(1) Points
cross-tabulate values
produce subtotal values (*)
produce a single result set
11. GROUPING SETS is another extension to the GROUP BY clause and is used to specify
multiple groupings of data but provide a single result set. True or False? Mark for
Review
(1) Points
True (*)
False
12. If you want to include subtotals and grand totals for all columns mentioned in a
GROUP BY clause, you should use which of the following extensions to the GROUP BY
clause? Mark for Review
(1) Points
ROLLUP
GROUP BY ALL COLUMNS
HAVING
CUBE (*)
13. Which of the following are correct SET operators? (choose two) Mark for
Review
(1) Points
(Choose all correct answers)
UNION, MINUS (*)
UNION ALL, PLUS ALL
MINUS, PLUS
UNION ALL, INTERSECT (*)
14. The difference between UNION and UNION ALL is Mark for Review
(1) Points
There is no difference; you get exactly the same result from both.
UNION ALL is more like a NATURAL JOIN.
UNION will remove duplicates; UNION ALL returns all rows from all queries
including the duplicates. (*)
UNION is a synomym for UNION ALL.
15. When using SET operators, the names of the matching columns must be identical in
all of the SELECT statements used in the query. True or False? Mark for Review
(1) Points
True
False (*)
1. How would you alter the following query to list only employees where two or more
employees have the same last name?
SELECT last_name, COUNT(employee_id)
FROM EMPLOYEES
GROUP BY last_name;
Mark for Review
(1) Points
SELECT last_name, COUNT(employee_id)
FROM EMPLOYEES
WHERE COUNT(*) > 1
GROUP BY last_name
SELECT last_name, COUNT(last_name)
FROM EMPLOYEES
GROUP BY last_name

HAVING COUNT(last_name) > 1;
(*)
SELECT last_name, COUNT(last_name)
FROM EMPLOYEES
GROUP BY last_name
EXISTS COUNT(last_name) > 1;
SELECT employee_id, DISTINCT(last_name)
FROM EMPLOYEES
GROUP BY last_name
HAVING last_name > 1;
2. Which statement about the GROUP BY clause is true? Mark for Review
(1) Points
To exclude rows before dividing them into groups using the GROUP BY clause, you
should use a WHERE clause. (*)
You can use a column alias in a GROUP BY clause.
You must use the HAVING clause with the GROUP BY clause.
By default, rows are not sorted when a GROUP BY clause is used.
3. The PRODUCTS table contains these columns:
PRODUCT_ID NUMBER(9) PK
CATEGORY_ID VARCHAR2(10)
LOCATION_ID NUMBER(9)
DESCRIPTION VARCHAR2(30)
COST NUMBER(7,2)
PRICE NUMBER(7,2)
QUANTITY NUMBER
You display the total of the extended costs for each product category by location.
You need to include only the products that have a price less than $25.00.
The extended cost of each item equals the quantity value multiplied by the cost value.
Which SQL statement will display the desired result?
Mark for Review
(1) Points
SELECT SUM(cost * quantity) TOTAL, location_id
FROM products
WHERE price < 25.00
GROUP BY location_id;
SELECT category_id, SUM(cost * quantity) TOTAL,location_id
FROM products
WHERE price > 25.00
GROUP BY category_id, location_id;
SELECT category_id, SUM(cost * quantity) TOTAL, location_id
FROM products
WHERE price < 25.00
GROUP BY category_id, location_id;
(*)
SELECT SUM(cost * quantity) TOTAL
FROM products
WHERE price < 25.00;
4. Evaluate this SELECT statement:
SELECT SUM(salary), department_id, manager_id
FROM employees
GROUP BY department_id, manager_id;
Which SELECT clause allows you to restrict the rows returned, based on a group function?
Mark for Review
(1) Points
HAVING salary > 100000
HAVING SUM(salary) > 100000 (*)
WHERE salary > 100000
WHERE SUM(salary) > 100000
5. The PLAYERS and TEAMS tables contain these columns:
PLAYERS
PLAYER_ID NUMBER NOT NULL, PRIMARY KEY
LAST_NAME VARCHAR2 (30) NOT NULL
FIRST_NAME VARCHAR2 (25) NOT NULL
TEAM_ID NUMBER
POSITION VARCHAR2 (25)
TEAMS

TEAM_ID NUMBER NOT NULL, PRIMARY KEY
TEAM_NAME VARCHAR2 (25)
You need to create a report that lists the names of each team with more than three goal
keepers.
Which SELECT statement will produce the desired result?
Mark for Review
(1) Points
SELECT t.team_name, COUNT(p.player_id)
FROM players p, teams t
ON (p.team_id = t.team_id)
WHERE UPPER(p.position) = 'GOAL KEEPER'
GROUP BY t.team_name
HAVING COUNT(p.player_id) > 3;
SELECT t.team_name, COUNT(p.player_id)
FROM players p
JOIN teams t ON (p.team_id = t.team_id)
WHERE UPPER(p.position) = 'GOAL KEEPER'
GROUP BY t.team_name
HAVING COUNT(p.player_id) > 3;
(*)
SELECT t.team_name, COUNT(p.player_id)
FROM players
JOIN teams t ON (p.team_id = t.team_id)
WHERE UPPER(p.position) = 'GOAL KEEPER'
HAVING COUNT(p.player_id) > 3;
SELECT t.team_name, COUNT(p.player_id)
FROM players p, teams t
ON (p.team_id = t.team_id)
WHERE UPPER(p.position) = 'GOAL KEEPER'
GROUP BY t.team_name;
6. Evaluate this statement:
SELECT department_id, AVG(salary)
FROM employees
WHERE job_id <> 69879
GROUP BY job_id, department_id
HAVING AVG(salary) > 35000
ORDER BY department_id;
Which clauses restricts the result? Choose two.
Mark for Review
(1) Points
(Choose all correct answers)
WHERE job_id <> 69879 (*)
SELECT department_id, AVG(salary)
HAVING AVG(salary) > 35000 (*)
GROUP BY job_id, department_id
7. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY GROUPING SETS((department_id, manager_id), (department_id, job_id))
What data will this query generate?
Mark for Review
(1) Points
Sum of salaries for (department_id, job_id) and (department_id, manager_id) (*)
Sum of salaries for (department_id, job_id, manager_id)
Subtotals for (job_id, manager_id)
The statement will fail.
8. You use GROUPING functions to ______ database rows from tabulated rows.
Mark for Review
(1) Points
COMPUTE
COUNT
DISTINGUISH (*)
CREATE
9. Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY GROUPING SETS(.......)

Select the correct GROUP BY GROUPING SETS clause from the following list:
Mark for Review
(1) Points
GROUP BY GROUPING SETS ((department_id, manager_id), (department_id, job_id),
(manager_id, job_id)) (*)
GROUP BY GROUPING SETS ((department_id, manager_id), (department_id,
SUM(salary), (manager_id, job_id))
GROUP BY GROUPING SETS (department_id, AVG(salary)), (department_id, job_id),
(department_id, manager_id)
GROUP BY GROUPING SETS (department_id, salary), (department_id, job_id),
(department_id, manager_id)
10. CUBE can be applied to all aggregate functions including AVG, SUM, MIN, MAX, and
COUNT. True or False? Mark for Review
(1) Points
True (*)
False
11. GROUPING SETS is another extension to the GROUP BY clause and is used to specify
multiple groupings of data but provide a single result set. True or False? Mark for
Review
(1) Points
True (*)
False
12. If you want to include subtotals and grand totals for all columns mentioned in a
GROUP BY clause, you should use which of the following extensions to the GROUP BY
clause? Mark for Review
(1) Points
HAVING
ROLLUP
CUBE (*)
GROUP BY ALL COLUMNS
13. The ___________ operator returns all rows from both tables, after eliminating
duplicates. Mark for Review
(1) Points
MINUS
UNION ALL
UNION (*)
INTERSECT
14. MINUS will give you rows from the fifirst query that are not present in the second
query. (True or False?) Mark for Review
(1) Points
True (*)
False
15. When using SET operators, the number of columns and the data types of the
columns must be identical in all of the SELECT statements used in the query. True or
False. Mark for Review
(1) Points
True (*)
False

The PAYMENT table contains these columns:
PAYMENT_ID NUMBER(9) PK
PAYMENT_DATE DATE
CUSTOMER_ID NUMBER(9)
Which SELECT statement could you use to display the number of times each customer payment
was made between January 1, 2003 and June 30, 2003 ?
SELECT COUNT(payment_id)
FROM payment
WHERE payment_date BETWEEN '01-Jan-2003' AND '30-Jun-2003';
SELECT customer_id, COUNT(payment_id)
FROM payment
WHERE payment_date BETWEEN '01-Jan-2003' AND '30-Jun-2003'
GROUP BY customer_id;
(*)
SELECT COUNT(payment_id)
FROM payment
WHERE payment_date BETWEEN '01-Jan-2003' AND '30-Jun-2003'
GROUP BY customer_id;
SELECT customer_id, COUNT(payment_id)
FROM payment
WHERE payment_date BETWEEN '01-Jan-2003' AND '30-Jun-2003';


Which of the following are correct SET operators? (choose two)
UNION, MINUS (*)
UNION ALL, INTERSECT (*)
MINUS, PLUS
UNION ALL, PLUS ALL

1-INTERSECT will give you the common rows found in both queries. (True or False?)
True (*)
False
2-Which statement about group functions is true?
Group functions can only be used in a SELECT list.
Group functions ignore null values. (*)
Group functions can be used in a WHERE clause.
A query that includes a group function in the SELECT list must include a GROUP BY clause.
3- When using SET operators, the names of the matching columns must be identical in all of the
SELECT statements used in the query. True or False?
True
False (*)
4- Evaluate this SELECT statement:
SELECT MAX(salary), department_id
FROM employees
GROUP BY department_id;
Which values are displayed?
The highest salary in each department (*)
The employees with the highest salaries
The employee with the highest salary for each department
The highest salary for all employees
5- The EMPLOYEES table contains the following columns:
EMPLOYEE_ID NUMBER(10) PRIMARY KEY
LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
DEPARTMENT VARCHAR2(20)
HIRE_DATE DATE
SALARY NUMBER(10)
You want to create a report that includes each employee's last name, employee identifification
number, date of hire, and salary. The report should include only those employees who have been
with the company for more than one year and whose salary exceeds $40,000.
Which of the following SELECT statements will accomplish this task?
SELECT employee_id, last_name, hire_date, salary
FROM employees
WHERE salary > 40000
AND (sysdate-hire_date) / 365 > 1;
(*)
SELECT employee_id, last_name, salary
FROM employees
WHERE salary > 40000
AND hire_date IN (sysdate-hire_date) / 365 > 1);
SELECT employee_id, last_name, salary
FROM employees
WHERE salary > 40000
AND hire_date =
(SELECT hire_date
FROM employees
WHERE (sysdate-hire_date) / 365 > 1);
SELECT employee_id, last_name, hire_date, salary
FROM employees
WHERE salary > 40000 AND hire_date =
(SELECT hire_date
FROM employees
WHERE (sysdate-hire_date) / 365 > 1);

1- Is the following statement correct?
SELECT department_id, AVG(salary)
FROM employees;
No, because the AVG function cannot be used on the salary column
No, because a GROUP BY department_id clause is needed (*)
Yes, because the SELECT clause can contain both individual columns and group functions
Yes
2- Examine the following statement:
SELECT department_id, manager_id, job_id, SUM(salary)
FROM employees
GROUP BY ROLLUP(department_id, manager_id)
What extra data will this query generate?
Subtotals for department_id, and grand totals for salary
Subtotals for department_id, job_id and grand totals for salary
Subtotals for department_id, job_id, manager_id and grand totals for salary
The statement will fail. (*)