Database Programming With SQL - MidTerm 2019
Database Programming With SQL - MidTerm 2019
Database Programming With SQL - MidTerm 2019
3. All computers in the world speak the same languages, so you only need to learn one programming
language - Oracle SQL. True or False?
True
False (*)
5. What would you use in the SELECT clause to return all the columns in the table?
An asterisk (*) (*)
A plus sign (+)
The ALL keyword
A minus sign (-)
6. You need to combine the FIRST_NAME and LAST_NAME columns in the EMPLOYEES table and display
the columns as a combined character string. Which operator should you use?
|
AND
|| (*)
+
9. To restrict the rows returned from an SQL Query, you should use the _____ clause:
SELECT
WHERE (*)
GROUP BY
CONDITION
All of the Above
11. If you write queries using the BETWEEN operator, it does not matter in what order you enter the
values, i.e. BETWEEN low value AND high value will give the same result as BETWEEN high value and low
value. True or False?
True
False (*)
12. You need to change the default sort order of the ORDER BY clause so that the data is displayed in
reverse alphabetical order. Which keyword should you include in the ORDER BY clause?
DESC (*)
ASC
CHANGE
SORT
16. Round and Trunc cannot be used on Date datatypes. True or False?
True
False (*)
SELECT SUBSTR(product_id, 3, 2)
FROM price
WHERE manufacturer_id = 59604; (*)
22. Which statement will return a listing of last names, salaries, and a rating of 'Low', 'Medium', 'Good'
or 'Excellent' depending on the salary value?
SELECT last_name,salary,
(RATING WHEN salary<5000 THEN 'Low'
WHEN salary<10000 THEN 'Medium'
WHEN salary<20000 THEN 'Good'
ELSE 'Excellent'
END) qualified_salary
FROM employees;
SELECT last_name,salary,
(CASE WHEN salary<5000 THEN 'Low'
WHEN salary<10000 THEN 'Medium'
WHEN salary<20000 THEN 'Good'
ELSE 'Excellent'
END) qualified_salary
FROM employees; (*)
SELECT last_name,sal,
(CASE WHEN sal<5000 THEN 'Low'
WHEN sal<10000 THEN 'Medium'
WHEN sal<20000 THEN 'Good'
ELSE 'Excellent'
END) qualified_salary
FROM employees;
SELECT last_name,salary,
(CASE WHEN salary<5000 THEN 'Low'
WHEN sal <10000 THEN 'Medium'
WHEN sal <20000 THEN 'Good'
ELSE 'Excellent'
END) qualified_salary
FROM employees;
23. Which SQL Statement should you use to display the prices in this format: "$00.30"?
SELECT TO_CHAR(price, '$99,999.99') FROM product;
SELECT TO_NUMBER(price, '$99,900.99') FROM product;
SELECT TO_CHAR(price, '$99,990.99') FROM product;
SELECT TO_CHAR(price, '$99,900.99') FROM product; (*)
24. You need to display the HIRE_DATE values in this format: 25th of July 2002. Which SELECT statement
would you use?
SELECT TO_CHAR(hire_date, 'DDspth 'of' Month RRRR') FROM employees;
25. All Human Resources data is stored in a table named EMPLOYEES. You have been asked to create a
report that displays each employee's name and salary. Each employee's 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?
TO_NUMBER
TO_DATE
TO_CHAR (*)
CHARTOROWID
28. 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 full outer join
A cross join (*)
An inner join
An equijoin
29. The join column must be included in the select statement when you use the NATURAL JOIN clause.
True or False?
True
False (*)
30. You need to display all the rows (both matching and non-matching) from both the EMPLOYEE and
EMPLOYEE_HIST tables. Which type of join would you use?
A right outer join
A left outer join
An inner join
A full outer join (*)
A query is needed to display each department and its manager name from the above tables. However,
not all departments have a manager but we want departments returned in all cases. Which of the
following SQL: 1999 syntax scripts will accomplish the task?
34. You need to create a report that lists all employees in department 10 (Sales) whose salary is not
equal to $25,000 per year. Which query should you issue to accomplish this task?
36. Which SELECT statement will calculate the number of rows in the PRODUCTS table?
SELECT COUNT FROM products;
SELECT COUNT(products);
SELECT ROWCOUNT FROM products;
SELECT COUNT (*) FROM products; (*)
37. You need to compute the total salary amount for all employees in department 10. Which group
function will you use?
MAX
COUNT
VARIANCE
SUM (*)
38. Which group functions below act on character, number, and date data types? (Choose all that are
correct.)
AVG
SUM
MAX (*)
COUNT (*)
MIN (*)
39. 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?
HAVING
GROUP BY ALL COLUMNS
CUBE (*)
ROLLUP
40. CUBE can be applied to all aggregate functions including AVG, SUM, MIN, MAX, and COUNT. True or
False?
True (*)
False
41. The ___________ operator returns all rows from both tables, after eliminating duplicates.
UNION (*)
INTERSECT
MINUS
UNION ALL
42. 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:
EMP_ID NUMBER(10) PRIMARY KEY
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?
SELECT salary(AVG), dept FROM employees GROUP BY dept;
SELECT dept, AVG(salary) FROM employees GROUP BY dept; (*)
SELECT AVG salary FROM employees BY dept;
SELECT AVG (salary) FROM employees BY dept;
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY (*)
SELECT
FROM
WHERE
HAVING
ORDER BY
GROUP BY
SELECT
FROM
HAVING
GROUP BY
WHERE
ORDER BY
SELECT
FROM
WHERE
ORDER BY
GROUP BY
HAVING
44. Is the following statement correct?
SELECT department_id, AVG(salary)
FROM employees;
Yes
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
45. 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?
=
>= (*)
>
<=
46. 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?
True (*)
False
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?
SELECT parts_name
FROM (SELECT AVG(cost) FROM manufacturers)
WHERE cost > AVG(cost);
48. Group functions can be used in subqueries even though they may return many rows. True or False?
True (*)
False