Midterm Exam Database Programming With SQL
Midterm Exam Database Programming With SQL
Section 1
(Answer all questions in this section)
1. The SELECT statement retrieves information from the database. In a SELECT statement, you
can do all of the following EXCEPT: Mark for Review
(1) Points
Joining
Selection
Projection
Manipulation (*)
2. In the default order of precedence, which operator would be evaluated first? Mark for Review
(1) Points
Multiplications and Divisions are at the same level and would be evaluated first based on left to
right order (*)
Subtractions and Additions are at the same level and would be evaluated first based on left to
right order
Divisions and Subtractions are at the same level and would be evaluated first based on left to
right order
Additions and Multiplications are at the same level and would be evaluated first based on left to
right order
3. You cannot use computers unless you completely understand exactly how they work. True or
False? Mark for Review
(1) Points
True
False (*)
4. There is only one kind of software used by all computers. True or False? Mark for
Review
(1) Points
True
False (*)
5. Databases are used in most countries and by most governments. Life, as we know it, would
change drastically if we no longer had access to databases. True or False? Mark for Review
(1) Points
True (*)
False
Section 2
(Answer all questions in this section)
6. The EMPLOYEES table includes these columns:
EMPLOYEE_ID NUMBER(4) NOT NULL
LAST_NAME VARCHAR2(15) NOT NULL
FIRST_NAME VARCHAR2(10) NOT NULL
HIRE_DATE DATE NOT NULL
You want to produce a report that provides the last names, first names, and hire dates of those
employees who were hired between March 1, 2000, and August 30, 2000. Which statements can you
issue to accomplish this task?
7. When using the "LIKE" operator, the % and _ symbols can be used to do a pattern-matching,
wild card search. True or False? Mark for Review
(1) Points
True (*)
False
8. Which SELECT statement will display both unique and non-unique combinations of the
MANAGER_ID and DEPARTMENT_ID values from the EMPLOYEES table? Mark for Review
(1) Points
SELECT manager_id, department_id FROM employees; (*)
SELECT manager_id, DISTINCT department_id FROM employees;
SELECT manager_id, department_id DISTINCT FROM employees;
SELECT DISTINCT manager_id, department_id FROM employees;
9. You want to retrieve a list of customers whose last names begin with the letters 'Fr' . Which
keyword should you include in the WHERE clause of your SELECT statement to achieve the desired
result? Mark for Review
(1) Points
BETWEEN
AND
IN
LIKE (*)
10. Which of the following elements cannot be included in a WHERE clause? Mark for
Review
(1) Points
A constant
A column name
A column alias (*)
A comparison condition
Section 2
(Answer all questions in this section)
11. You need to display employees with salaries that are at least 30000 or higher. Which
comparison operator should you use? Mark for Review
(1) Points
"=>"
>
!=
>= (*)
Section 3
(Answer all questions in this section)
12. What value will the following SQL statement return?
SELECT employee_id
FROM employees
WHERE employee_id BETWEEN 100 AND 150
OR employee_id IN(119, 175, 205)
AND (employee_id BETWEEN 150 AND 200);
Mark for Review
(1) Points
200, 201, 202, 203, 204, 205, 206
100, 101, 102, 103, 104, 107, 124, 141, 142, 143, 144, 149 (*)
19
No rows will be returned
13. Which SELECT statement should you use to limit the display of product information to those
products with a price of less than 50? Mark for Review
(1) Points
14. Which clause would you include in a SELECT statement to sort the rows returned by the
LAST_NAME column? Mark for Review
(1) Points
ORDER BY (*)
WHERE
HAVING
FROM
Yes, it will return the highest salary, the lowest salary, and the average salary from all
employees. (*)
No, it is illegal. You cannot use more than one multi-row function in a SELECT statement.
Section 4
(Answer all questions in this section)
16. ROUND and TRUNC functions can be used with which of the following Datatypes? Mark
for Review
(1) Points
Dates and numbers (*)
Dates and characters
Numbers and characters
None of the above
17. 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? Mark for Review
(1) Points
SELECT LENGTH(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;
SELECT SUBSTR(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;
(*)
Section 5
(Answer all questions in this section)
20. CASE and DECODE evaluate expressions in a similar way to IF-THEN-ELSE logic. However,
DECODE is specific to Oracle syntax. True or False? Mark for Review
(1) Points
True (*)
False
Section 5
(Answer all questions in this section)
21. When executed, which statement displays a zero if the TUITION_BALANCE value is zero and
the HOUSING_BALANCE value is null? Mark for Review
(1) Points
22. You need to replace null values in the DEPT_ID column with the text N/A. Which functions
should you use? Mark for Review
(1) Points
TO_CHAR and NULLIF
TO_NUMBER and NULLIF
TO_CHAR and NVL (*)
TO_CHAR and NULL
23. 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? Mark for Review
(1) Points
1917
1901
2017 (*)
2001
25. Which best describes the TO_CHAR function? Mark for Review
(1) Points
The TO_CHAR function can be used to remove text from column data that will be returned by
the database.
The TO_CHAR function can be used to display dates and numbers according to formatting
conventions that are supported by Oracle. (*)
The TO_CHAR function can be used to specify meaningful column names in an SQL
statement's result set.
Section 6
(Answer all questions in this section)
26. Which SELECT statement implements a self join? Mark for Review
(1) Points
27. Hierarchical queries MUST use the LEVEL pseudo column. True or False? Mark for
Review
(1) Points
True
False (*)
28. Below find the structures of the PRODUCTS and VENDORS tables:
PRODUCTS
PRODUCT_ID NUMBER
PRODUCT_NAME VARCHAR2 (25)
VENDOR_ID NUMBER
CATEGORY_ID NUMBER
VENDORS
VENDOR_ID NUMBER
VENDOR_NAME VARCHAR2 (25)
ADDRESS VARCHAR2 (30)
CITY VARCHAR2 (25)
REGION VARCHAR2 (10)
POSTAL_CODE VARCHAR2 (11)
You want to create a query that will return an alphabetical list of products, including the product name and
associated vendor name, for all products that have a vendor assigned.
Which two queries could you use?
29. 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? Mark for Review
(1) Points
A cross join (*)
An inner join
An equijoin
A full outer join
30. Which of the following conditions will cause an error on a NATURAL JOIN? Mark for
Review
(1) Points
If it selects rows from the two tables that have equal values in all matched columns.
When you attempt to write it as an equijoin.
If the columns having the same names have different data types, then an error is returned. (*)
When the NATURAL JOIN clause is based on all columns in the two tables that have the same
name.
Section 6
(Answer all questions in this section)
31. What is another name for a simple join or an inner join? Mark for Review
(1) Points
Equijoin (*)
Outer Join
Self Join
Nonequijoin
Section 7
(Answer all questions in this section)
34. When joining 3 tables in a SELECT statement, how many join conditions are needed in the
WHERE clause? Mark for Review
(1) Points
3
0
2 (*)
1
Section 8
(Answer all questions in this section)
Which two clauses represent valid uses of aggregate functions for this table?
38. Which group function would you use to display the highest salary value in the EMPLOYEES
table? Mark for Review
(1) Points
COUNT
MIN
MAX (*)
AVG
Section 9
(Answer all questions in this section)
39. The difference between UNION and UNION ALL is Mark for Review
(1) Points
UNION will remove duplicates; UNION ALL returns all rows from all queries including the
duplicates. (*)
Select the correct GROUP BY GROUPING SETS clause from the following list:
Section 9
(Answer all questions in this section)
41. 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
42. Group functions can be nested to a depth of? Mark for Review
(1) Points
Group functions cannot be nested.
Two (*)
Three
Four
44. Which statement about the GROUP BY clause is true? Mark for Review
(1) Points
By default, rows are not sorted when a GROUP BY clause is used.
To exclude rows before dividing them into groups using the GROUP BY clause, you should use
a WHERE clause. (*)
You must use the HAVING clause with the GROUP BY clause.
You can use a column alias in a GROUP BY clause.
Section 10
(Answer all questions in this section)
45. Which of the following best describes the meaning of the ANY operator? Mark for
Review
(1) Points
Equal to any member in the list
Compare value to each value returned by the subquery (*)
Equal to each value in the list
Compare value to the first value returned by the subquery
Section 10
(Answer all questions in this section)
46. Which statement about the ANY operator, when used with a multiple-row subquery, is
true? Mark for Review
(1) Points
The ANY operator can be used with the DISTINCT keyword.
The ANY operator can be used with the LIKE and IN operators.
The ANY operator is a synonym for the ALL operator.
The ANY operator compares every value returned by the subquery. (*)
48. Which comparison operator can only be used with a single-row subquery? Mark for
Review
(1) Points
ALL
ANY
<> (*)
IN
49. Which operator can be used with a multiple-row subquery? Mark for Review
(1) Points
IN (*)
<>
=
LIKE
50. Table aliases must be used when you are writing correlated subqueries. (True or
false?) Mark for Review
(1) Points
True
False (*)
Oracle Midterm 2
Section 1 Lesson 1
SELECT LENGTH(email)
FROM employee;
(1) Points
The number of characters for each value in the EMAIL column in the employees table. (*)
Correct
2. Which SQL function can be used to remove heading or trailing characters (or both) from a
character string? Mark for Review
(1) Points
LPAD
CUT
NVL2
TRIM (*)
Correct
3. Which SQL function is used to return the position where a specific character string begins within
a larger character string? Mark for Review
(1) Points
CONCAT
INSTR (*)
LENGTH
SUBSTR
Correct
4. You need to display the number of characters in each customers last name. Which function
should you use? Mark for Review
(1) Points
LENGTH (*)
LPAD
COUNT
SUBSTR
Correct
FROM employees;
(1) Points
The last name of employees that have a salary that includes a $ in the value, size of 15 and the
column labeled SALARY.
The last name and the format of the salary limited to 15 digits to the left of the decimal and the
column labeled SALARY.
The last name and salary for all employees with the format of the salary 15 characters long, left-
padded with the $ and the column labeled SALARY. (*)
The query will result in an error: ORA-00923: FROM keyword not found where expected.
Correct
6. Which functions can be used to manipulate character, number, and date column values? Mark
for Review
(1) Points
7. Which three statements about functions are true? (Choose three.) Mark for Review
(1) Points
The ROUND number function rounds a value to a specified decimal place or the nearest whole
number. (*)
The CONCAT function can only be used on character strings, not on numbers.
The SUBSTR character function returns a portion of a string beginning at a defined character
position to a specified length. (*)
Section 1 Lesson 2
FROM dual;
(1) Points
1200
1282
1282.25
1300 (*)
Correct
(1) Points
IN (*)
LIKE
BETWEENIN
IS NULL
Correct
10. Evaluate this function: MOD (25, 2) Which value is returned? Mark for Review
(1) Points
1 (*)
25
Correct
Section 1 Lesson 3
11. Which SELECT statement will return a numeric value? Mark for Review
(1) Points
FROM employee;
FROM employee;
(*)
SELECT SYSDATE 7
FROM employee;
SELECT SYSDATE + 30
FROM dual;
(1) Points
13. Which of the following SQL statements will correctly display the last name and the number of
weeks employed for all employees in department 90? Mark for Review
(1) Points
FROM employees
WHERE department_id = 90;
(*)
FROM employees
FROM employees
FROM employees
Correct
14. You need to display the current year as a character value (for example: Two Thousand and
One). Which element would you use? Mark for Review
(1) Points
RR
YY
YYYY
YEAR (*)
(1) Points
FROM orders
FROM orders
ORDER BY total;
FROM orders
(*)
FROM orders
Correct
Section 2 Lesson 1
EMPLOYEE_ID NUMBER(9)
HIRE_DATE DATE
(1) Points
FROM employees;
FROM employees;
(*)
FROM employees;
FROM employees;
Incorrect. Refer to Section 2
17. You have been asked to create a report that lists all customers who have placed orders of at
least $2,500. The reports date should be displayed in the Day, Date Month, Year format (For
example, Tuesday, 13 April, 2004 ). Which statement should you issue? Mark for Review
(1) Points
(*)
18. 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? Mark for Review
(1) Points
2001
1901
2017 (*)
1917
Correct
19. Which two statements concerning SQL functions are true? (Choose two.) Mark for Review
(1) Points
Conversion functions convert a value from one data type to another data type. (*)
Single-row functions manipulate groups of rows to return one result per group of rows.
Correct
EMPLOYEE_ID NUMBER(9)
SALARY NUMBER(6)
You need to create a report to display the salaries of all employees. Which script should you use
to display the salaries in format: $45,000.00?
Mark for Review
(1) Points
FROM employees;
FROM employees;
FROM employees;
FROM employees;
(*)
Correct
Section 2 Lesson 1
21. Which statement concerning single row functions is true? Mark for Review
(1) Points
Single row functions can accept only one argument, but can return multiple values.
22. Which statement about group functions is true? Mark for Review
(1) Points
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.
FROM styles
WHERE style_name LIKE SANDAL AND NVL(cost, 0) < 15.00
(1) Points
(*)
Correct
24. Which of the following General Functions will return the first non-null expression in the
expression list? Mark for Review
(1) Points
NVL
NVL2
NULLIF
COALESCE (*)
Correct
Section 3 Lesson 2
CUSTOMERS
COMPANY VARCHAR2(30)
LOCATION VARCHAR2(20)
SALES
TOTAL_SALES NUMBER(30)
Which SELECT statement will return the customer ID, the company and the total sales?
(1) Points
(*)
Correct
26. You have been asked to create a report that lists all corporate customers and all orders that
they have placed. The customers should be listed alphabetically beginning with the letter A, and
their corresponding order totals should be sorted from the highest amount to the lowest amount.
Which of the following statements should you issue? Mark for Review
(1) Points
(*)
Correct
27. What happens when you create a Cartesian product? Mark for Review
(1) Points
All rows from one table are joined to all rows of another table (*)
The table is joined to itself, one column to the next column, exhausting all possibilities
All rows that do not match in the WHERE clause are displayed
Correct
ORDER BY 4;
(1) Points
ORDER BY 4;
(1) Points
a self-join
an outer join
an equijoin
30. Your have two tables named EMPLOYEES and SALES. You want to identify the sales
representatives who have generated at least $100,000 in revenue.
(1) Points
(*)
Section 3 Lesson 4
FROM player p
(1) Points
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 join between the player table and the team table on PLAYER_ID
32. The EMPLOYEE_ID column in the EMPLOYEE table corresponds to the EMPLOYEE_ID column
of the ORDER table. The EMPLOYEE_ID column in the ORDER table contains null values for rows
that you need to display.
Which type of join should you use to display the data? Mark for Review
(1) Points
natural join
self-join
equijoin
33. Which operator would you use after one of the column names in the WHERE clause when
creating an outer join? Mark for Review
(1) Points
(+) (*)
Correct
Section 4 Lesson 2
34. You need to join two tables that have two columns with the same name and compatible data
types. Which type of join would you create to join the tables on both of the columns? Mark for
Review
(1) Points
Outer join
Self-join
Correct
35. A join between tables where the result set includes matching values from both tables but does
NOT return any unmatched rows could be called which of the following? (Choose three) Mark for
Review
(1) Points
Equijoin (*)
Nonequijoin
36. Which of the following best describes a natural join? Mark for Review
(1) Points
A join between two tables that includes columns that share the same name, datatypes and lengths
(*)
Section 4 Lesson 3
37. Which SELECT clause creates an equijoin by specifying a column name common to both
tables? Mark for Review
(1) Points
A HAVING clause
Correct
38. Below find the structures of the PRODUCTS and VENDORS tables:
PRODUCTS
PRODUCT_ID NUMBER
VENDOR_ID NUMBER
CATEGORY_ID NUMBER
VENDORS
VENDOR_ID NUMBER
You want to create a query that will return an alphabetical list of products, including the product
name and associated vendor name, for all products that have a vendor assigned.
(1) Points
FROM products p
ORDER BY p.product_name;
FROM products p
ORDER BY p.product_name;
ORDER BY p.product_name;
(*)
SELECT p.product_name, v.vendor_name
FROM products p
ORDER BY p.product_name;
FROM products p
ORDER BY p.product_name;
(*)
39. The primary advantage of using JOIN ON is: Mark for Review
(1) Points
The join happens automatically based on matching column names and data types
40. Below find the structure of the CUSTOMERS and SALES_ORDER tables:
CUSTOMERS
CREDIT_LIMIT NUMBER(7,2)
SALES_ORDER
ORDER_DT DATE
You need to create a report that displays customers without a sales order. Which statement could
you use?
(1) Points
SELECT c.customer_name
FROM customers c
(*)
SELECT c.customer_name
SELECT c.customer_name
SELECT c.customer_name
FROM customers c
Correct
Section 4 Lesson 4
41. Which two sets of join keywords create a join that will include unmatched rows from the first
table specified in the SELECT statement? Mark for Review
(1) Points
42. Which query represents the correct syntax for a left outer join? Mark for Review
(1) Points
FROM customers c
ON c.cust_id = o.cust_id;
FROM customers c
ON c.cust_id = o.cust_id;
FROM customers c
(*)
FROM customers c
ON c.cust_id = o.cust_id;
(1) Points
an inner join
Correct
Section 5 Lesson 1
FROM employee
GROUP BY dept_id;
(1) Points
The hire dates in the EMPLOYEE table that contain NULL values.
Correct
45. What is the best explanation as to why this SQL statement will NOT execute?
FROM employees
GROUP BY Department;
(1) Points
Salaries cannot be averaged as not all the numbers will divide evenly.
FROM employees
GROUP BY job_id;
(1) Points
Displays each job id and the number of people assigned to that job id. (*)
47. 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
join clause
order by clause
Correct
Section 5 Lesson 2
48. You need to calculate the average salary of employees in each department. Which group
function will you use? Mark for Review
(1) Points
AVG (*)
MEAN
MEDIAN
AVERAGE
49. Which aggregate function can be used on a column of the DATE data type? Mark for Review
(1) Points
AVG
MAX (*)
STDDEV
SUM
Correct
CUSTOMER_ID NUMBER(9)
FNAME VARCHAR2(25)
LNAME VARCHAR2(30)
CATEGORY VARCHAR2(20)
You need to calculate the average credit limit for all the customers in each category. The average
should be calculated based on all the rows in the table excluding any customers who have not yet
been assigned a credit limit value. Which group function should you use to calculate this value?
(1) Points
AVG (*)
SUM
COUNT
STDDEV
Correct
Section 5 Lesson 2
(Answer all questions in this section)
51. You need to calculate the standard deviation for the cost of products produced in the
Birmingham facility. Which group function will you use? Mark for Review
(1) Points
STDEV
STDDEV (*)
VAR_SAMP
VARIANCE
TRUCKS
TYPE VARCHAR2(30)
YEAR DATE
MODEL VARCHAR2(20)
PRICE NUMBER(10)
Which SELECT statement will return the average price for the 44 model?
(1) Points
Correct
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.)
(1) Points
MAX (*)
SUM
AVG
MIN (*)
COUNT (*)
NAME VARCHAR2(30)
LOCATION_ID NUMBER
ORDER_DT DATE
ORDER_AMOUNT NUMBER(8,2)
Which two clauses represent valid uses of aggregate functions for this table?
(1) Points
FROM MAX(order_dt)
SELECT SUM(order_dt)
55. Which group function would you use to display the highest salary value in the EMPLOYEE
table? Mark for Review
(1) Points
AVG
COUNT
MAX (*)
MIN
Correct
Section 5 Lesson 3
SELECT COUNT(*)
FROM products;
(1) Points
Correct
57. Group functions can avoid computations involving duplicate values by including which
keyword? Mark for Review
(1) Points
NULL
DISTINCT (*)
SELECT
UNLIKE
Correct
58. Which SELECT statement will calculate the number of rows in the PRODUCTS table? Mark for
Review
(1) Points
SELECT COUNT(products);
Correct
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?
(1) Points
(*)
Correct
Section 6 Lesson 1
60. What is the correct order of clauses in a SELECT statement? Mark for Review
(1) Points
SELECT
FROM
WHERE
ORDER BY
HAVING
SELECT
FROM
HAVING
GROUP BY
WHERE
ORDER BY
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
(*)
SELECT
FROM
WHERE
HAVING
ORDER BY
GROUP BY
Correct
Section 6 Lesson 1
(Answer all questions in this section)
DEPARTMENT_ID NUMBER
HIRE_DATE DATE
FROM employees
ORDER BY hire_date;
(1) Points
Correct
62. 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 made a
payment between January 1, 2003 and June 30, 2003 ?
(1) Points
FROM payment
GROUP BY customer_id;
(*)
SELECT COUNT(payment_id)
FROM payment
FROM payment
SELECT COUNT(payment_id)
FROM payment
WHERE payment_date BETWEEN 01-JAN-2003 AND 30-JUN-2003
GROUP BY customer_id;
63. You want to write a report that returns the average salary of all employees in the company,
sorted by departments. The EMPLOYEES table contains the following columns:
EMPLOYEES:
LNAME VARCHAR2(20)
FNAME VARCHAR2(20)
DEPT VARCHAR2(20)
HIRE_DATE DATE
SALARY NUMBER(10)
Which SELECT statement will return the information that you require?
(1) Points
FROM employees
GROUP BY dept;
FROM employees
GROUP BY dept;
(*)
FROM employees
BY dept;
FROM employees
BY dept;
Correct
FROM employee
WHERE status = I
GROUP BY dept_id
ORDER BY 2;
(1) Points
FROM employees
ORDER BY department_id;
(1) Points
Correct
MANUFACTURER_ID NUMBER
MANUFACTURER_NAME VARCHAR2(30)
TYPE VARCHAR2(25)
LOCATION_ID NUMBER
You need to display the number of unique types of manufacturers at each location. Which SELECT
statement should you use?
(1) Points
FROM manufacturer
GROUP BY location_id;
(*)
FROM manufacturer;
FROM manufacturer
GROUP BY location_id;
FROM manufacturer
GROUP BY type;
Correct
67. 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 use should a
WHERE clause. (*)
You must use the HAVING clause with the GROUP BY clause.
Section 6 Lesson 2
68. Which operator can be used with a multiple-row subquery? Mark for Review
(1) Points
IN (*)
<>
LIKE
Correct
69. 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
(*)
SELECT product_name
FROM products
FROM products
GROUP by product_name;
SELECT product_name
CUSTOMER
CUSTOMER_ID NUMBER(5)
NAME VARCHAR2(25)
CREDIT_LIMIT NUMBER(8,2)
OPEN_DATE DATE
ORDER_HISTORY
ORDER_ID NUMBER(5)
CUSTOMER_ID NUMBER(5)
ORDER_DATE DATE
TOTAL NUMBER(8,2)
Which of the following scenarios would require a subquery to return the desired results?
(1) Points
You need to display the date each customer account was opened.
You need to display all the orders that were placed on a certain date.
You need to display all the orders that were placed on the same day as order number 25950. (*)
Section 6 Lesson 2
71. Which operator can be used with subqueries that return only one row? Mark for Review
(1) Points
LIKE (*)
ANY
ALL
IN
(1) Points
Subqueries are often used in a WHERE clause to return values for an unknown conditional value.
(*)
Subqueries generally execute last, after the main or outer query executes.
Correct
Section 6 Lesson 3
73. Which statement about the <> operator is true? Mark for Review
(1) Points
The <> operator returns the same result as the ANY operator in a subquery.
The <> operator can be used when a single-row subquery returns only one row. (*)
(1) Points
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
(1) Points
no rows (*)
a null value
an error
Section 6 Lesson 4
76. 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
BETWEENAND
Correct
77. Which operator or keyword cannot be used with a multiple-row subquery? Mark for Review
(1) Points
ALL
ANY
= (*)
>
Correct
FROM payment
WHERE payment_id =
(SELECT payment_id
FROM payment
(1) Points
Change the outer query WHERE clause to WHERE payment_id IN. (*)
79. Which of the following best describes the meaning of the ANY operator? Mark for Review
(1) Points
80. What would happen if you attempted to use a single-row operator with a multiple-row
subquery? Mark for Review
(1) Points
Section 6 Lesson 4
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)
(1) Points
WHERE manufacturers_id =
(SELECT id
FROM manufacturers
FROM parts
WHERE manufacturers_id !=
(SELECT id
FROM manufacturers
FROM parts
WHERE manufacturers_id IN
(SELECT id
FROM manufacturers m
(*)
SELECT parts_name
FROM
(SELECT AVG(cost)
FROM manufacturers)
82. You are looking for Executive information using a subquery. What will the following SQL
statement display?
FROM employees
WHERE department_id IN
(SELECT department_id
FROM departments
(1) Points
The department ID, department name and last name for every employee in the Executive
department.
The department ID, last name, department name for every Executive in the employees table.
The department ID, last name, job ID from departments for Executive employees.
The department ID, last name, job ID for every employee in the Executive department. (*)
Correct
FROM payment
WHERE payment_id =
(SELECT payment_id
FROM payment
WHERE payment_date >= 05-JAN-2002 OR payment_amount > 500.00);
(1) Points
Change the outer query WHERE clause to WHERE payment_id IN. (*)
Include the PAYMENT_ID column in the select list of the outer query.
Remove the single quotes around the date value in the inner query WHERE clause.
Correct
84. You need to display all the products that cost more than the maximum cost of every product
produced in Japan. Which multiple-row comparison operator could you use? Mark for Review
(1) Points
>ANY (*)
NOT=ALL
IN
>IN
85. Which statement about the ANY operator when used with a multiple-row subquery is
true? Mark for Review
(1) Points
The ANY operator compares every value returned by the subquery. (*)
The ANY operator can be used with the LIKE and IN operators.
FROM players
WHERE team_id IN
(SELECT team_id
FROM teams
(1) Points
All the rows in the PLAYER table would be returned by the outer query.
Correct
Section 7 Lesson 1
DOB DATE
ENROLL_DATE DATE
You create another table, named FT_STUDENTS, with an identical structure.You want to insert all
full-time students, who have a STU_TYPE_ID value of F, into the new table. You execute this
INSERT statement:
FROM students
(1) Points
All full-time students are inserted into the FT_STUDENTS table. (*)
An error occurs because the INSERT statement does NOT contain a VALUES clause.
88. Which statement about the VALUES clause of an INSERT statement is true? Mark for Review
(1) Points
If no column list is specified, then the values must be in the order the columns are specified in the
table. (*)
Character, date, and numeric data must be enclosed within single quotes in the VALUES clause.
89. You need to copy rows from the EMPLOYEE table to the EMPLOYEE_HIST table. What could
you use in the INSERT statement to accomplish this task? Mark for Review
(1) Points
an ON clause
a SET clause
a subquery (*)
a function
PROD_ID NUMBER(4)
PROD_NAME VARCHAR2(25)
PROD_PRICE NUMBER(3)
You want to add the following row data to the PRODUCTS table:
(1) Points
The row was created with the correct data in all three columns. (*)
The row was created with the correct data in two of three columns.
The row was created with the correct data in one of the three columns.
The row was created completely wrong. No data ended up in the correct columns.
Section 7 Lesson 2
91. One of the sales representatives, Janet Roper, has informed you that she was recently
married, and she has requested that you update her name in the employee database. Her new last
name is Cooper. Janet is the only person with the last name of Roper that is employed by the
company. The EMPLOYEES table contains these columns and all data is stored in lowercase:
LNAME VARCHAR2(20)
FNAME VARCHAR2(20)
SALARY NUMBER(10)
(1) Points
UPDATE employees
(*)
UPDATE employees
UPDATE employees
Correct
LNAME VARCHAR2(20)
FNAME VARCHAR2(20)
DEPT VARCHAR2(20)
HIRE_DATE DATE
SALARY NUMBER(9,2)
BONUS NUMBER(9,2)
You want to execute one DML statement to change the salary of all employees in department 10
to equal the new salary of employee number 89898. Currently, all employees in department 10
have the same salary value. Which statement should you execute?
(1) Points
UPDATE employee
FROM employee
UPDATE employee
UPDATE employee
(*)
UPDATE employee
SET salary = (SELECT salary FROM employee WHERE emp_id = 89898 AND dept = 10);
Correct
TEAM_ID NUMBER
SALARY NUMBER(9,2)
You need to increase the salary of each player for all players on the Tiger team by 12.5 percent.
The TEAM_ID value for the Tiger team is 5960. Which statement should you use?
(1) Points
UPDATE players SET salary = salary * 1.125 WHERE team_id = 5960; (*)
Correct
94. You need to delete a record in the EMPLOYEES table for Tim Jones, whose unique employee
identification number is 348. The EMPLOYEES table contains these columns:
LNAME VARCHAR2(20)
FNAME VARCHAR2(20)
ADDRESS VARCHAR2(30)
PHONE NUMBER(10)
Which DELETE statement will delete the appropriate record without deleting any additional records?
(1) Points
95. You need to update the expiration date of products manufactured before June 30th . In which
clause of the UPDATE statement will you specify this condition? Mark for Review
(1) Points
the ON clause
Correct
96. Which of the following represents the correct syntax for an INSERT statement? Mark for
Review
(1) Points
INSERT VALUES INTO customers (3178 J. Smith 123 Main Street Nashville TN 37777;
INSERT INTO customers VALUES 3178 J. Smith 123 Main Street Nashville TN 37777;
INSERT INTO customers VALUES (3178, J., Smith, 123 Main Street, Nashville, TN, 37777);
(*)
INSERT customers VALUES 3178, J., Smith, 123 Main Street, Nashville, TN, 37777;
97. One of your employees was recently married. Her employee ID is still 189, however, her last
name is now Rockefeller. Which SQL statement will allow you to reflect this change? Mark for
Review
(1) Points
98. When the WHERE clause is missing in a DELETE statement, what is the result? Mark for
Review
(1) Points
Correct
99. What keyword in an UPDATE statement speficies the columns you want to change? Mark for
Review
(1) Points
SELECT
WHERE
SET (*)
HAVING
Correct
100. You need to update both the DEPARTMENT_ID and LOCATION_ID columns in the EMPLOYEE
table using one UPDATE statement. Which clause should you include in the UPDATE statement to
update multiple columns? Mark for Review
(1) Points
the ON clause
Review your answers, feedback, and question scores below. An asterisk (*)
indicates a correct answer.
Part I of the Semester 2 Mid Term Exam covers Sections 1-4, and the
Review of Joins in Section 5, of Database Programming with SQL
curriculum.
Section 1
1.
You need to return a portion of each employees last name, beginning with
the first character up to the fifth character. Which character function should
you use? Mark for Review
(1) Points
INSTR
TRUNC
SUBSTR (*)
CONCAT
Correct
2.
You query the database with this SQL statement:
SELECT LOWER(SUBSTR(CONCAT(last_name, first_name)), 1, 5) ID
FROM employee;
In which order are the functions evaluated? Mark for Review
(1) Points
Correct
3.
The STYLES table contains this data:
STYLE_ID STYLE_NAME CATEGORY COST
895840 SANDAL 85940 12.00
968950 SANDAL 85909 10.00
869506 SANDAL 89690 15.00
809090 LOAFER 89098 10.00
890890 LOAFER 89789 14.00
857689 HEEL 85940 11.00
758960 SANDAL 86979 12.00
You query the database and return the value 79. Which script did you use?
Mark for Review
(1) Points
4.
Which SQL function can be used to remove heading or trailing characters
(or both) from a character string? Mark for Review
(1) Points
LPAD
CUT
NVL2
TRIM (*)
Correct
5.
You issue this SQL statement:
SELECT INSTR (organizational sales, al)
FROM dual;
Which value is returned by this command? Mark for Review
(1) Points
13 (*)
17
Correct
6.
The PRICE table contains this data:
PRODUCT_ID MANUFACTURER_ID
86950 59604
You query the database and return the value 95. Which script did you use?
Mark for Review
(1) Points
SELECT SUBSTR(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;
(*)
SELECT LENGTH(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604;
Correct
7.
Evaluate this SELECT statement:
SELECT LENGTH(email)
FROM employee;
What will this SELECT statement display? Mark for Review
(1) Points
Correct
8.
You need to subtract three months from the current date. Which function
should you use? Mark for Review
(1) Points
ROUND
TO_DATE
ADD_MONTHS (*)
MONTHS_BETWEEN
Correct
9.
Evaluate this SELECT statement:
SELECT SYSDATE + 30
FROM dual;
Which value is returned by the query? Mark for Review
(1) Points
10.
You need to display the current year as a character value (for example:
Two Thousand and One). Which element would you use? Mark for Review
(1) Points
RR
YY
YYYY
YEAR (*)
Correct
Page 1 of 5
Section 1 11. Which SELECT statement will return a numeric value? Mark
for Review
(1) Points
SELECT SYSDATE 7
FROM employee;
Incorrect. Refer to Section 1
12. Which function would you use to return the current database server
date and time? Mark for Review
(1) Points
DATE
SYSDATE (*)
DATETIME
CURRENTDATE
Correct
13. You issue this SQL statement:
SELECT TRUNC(751.367,-1) FROM dual;
Which value does this statement display?
Mark for Review
(1) Points
700
750 (*)
751
751.3
Correct
14. Which comparison operator retrieves a list of values? Mark for Review
(1) Points
IN (*)
LIKE
BETWEEN IN
IS NULL
Correct
15. You issue this SQL statement:
SELECT ROUND (1282.248, -2) FROM dual;
What value does this statement produce?
Mark for Review
(1) Points
1200
1282
1282.25
1300 (*)
Correct
Section 2 16. 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
Evaluate this SELECT statement:
SELECT style_id, style_name, category, cost
FROM styles WHERE style_name LIKE SANDAL AND NVL(cost, 0) <
15.00
ORDER BY category, cost;
Which result will the query provide?
Mark for Review
(1) Points
Correct
17. Which statement about group functions is true? Mark for Review
(1) Points
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
18. When executed, which statement displays a zero if the
TUITION_BALANCE value is zero and the HOUSING_BALANCE value is
null? Mark for Review
(1) Points
Correct
19. The PRODUCT table contains this column: PRICE NUMBER(7,2)
Evaluate this statement:
SELECT NVL(10 / price, 4)
FROM PRODUCT;
What would happen if the PRICE column contains null values?
Mark for Review
(1) Points
The statement would fail because values cannot be divided by 4.
Use the TO_DATE function to convert a character string to a date value. (*)
Correct
Section 2 21. Which statement concerning single row functions is true?
Mark for Review
(1) Points
Single row functions can accept only one argument, but can return multiple
values.
Single row functions cannot modify a data type.
Correct
22. Which SQL Statement should you use to display the prices in this
format: $00.30? Mark for Review
(1) Points
Correct
23. The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(9)
LAST_NAME VARCHAR2 (25)
FIRST_NAME VARCHAR2 (25)
SALARY NUMBER(6)
You need to create a report to display the salaries of all employees. Which
script should you use to display the salaries in format: $45,000.00?
Mark for Review
(1) Points
SELECT TO_CHAR(salary, $999,999)
FROM employees;
Correct
24. All Human Resources data is stored in a table named EMPLOYEES.
You have been asked to create a report that displays each employees
name and salary. Each employees salary must be displayed in the
following format: $000,000.00. Which function should you include in a
SELECT statement to achieve the desired result? Mark for Review
(1) Points
TO_CHAR (*)
TO_DATE
TO_NUMBER
CHARTOROWID
Correct
25. Which two statements concerning SQL functions are true? (Choose
two.) Mark for Review
(1) Points (Choose all correct answers)
Conversion functions convert a value from one data type to another data
type. (*)
Correct
Section 3 26. You need to provide a list of the first and last names of all
employees who work in the Sales department who earned a bonus and had
sales over $50,000. The company president would like the sales listed
starting with the highest amount first. The EMPLOYEES table and the
SALES_DEPT table contain the following columns:
EMPLOYEES
EMPLOYEE_ID NUMBER(10) PRIMARY KEY
LAST_NAME VARCHAR2(20)
FIRST_NAME VARCHAR2(20)
DEPARTMENT_ID VARCHAR2(20)
HIRE_DATE DATE
SALARY NUMBER(10)
SALES_DEPT
SALES_ID NUMBER(10) PRIMARY KEY
SALES NUMBER(20)
QUOTA NUMBER(20)
MANAGER VARCHAR2(30)
BONUS NUMBER(10)
EMPLOYEE_ID NUMBER(10) FOREIGN KEY
Which SELECT statement will accomplish this task?
Mark for Review
(1) Points
Correct
27. 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 employees bonus, as a
calculation of salary times bonus. Which of the following queries should you
issue?
Mark for Review
(1) Points
Correct
29. What is produced when a join condition is not specified in a multiple-
table query using Oracle proprietary Join syntax? Mark for Review
(1) Points
A self-join
An outer join
An equijoin
Correct
30. You have two tables named EMPLOYEES and SALES. You want to
identify the sales representatives who have generated $100,000, or more,
in revenue. Which query should you issue? Mark for Review
(1) Points
SELECT e.first_name, e.last_name, s.sales
FROM employees e, sales s
WHERE e.employee_id = s.employee_id AND revenue > 100000;
Correct
Section 3 31. Which statement about the join syntax of an Oracle
Proprietary join syntax SELECT statement is true? Mark for Review
(1) Points
Correct
32. 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? Mark for Review
(1) Points
An equijoin
A cross join
A non-equijoin (*)
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 join between the player table and the team table on PLAYER_ID
Correct
34. 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? Mark for Review
(1) Points
Natural join
Self-join
Equijoin
Correct
35. Using Oracle Proprietary join syntax, which two operators can be used
in an outer join condition using the outer join operator (+)? Mark for Review
(1) Points
OR and =
BETWEENAND and IN
IN and =
Correct
36. Evaluate this SELECT statement:
SELECT *
FROM employee e, employee m
WHERE e.manager_id = m.employee_id;
Which type of join is created by this SELECT statement?
Mark for Review
(1) Points
a cross join
A cross join
An inner join
Correct
39. Which query will retrieve all the rows in the EMPLOYEES table, even if
there is no match in the DEPARTMENTS table? Mark for Review
(1) Points
Correct
40. Which of the following best describes a natural join? Mark for Review
(1) Points
A join between two tables that includes columns that share the same name,
datatypes and lengths (*)
A join that produces a Cartesian product
Correct
Section 4 41. Which statement about a natural join is true? Mark for Review
(1) Points
Columns with the same names must have identical data types.
Columns with the same names must have the same precision and
datatype. (*)
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
42. You need to join two tables that have two columns with the same name,
datatype and precision. Which type of join would you create to join the
tables on both of the columns? Mark for Review
(1) Points
Cross join
Outer join
Self-join
Correct
43. The primary advantages of using JOIN ON is: (Select two) Mark for
Review
(1) Points (Choose all correct answers)
It permits columns that dont have matching data types to be joined. (*)
Correct
44. For which condition would you use an equijoin query with the USING
keyword? Mark for Review
(1) Points
You need to perform a join of the CUSTOMER and ORDER tables but limit
the number of columns in the join condition. (*)
SELECT c.customer_name
FROM customers c
WHERE c.customer_id not in (SELECT s.customer_id FROM sales_order
s);
(*)
SELECT c.customer_name
FROM customers c, sales_order s
WHERE c.customer_id = s.customer_id(+);
SELECT c.customer_name
FROM customers c, sales_order s
WHERE c.customer_id (+) = s.customer_id;
SELECT c.customer_name
FROM customers c
RIGHT OUTER JOIN sales_order s
ON (c.customer_id = s.customer_id);
Correct
Section 5 47. Which statement about the GROUP BY clause is true? Mark
for Review
(1) Points
The first column listed in the GROUP BY clause is the most major
grouping. (*)
The last column listed in the GROUP BY clause is the most major
grouping.
Correct
48. 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
JOIN clause
ORDER BY clause
Correct
49. 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
Salaries cannot be averaged as not all the numbers will divide evenly.
Correct
50. 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.
Correct