0% found this document useful (0 votes)
251 views37 pages

Quiz 4,5,67

This document covers SQL functions and conditional expressions. It contains multiple choice questions about functions like ROUND, TRUNC, CONCAT and CASE/DECODE expressions. Date functions like ADD_MONTHS and character functions like LENGTH, SUBSTR are also assessed.

Uploaded by

Fadli Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
251 views37 pages

Quiz 4,5,67

This document covers SQL functions and conditional expressions. It contains multiple choice questions about functions like ROUND, TRUNC, CONCAT and CASE/DECODE expressions. Date functions like ADD_MONTHS and character functions like LENGTH, SUBSTR are also assessed.

Uploaded by

Fadli Rahman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Section 4

(Answer all questions in this section)


1. Which functions can be used to manipulate character, number, and date column
values?
ROUND, TRUNC, and MOD
ROUND, TRUNC, and ADD_MONTHS
CONCAT, RPAD, and TRIM (*)
UPPER, LOWER, and INITCAP
Correct
(1/1) Points
2. 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?

SELECT INSTR(category, 2,2)


FROM styles
WHERE style_id = 895840;
SELECT SUBSTR(category, -2,2)
FROM styles
WHERE style_id = 758960; (*)
SELECT INSTR(category, -2,2)
FROM styles
WHERE style_id = 895840;
SELECT SUBSTR(category, 2,2)
FROM styles
WHERE style_id = 895840;
Correct
(1/1) Points
3. Which character manipulation function always returns a numerical value?
SUBSTR
LENGTH (*)
TRIM
LPAD
Correct
(1/1) Points
4. Evaluate this SELECT statement:
SELECT LENGTH(email)
FROM employee;

What will this SELECT statement display?

The longest e-mail address in the EMPLOYEE table


The email address of each employee in the EMPLOYEE table
The maximum number of characters allowed in the EMAIL column
The number of characters for each value in the EMAIL column in the employees
table (*)
Correct
(1/1) Points
5. Which three statements about functions are true? (Choose three.)
(Choose all correct answers)
The SUBSTR character function returns a portion of a string beginning at a defined
character position to a specified length. (*)
The SYSDATE function returns the Oracle Server date and time. (*)
The CONCAT function can only be used on character strings, not on numbers.
The ROUND number function rounds a value to a specified decimal place or the
nearest whole number. (*)
Correct
6. Which of the following Date Functions will add calendar months to a date?
ADD_MONTHS (*)
NEXT_MONTH
MONTHS + Date
Months + Calendar (Month)
Correct
(1/1) Points
7. Which SELECT statement will NOT return a date value?
SELECT (30 + hire_date) + 1440/24
FROM employees;
SELECT (SYSDATE - hire_date) + 10*8
FROM employees; (*)
SELECT SYSDATE - TO_DATE('25-Jun-2002') + hire_date
FROM employees;
SELECT (hire_date - SYSDATE) + TO_DATE('25-Jun-2002')
FROM employees;
Correct
(1/1) Points
8. What is the result of the following query?
SELECT ADD_MONTHS ('11-Jan-1994',6)
FROM dual;
11-Jul-1994 (*)
17-Jul-1994
11-Jan-1995
17-Jan-1994
Correct
(1/1) Points
9. You want to create a report that displays all orders and their amounts that were
placed during the month of January. You want the orders with the highest amounts
to appear first. Which query should you issue?
SELECT orderid, total
FROM orders
WHERE order_date LIKE '01-Jan-2002' AND '31-Jan-2002'
ORDER BY total DESC;
SELECT orderid, total
FROM orders
WHERE order_date BETWEEN '01-Jan-2002' AND '31-Jan-2002'
ORDER BY total DESC; (*)
SELECT orderid, total
FROM orders
WHERE order_date IN ( 01-Jan-2002 , 31-Jan-2002 )
ORDER BY total;
SELECT orderid, total
FROM orders
WHERE order_date BETWEEN '31-Jan-2002' AND '01-Jan-2002'
ORDER BY total DESC;
Correct
(1/1) Points
10. What function would you use to return the highest date in a month?
FINAL_DAY
LAST_DAY (*)
HIGHEST_DAY
END_DAY
Correct
11. What is the result of the following SQL Statement:
SELECT ROUND(45.923,-1)
FROM DUAL;
46
45.9
50 (*)
None of the above
Correct
(1/1) Points
12. Which script displays '01-May-2004' when the HIRE_DATE value is '20-May-
2004'?
SELECT TRUNC(hire_date, 'MI')
FROM employees;
SELECT ROUND(hire_date, 'MONTH')
FROM employees;
SELECT ROUND(hire_date, 'MON')
FROM employees;
SELECT TRUNC(hire_date, 'MONTH')
FROM employees; (*)
Correct
(1/1) Points
13. ROUND and TRUNC functions can be used with which of the following
Datatypes?
Dates and numbers (*)
Dates and characters
Numbers and characters
None of the above
Correct
(1/1) Points
14. Which comparison operator retrieves a list of values?
LIKE
IN (*)
IS NULL
BETWEEN IN
Correct
(1/1) Points
15. Which number function may be used to determine if a value is odd or even?
BINARY
TRUNC
ROUND
MOD (*)
Correct
Section 5
(Answer all questions in this section)
1. Which of the following is a conditional expression used in SQL?
WHERE
CASE (*)
DESCRIBE
NULLIF
Correct
(1/1) Points
2. 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 (*)
False
Correct
(1/1) Points
3. 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

Invalid statement.
King, A N Other
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other (*)
King, A N Other
Kochhar, King
De Haan, King
Hunold, Kochhar
Ernst, De Haan
King, Null
Kochhar, King
De Haan, King
Hunold, A N Other
Ernst, A N Other
Correct
(1/1) Points
4. If quantity is a number datatype, what is the result of this statement?
SELECT NVL(200/quantity, 'zero') FROM inventory;
ZERO
zero
The statement fails (*)
Null
Correct
(1/1) Points
5. You need to replace null values in the DEPT_ID column with the text N/A. Which
functions should you use?
TO_CHAR and NULLIF
TO_NUMBER and NULLIF
TO_CHAR and NVL (*)
TO_CHAR and NULL
Correct
6. Which statement about group functions is true?
NVL and NVL2, but not COALESCE, can be used with group functions to replace null
values.
NVL and COALESCE, but not NVL2, can be used with group functions to replace null
values.
NVL, NVL2, and COALESCE can be used with group functions to replace null
values. (*)
COALESCE, but not NVL and NVL2, can be used with group functions to replace null
values.
Correct
(1/1) Points
7. Which of the following General Functions will return the first non-null expression
in the expression list?
NVL2
NULLIF
NVL
COALESCE (*)
Correct
(1/1) Points
8. When executed, which statement displays a zero if the TUITION_BALANCE value
is zero and the HOUSING_BALANCE value is null?
SELECT NVL (tuition_balance + housing_balance, 0) "Balance Due"
FROM student_accounts; (*)
SELECT NVL(tuition_balance, 0), NVL (housing_balance), tuition_balance +
housing_balance "Balance Due"
FROM student_accounts;
SELECT TO_NUMBER(tuition_balance, 0), TO_NUMBER (housing_balance, 0),
tutition_balance + housing_balance "Balance Due"
FROM student_accounts;
SELECT tuition_balance + housing_balance
FROM student_accounts;
Correct
(1/1) Points
9. The PRODUCT table contains this column: PRICE NUMBER(7,2)
Evaluate this statement:
SELECT NVL(10 / price, '0')
FROM PRODUCT;

What would happen if the PRICE column contains null values?

A value of 0 would be displayed. (*)


The statement would fail because values cannot be divided by null.
The statement would fail because values cannot be divided by 0.
A value of 10 would be displayed.
Correct
(1/1) Points
10. You have been asked to create a report that lists all customers who have placed
orders of at least $2,500. The report's date should be displayed using this format:
Day, Date Month, Year (For example, Tuesday, 13 April, 2004 ).
Which statement should you issue?
SELECT companyname, TO_CHAR (sysdate, 'fmdd, dy month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_DATE (date, 'day, dd month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_DATE (sysdate, 'dd, dy month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500;
SELECT companyname, TO_CHAR (sysdate, 'fmDay, dd Month, yyyy'), total
FROM customers NATURAL JOIN orders
WHERE total >= 2500; (*)
Correct
11. Which statement will return the salary (for example, the salary of 6000) from the
Employees table in the following format? $6000.00
SELECT TO_CHAR(salary, '99999.00') SALARY
FROM employees

SELECT TO_CHAR(salary, '$99999') SALARY


FROM employees

SELECT TO_CHAR(sal, '$99999.00') SALARY


FROM employees

SELECT TO_CHAR(salary, '$99999.00') SALARY


FROM employees
(*)
Correct
(1/1) Points
12. A table has the following definition: EMPLOYEES(
EMPLOYEE_ID NUMBER(6) NOT NULL,
NAME VARCHAR2(20) 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;
No.ᅠ You will have to re-wirte the statement and perform explicit datatype
conversion.
Yes, Oracle will perform implicit datatype conversion, but the WHERE clause will not
find any matching data. (*)
No, because the datatypes of EMPLOYEE_ID and MANAGER_ID are different.
Yes, Oracle will perform implicit dataype conversion, and the query will return one
row of data.
Correct
(1/1) Points
13. The following script will run successfully. True or False?
SELECT TO_CHAR(TO_DATE('25-Dec-2004','dd-Mon-yyyy'))
FROM dual
True (*)
False
Correct
(1/1) Points
14. If you use the RR format when writing a query using the date 27-Oct-17 and the
year is 2001, what year would be the result?
2017 (*)
1917
2001
1901
Correct
(1/1) Points
15. The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2 (25)
FIRST_NAME VARCHAR2 (25)
HIRE_DATE DATE

You need to display HIRE_DATE values in this format:


January 28, 2000

Which SQL statement could you use?

SELECT TO_CHAR(hire_date, 'Month DD, YYYY')


FROM employees; (*)
SELECT TO_CHAR(hire_date, Month DD, YYYY)
FROM employees;
SELECT hire_date(TO_CHAR 'Month DD', ' YYYY')
FROM employees;
SELECT TO_CHAR(hire_date, 'Month DD', ' YYYY')
FROM employees;
Correct
Section 6
(Answer all questions in this section)
1. Which of the following statements is the simplest description of a nonequijoin?
A join that joins a table to itself
A join condition containing something other than an equality operator (*)
A join condition that includes the (+) on the left hand side
A join condition that is not equal to other joins
Correct
(1/1) Points
2. The keywords JOIN _____________ should be used to join tables with the same
column names but different datatypes.
USING (*)
OVER
NATURAL ON
WHEN
Correct
(1/1) Points
3. The following is a valid SQL statement.
SELECT employees.employee_id, employees.last_name, departments.location_id,
department_id
FROM employees JOIN departments
USING (department_id) ;

True or False?

True (*)
False
Correct
(1/1) Points
4. What types of joins will return the unmatched values from both tables in the join?
Left outer joins
Right outer joins
Natural joins
Full outer joins (*)
Correct
(1/1) Points
5. For which of the following tables will all the values be retrieved even if there is no
match in the other?
SELECT employees.last_name, employees.department_id,
departments.department_name
FROM employees
LEFT OUTER JOIN departments
ON (employees.department_id = departments.department_id);

employees (*)
Both
department
Neither. The LEFT OUTER JOIN limits the value to the matching department ids.
Correct
6. Which type of join returns rows from one table that have NO direct match in the
other table?
Outer join (*)
Equijoin
Natural join
Self join
Correct
(1/1) Points
7. If you select rows from two tables (employees and departments) using the outer
join specified in the example, what will you get?
SELECT employees.last_name, employees.department_id,
departments.department_name
FROM employees
LEFT OUTER JOIN departments
ON (employees.department_id = departments.department_id);

All employees that do not have a department_id assigned to them


All employees including those that do not have a departement_id assigned to
them (*)
No employees as the statement will fail
None of the above
Correct
(1/1) Points
8. The join column must be included in the select statement when you use the
NATURAL JOIN clause. True or False?
True
False (*)
Correct
(1/1) Points
9. Which statement about a natural join is true?
Columns with the same names must have the same datatype. (*)
Columns with the same names must not have identical data types.
Columns with the same names must have compatible data types.
Columns with the same names cannot be included in the SELECT list of the query.
Correct
(1/1) Points
10. You need to join all the rows in the EMPLOYEES table to all the rows in the
EMP_REFERENCE table. Which type of join should you create?
A cross join (*)
An equijoin
A full outer join
An inner join
Correct
(1/1) Points
Previous

11. Which of the following database design concepts is implemented with a self
join?
Arc
Supertype
Non-Transferability
Recursive Relationship (*)
Correct
(1/1) Points
12. Evaluate this SELECT statement:
SELECT *
FROM employee worker JOIN employee manager
ON worker.mgr_id = manager.emp_id;
Which type of join is created by this SELECT statement?

a self join (*)


a left outer join
a cross join
a full outer join
Correct
(1/1) Points
13. Which select statement will return the last name and hire date of an employee
and his/ her manager for employees that started in the company before their
managers?
SELECT worker.last_name, worker.hire_date, manager.last_name,
manager.hire_date
FROM employees worker JOIN employees manager
ON worker.manager_id = manager.employee_id
WHERE worker.hire_date > manager.hire_date
SELECT worker.last_name, worker.hire_date, manager.last_name,
manager.hire_date
FROM employees worker JOIN employees manager
ON worker.manager_id = manager.employee_id
WHERE worker.hire_date < manager.hire_date (*)
SELECT worker.last_name, worker.hire_date, manager.last_name,
manager.hire_date
FROM employees worker JOIN employees worker
ON worker.manager_id = worker.employee_id
WHERE worker.hire_date < worker.hire_date
SELECT worker.last_name, worker.hire_date, manager.last_name,
manager.hire_date
FROM employees worker JOIN employees manager
ON worker.manager_id != manager.employee_id
WHERE worker.hire_date < manager.hire_date
Correct
(1/1) Points
14. Which of the following database design concepts do you need in your tables to
write Hierarchical queries?
Arc
Recursive Relationship (*)
Supertype
Non-Transferability
Correct
(1/1) Points
15. Which statement about a self join is true?
Table aliases cannot be used to qualify table names.
Table aliases must be used to qualify table names. (*)
A self join must be implemented by defining a view.
The NATURAL JOIN clause must be used.
Correct
(1/1) Points
Previous
Section 7
(Answer all questions in this section)

1. Using Oracle Proprietary join syntax, which operator would you use after one of the
column names in the WHERE clause when creating an outer join?

(+) (*)

Correct

(1/1) Points

2. Which symbol is used to perform an outer join?

(+) (*)

||

Correct

(1/1) Points

3. The following statement is an example of a nonequi-join?

SELECT e.last_name, e.salary, j.grade_level


FROM employees e, job_grades j
WHERE e.salary
BETWEEN j.lowest_sal AND j.highest_sal;

True or False?

True (*)

False

Correct

(1/1) Points
4. Evaluate this SELECT statement:

SELECT p.player_id, m.last_name, m.first_name, t.team_name


FROM player p
LEFT OUTER JOIN player m ON (p.manager_id = m.player_id)
LEFT OUTER JOIN team t ON (p.team_id = t.team_id);

Which join is evaluated first?

The join between the player table and the team table on TEAM_ID

The join between the player table and the team table on MANAGER_ID

The self-join of the player table (*)

The join between the player table and the team table on PLAYER_ID

Correct

(1/1) Points

5. You need to join the EMPLOYEES table and the SCHEDULES table, but the two tables do
not have any corresponding columns. Which type of join will you create?

A non-equijoin (*)

It is not possible to join these two tables.

An equijoin

A full outer join

Correct

(1/1) Points

Page 1 of 3 Next

6. The EMPLOYEE_ID column in the EMPLOYEES table corresponds to the


EMPLOYEE_ID column of the ORDERS table.
The EMPLOYEE_ID column in the ORDERS table contains null values for rows that
you need to display.
Which type of join should you use to display the data?
Equijoin
Natural join
Outer join (*)
Self-join
Correct
(1/1) Points
7. Which of the following best describes the function of an outer join?
An outer join will return all rows that meet the join criteria and will return NULL
values from one table if no rows from the other table satisfy the join criteria. (*)
An outer join will return only those rows that do not meet the join criteria.
An outer join will return data only if both tables contain an identical pair of
columns.
An outer join will return only data from the far left column in one table and the far
right column in the other table.
Correct
(1/1) Points
8. Will the following statement work?
SELECT department_name, last_name
FROM employees, departments
WHERE department_id = department_id;

Yes, Oracle will resolve which department_id colum comes from which table.
Yes, there are no syntax errors in that statement
No, Oracle will return a Column Ambiguously Defined error. (*)
No, Oracle will not allow joins in the WHERE clause
Correct
(1/1) Points
9. What is the result of a query that selects from two tables but includes no join
condition?
A Cartesian product (*)
A selection of matched rows from both tables
A selection of rows from the first table only
A syntax error
Correct
(1/1) Points
10. Which statement about the join syntax of an Oracle Proprietary join syntax
SELECT statement is true?
The ON keyword must be included.
The WHERE clause represents the join criteria. (*)
The JOIN keyword must be included.
The FROM clause represents the join criteria.
Incorrect. Refer to Section 7 Lesson 1.
11. If table A has 10 rows and table B has 5 rows, how many rows will be returned if
you perform a equi-join on those two tables?
10
5
50
It depends on how many rows have matching data in each of the two tables. (*)
Incorrect. Refer to Section 7 Lesson 1.
(0/1) Points
12. Evaluate this SQL statement:
SELECT e.employee_id, e.last_name, e.first_name, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id AND employees.department_id > 5000
ORDER BY 4;

Which clause contains a syntax error?

ORDER BY 4;
WHERE e.department_id = d.department_id
SELECT e.employee_id, e.last_name, e.first_name, d.department_name
AND employees.department_id > 5000 (*)
FROM employees e, departments d
Correct
(1/1) Points
13. You have two tables named EMPLOYEES and SALES. You want to identify the
sales representatives who have generated at least $100,000 in revenue.
Which query should you issue?
SELECT e.first_name, e.last_name, s.sales
FROM employees e, sales s
WHERE e.employee_id = s.employee_id AND revenue >= 100000; (*)
SELECT e.first_name, e.last_name, s.sales
FROM employees e, sales s
WHERE e.employee_id = s.employee_id AND revenue > 100000;
SELECT e.first_name, e.last_name, s.sales
FROM employees, sales
WHERE e.employee_id = s.employee_id AND revenue >= 100000;
SELECT first_name, last_name, sales
FROM employees e, sales s
WHERE e.employee_id = s.employee_id AND revenue > 100000;
Correct
(1/1) Points
14. You have the following EMPLOYEES table:
EMPLOYEE_ID NUMBER(5) NOT NULL PRIMARY KEY
FIRST_NAME VARCHAR2(25)
LAST_NAME VARCHAR2(25)
ADDRESS VARCHAR2(35)
CITY VARCHAR2(25)
STATE VARCHAR2(2)
ZIP NUMBER(9)
TELEPHONE NUMBER(10)
DEPARTMENT_ID NUMBER(5) NOT NULL FOREIGN KEY

The BONUS table includes the following columns:

BONUS_ID NUMBER(5) NOT NULL PRIMARY KEY


ANNUAL_SALARY NUMBER(10)
BONUS_PCT NUMBER(3, 2)
EMPLOYEE_ID VARCHAR2(5) NOT NULL FOREIGN KEY

You want to determine the amount of each employee's bonus as a calculation of


salary times bonus. Which of the following queries should you issue?

SELECT e.first_name, e.last_name, b.annual_salary, b. bonus_pct


FROM employees e, bonus b
WHERE e.employee_id = b.employee_id;
SELECT e.first_name, e.last_name, b.annual_salary, b. bonus_pct
FROM employees, bonus
WHERE e.employee_id = b.employee_id;
SELECT e.first_name, e.last_name, b.annual_salary * b. bonus_pct
FROM employees e, bonus b
WHERE e.employee_id = b.employee_id; (*)
SELECT first_name, last_name, annual_salary * bonus_pct
FROM employees, bonus NATURAL JOIN;
Correct
(1/1) Points
15. The PATIENTS and DOCTORS tables contain these columns:
PATIENTS
PATIENT_ID NUMBER(9)
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)

DOCTORS
DOCTOR_ID NUMBER(9)
LAST_NAME VARCHAR2 (20)
FIRST_NAME VARCHAR2 (20)

You issue this statement:


SELECT patient_id, doctor_id
FROM patients, doctors;

Which result will this statement provide?

A report containing each patient's id value and his doctor's id value


A report containing all possible combinations of the PATIENT_ID and DOCTOR_ID
values (*)
A report with NO duplicate PATIENT_ID or DOCTOR_ID values
A syntax error
Correct
Section 8
(Answer all questions in this section)
1. The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
SALARY NUMBER(7,2)
DEPARTMENT_ID NUMBER(9)

You need to display the number of employees whose salary is greater than
$50,000? Which SELECT would you use?

SELECT COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY employee_id, last_name, first_name, salary, department_id;
SELECT COUNT(*)
FROM employees
WHERE salary > 50000; (*)
SELECT * FROM employees
WHERE salary > 50000;
SELECT COUNT(*)
FROM employees
WHERE salary < 50000;
SELECT * FROM employees
WHERE salary < 50000;
Correct
(1/1) Points
2. Given the following data in the employees table (employee_id, salary,
commission_pct)
DATA: (143, 2600, null
144, 2500, null
149, 10500, .2
174, 11000, .3
176, 8600, .2
178, 7000, .15)

What is the result of the following statement:


SELECT SUM(commission_pct), COUNT(commission_pct)
FROM employees
WHERE employee_id IN( 143,144,149,174,176,178);

SUM = 1.85 and COUNT = 6


SUM = 1.85 and COUNT = 4
SUM = .85 and COUNT = 4 (*)
SUM = .85 and COUNT = 6
Incorrect. Refer to Section 8 Lesson 2.
(0/1) Points
3. What would the following SQL statement return?
SELECT COUNT(first_name)
FROM employees;

The total number of rows in the employees table


The total number of non-null first names in the employees table (*)
A listing of all non-null first names in the employees table
A listing of all unique first names in the employees table
Correct
(1/1) Points
4. Evaluate this SQL statement:
SELECT COUNT (amount)
FROM inventory;

What will occur when the statement is issued?

The statement will count the number of rows in the INVENTORY table where the
AMOUNT column is not null. (*)
The statement will replace all NULL values that exist in the AMOUNT column.
The statement will return the greatest value in the INVENTORY table.
The statement will return the total number of rows in the AMOUNT column.
Correct
(1/1) Points
5. Which SELECT statement will calculate the number of rows in the PRODUCTS
table?
SELECT ROWCOUNT FROM products;
SELECT COUNT (*) FROM products; (*)
SELECT COUNT(products);
SELECT COUNT FROM products;
Correct
Section 8
(Answer all questions in this section)
6. Which statement about the COUNT function is true?
The COUNT function always ignores null values by default. (*)
The COUNT function ignores duplicates by default.
The COUNT function can be used to find the maximum value in each column.
The COUNT function can be used to determine the number of unique, non-null
values in a column.
Correct
(1/1) Points
7. Examine the data from the LINE_ITEM table:
LINE_ITEM_ID ORDER_ID PRODUCT_ID PRICE DISCOUNT
890898 847589 848399 8.99 0.10
768385 862459 849869 5.60 0.05
867950 985490 945809 5.60
954039 439203 438925 5.25 0.15
543949 349302 453235 4.50
You query the LINE_ITEM table and a value of 5 is returned. Which SQL statement
did you execute?

SELECT SUM(discount)
FROM line_item;
SELECT AVG(discount)
FROM line_item;
SELECT COUNT(discount)
FROM line_item;
SELECT COUNT(*)
FROM line_item; (*)
Correct
(1/1) Points
8. Given the following data in the employees table (employee_id, salary,
commission_pct)
DATA: (143, 2600, null
144, 2500, null
149, 10500, .2
174, 11000, .3
176, 8600, .2
178, 7000, .15)

What is the result of the following statement:

SELECT AVG(commission_pct)
FROM employees
WHERE employee_id IN( 143,144,149,174,176,178);

0.2125 (*)
0.0425
1.2125
This statement is invalid
Correct
(1/1) Points
9. The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
SALARY NUMBER(9,2)
HIRE_DATE DATE
BONUS NUMBER(7,2)
COMM_PCT NUMBER(4,2)

Which three functions could be used with the HIRE_DATE, LAST_NAME, or SALARY
columns? (Choose three.)

(Choose all correct answers)


COUNT (*)
MAX (*)
SUM
MIN (*)
AVG
Correct
(1/1) Points
10. Group functions return a value for ________________ and ________________ null
values in their computations.
each row, ignore
a row set, ignore (*)
each row, include
a row set, include
Correct
11. Which group functions below act on character, number, and date data types?
(Choose three)
(Choose all correct answers)
MAX (*)
SUM
MIN (*)
AVG
COUNT (*)
Correct
(1/1) Points
12. You can use GROUP functions in all clauses of a SELECT statement. True or
False?
True
False (*)
Correct
(1/1) Points
13. Given the following data in the employees table (employee_id, salary,
commission_pct)
DATA: (143, 2600, null
144, 2500, null
149, 10500, .2
174, 11000, .3
176, 8600, .2
178, 7000, .15)

What is the result of the following statement:

SELECT SUM(commission_pct), COUNT(salary)


FROM employees
WHERE employee_id IN( 143,144,149,174,176,178);

SUM = .85 and COUNT = 6 (*)


SUM = 1.85 and COUNT = 6
SUM = .85 and COUNT = 4
SUM = 1.85 and COUNT =4
Correct
(1/1) Points
14. You need to calculate the average salary of employees in each department.
Which group function will you use?
MEDIAN
MEAN
AVERAGE
AVG (*)
Correct
(1/1) Points
15. Which group function would you use to display the highest salary value in the
EMPLOYEES table?
MIN
COUNT
MAX (*)
AVG
Correct
Section 9
(Answer all questions in this section)
1. Evaluate this SELECT statement:
SELECT COUNT(emp_id), mgr_id, dept_id
FROM employees
WHERE status = 'I'
GROUP BY dept_id
HAVING salary > 30000
ORDER BY 2;

Why does this statement return a syntax error?

A single query cannot contain a WHERE clause and a HAVING clause.


MGR_ID must be included in the GROUP BY clause. (*)
The ORDER BY clause must specify a column name in the EMPLOYEE table.
The HAVING clause must specify an aggregate function.
Correct
(1/1) Points
2. 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?

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;
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
HAVING COUNT(p.player_id) > 3;
Correct
(1/1) Points
3. 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;

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.
Correct
(1/1) Points
4. Is the following statement correct?
SELECT department_id, AVG(salary)
FROM employees;

No, because a GROUP BY department_id clause is needed (*)


Yes, because the SELECT clause can contain both individual columns and group
functions
Yes
No, because the AVG function cannot be used on the salary column
Correct
(1/1) Points
5. What will the following SQL Statement do?
SELECT job_id, COUNT(*)
FROM employees
GROUP BY job_id;

Displays only the number of job_ids


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 all the employees and groups them by job
Correct
Section 10
(Answer all questions in this section)
1. Subqueries can only be placed in the WHERE clause. True or False?
True
False (*)
Correct
(1/1) Points
2. Which of the following statements is a true guideline for using subqueries?
The outer and inner queries can reference more than one table. They can get data
from different tables. (*)
Only one WHERE clause can be used for a SELECT statement, and if specified, it
must be the outer query.
Place the subquery on the left side of the comparison condition.
Do not enclose the subquery in parentheses.
Correct
(1/1) Points
3. What will the following statement return:
SELECT last_name, salary
FROM employees
WHERE (department_id, job_id) = (SELECT department_id, job_id
FROM employees
WHERE employee_id = 103)

A list of last_names and salaries of employees that works in the same department
and has the same job_id as that of employee 103. (*)
A list of last_names or salaries of employees that works in the same department
and has the same job_id as that of employee 103.
A list of last_names and salaries of employees that works in the same department
or has the same job_id as that of employee 103.
Nothing. It is an invalid statement.
Correct
(1/1) Points
4. Which best describes a single-row subquery?
A query that returns only one row from the inner SELECT statement (*)
A query that returns one or more rows from the inner SELECT statement
A query that returns only one column value from the inner SELECT statement
A query that returns one or more column values from the inner SELECT statement
Correct
(1/1) Points
5. If the subquery returns no rows, will the outer query return any values?
No, because the subquery will be treated like a null value. (*)
Yes. It will just run and ignore the subquery.
Yes, Oracle will find the nearest value and rewrite your statement implicitly when
you run it.
No, because you are not allowed to return empty values from a subquery.
Correct
6. Which statement about the <> operator is true?
The <> operator returns the same result as the ANY operator in a subquery.
The <> operator is NOT a valid SQL operator.
The <> operator can be used when a single-row subquery returns only one row. (*)
The <> operator CANNOT be used in a single-row subquery.
Correct
(1/1) Points
7. In a subquery, the ALL operator compares a value to every value returned by the
inner query. True or False?
True (*)
False
Correct
(1/1) Points
8. 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?

Remove the quotes surrounding the date value in the OR clause.


Change the outer query WHERE clause to 'WHERE payment_id IN'. (*)
Change the comparison operator to a single-row operator.
Remove the parentheses surrounding the nested SELECT statement.
Correct
(1/1) Points
9. Group functions can be used in multiple-row subqueries in the HAVING and
GROUP BY clauses. True or False?
True (*)
False
Correct
(1/1) Points
10. 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');

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 (*)
The department ID, last name, and department name for every Executive in the
employees table
The department ID, department name, and last name for every employee in the
Executive department
Correct
11. What is wrong with the following query?
SELECT employee_id, last_name
FROM employees
WHERE salary =
(SELECT MIN(salary) FROM employees GROUP BY department_id);
Nothing, it will run without problems.
Subquery returns more than one row and single row comparison operator is
used. (*)
Single rows contain multiple values and a logical operator is used.
Subquery references the wrong table in the WHERE clause.
Correct
(1/1) Points
12. 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?

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);
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)); (*)
Correct
(1/1) Points
13. Which answer is INCORRECT? The parent statement of a correlated subquery
can be:
A SELECT statement
An INSERT statement (*)
An UPDATE statement
A DELETE statement
Correct
(1/1) Points
14. The Oracle server performs a correlated subquery when the subquery
references a column from a table referred to in the parent. True or False?
True (*)
False
Correct
(1/1) Points
15. The WITH clause enables a SELECT statement to define 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?
True (*)
False
Correct

You might also like