CC6001ES ADSD SQL Exam Model Paper 1 Answers

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

CC6001ES Autumn In-class test Answers

1. Look at the data in table PRODUCTS. Which SQL will list the items on the BL
shelves? (Show the result with the most available quantity at the top row.)

a. SELECT * FROM products


WHERE shelf like '%BL'
ORDER BY available_qty SORT DESC;
b. SELECT * FROM products
WHERE shelf like 'BL%';
c. SELECT * FROM products
WHERE shelf = 'BL%'
ORDER BY available_qty DESC;
*d. SELECT * FROM products
WHERE shelf like 'BL%'
ORDER BY available_qty DESC;

2. A developer reports that she is receiving the following error:


SELECT key_seq.currval FROM dual;

ERROR at line 1:
ORA-08002: sequence KEY_SEQ.CURRVAL is not yet defined
Which of the following statements does the developer need to run to fix this
condition?

a. create sequence key_seq;


b. create synonym key_seq;
*c. select key_seq.nextval from dual;
d. grant create sequence to public;
3. Bitmapped indexes are best suited to which type of environment?

a. High-cardinality columns
b. Online transaction processing (OLTP) applications
c. Full-table scan access
*d. Low- to medium-cardinality columns

4. Column alias names cannot be used in which clause?

a. SELECT clause
*b. WHERE clause
c. ORDER BY clause
d. None of the above

5. Consider the following SQL, and choose the most appropriate option.
SELECT COUNT(DISTINCT SUBSTR(first_name, 1,1))
FROM employees;

a. A single-row function nested inside a group function is not allowed.


b. The GROUP BY clause is required to successfully run this query.
c. Removing the DISTINCT qualifier will fix the error in the query.
*d. The query will execute successfully without any modification.

6. Consider the following UPDATE statement. Which UPDATE statements from


the options will accomplish the same task? (Choose two.)
UPDATE ACCOUNTS
SET LAST_UPDATED = SYSDATE,
UPDATE_USER = USER;

a. UPDATE ACCOUNTS
SET (LAST_UPDATED, UPDATE_USER) =
(SYSDATE, USER);
*b. UPDATE ACCOUNTS
SET LAST_UPDATED =
(SELECT SYSDATE FROM DUAL),
UPDATE_USER = (SELECT USER FROM DUAL);
*c. UPDATE ACCOUNTS
SET (LAST_UPDATED, UPDATE_USER) =
(SELECT SYSDATE, USER FROM DUAL);
d. UPDATE ACCOUNTS
SET LAST_UPDATED = SYSDATE
AND UPDATE_USER = USER;

7. Consider the following code segment. How many rows will be in the CARS
table after all these statements are executed?
SELECT COUNT(*) FROM CARS;
COUNT(*)
--------
30

DELETE FROM CARS WHERE MAKE = 'TOYOTA';


2 rows deleted.

SAVEPOINT A;
Savepoint creted.

INSERT INTO CARS VALUES ('TOYOTA','CAMRY',4,220);


1 row created.

SAVEPOINT A;

INSERT INTO CARS VALUES ('TOYOTA','COROLLA',4,180);


1 row created.

ROLLBACK TO SAVEPOINT A;
Rollback complete.

a. 28
*b. 29
c. 30
d. 32
8. Consider the following query:
SELECT deptno, ename, salary salary, average,
salary-average difference
FROM emp,
(SELECT deptno dno, AVG(salary) average FROM emp
GROUP BY deptno)
WHERE deptno = dno
ORDER BY 1, 2;
Which of the following statements is correct?

a. The query will fail because no alias name is provided for the subquery.
b. GROUP BY cannot be used inside a subquery.
c. The query will fail because a column selected in the subquery is
referenced outside the scope of the subquery.
*d. The query will work without errors.

9. Consider the following statement:


CREATE TABLE MY_TABLE (
1ST_COLUMN NUMBER,
2ND_COLUMN VARCHAR2 (20));
Which of the following best describes this statement?

a. Tables cannot be created without a defining a primary key. The table


definition here is missing the primary key.
b. The reserved word COLUMN cannot be part of the column name.
*c. The column names are invalid.
d. There is no maximum length specified for the first column definition.
You must always specify a length for character and numeric columns.
e. There is no error in the statement.

10. Consider the following three SQL statements. Choose the most appropriate
option.
1. DELETE FROM CITY WHERE CNT_CODE = 1;
2. DELETE CITY WHERE CNT_CODE = 1;
3. DELETE (SELECT * FROM CITY WHERE CNT_CODE = 1);
a. Statements 1 and 2 will produce the same result; statement 3 will error
out.
b. Statements 1 and 2 will produce the same result; statement 3 will
produce a different result.
*c. Statements 1, 2, and 3 will produce the same result.
d. Statements 1, 2, and 3 will produce different results.

11. Consider the following two SQL statements, and choose the best option:
1. SELECT TO_DATE('30-SEP-07','DD-MM-YYYY') from dual;
2. SELECT TO_DATE('30-SEP-07','DD-MON-RRRR') from dual;

a. Statement 1 will error; 2 will produce result.


b. The resulting date value from the two statements will be the same.
*c. The resulting date value from the two statements will be different.
d. Both statements will generate an error.

12. Evaluate the following SQL statement:

SQL> SELECT cust_id, cust_last_name


FROM customers
WHERE cust_credit_limit IN
(select cust_credit_limit
FROM customers
WHERE cust_city ='Singapore');

Which statement is true regarding the above query if one of the values generated
by the
subquery is NULL?

a. It produces an error
b. It executes but returns no rows.
*c. It generates output for NULL as well as the other values produced by
the subquery.
d. It ignores the NULL value and generates output for the other values
produced by the
subquery.

13. Evaluate the following query:


SQL> SELECT TRUNC(ROUND(156.00,-1),-1)
FROM DUAL;
What would be the outcome?

a. 16
b. 100
*c. 160
d. 200
e. 150

14. Examine the data in the EMPLOYEES and DEPARTMENTS tables.

You want to retrieve all employees' last names, along with their managers' last
names and their department names. Which query would you use?

a. SELECT e.last_name, m.last_name, department_name


FROM employees e
LEFT OUTER JOIN employees m on ( e.manager_id = m.employee_id)
RIGHT OUTER JOIN departments d ON (e.department_id =
d.department_id);
*b. SELECT e.last_name, m.last_name, department_name
FROM employees e
LEFT OUTER JOIN employees m on ( e.manager_id = m.employee_id)
LEFT OUTER JOIN departments d ON (e.department_id =
d.department_id);
c. SELECT e.last_name, m.last_name, department_name
FROM employees e
RIGHT OUTER JOIN employees m on ( e.manager_id = m.employee_id)
LEFT OUTER JOIN departments d ON (e.department_id =
d.department_id);
d. SELECT e.last_name, m.last_name, department_name
FROM employees e
RIGHT OUTER JOIN employees m on ( e.manager_id = m.employee_id)
RIGHT OUTER JOIN departments d ON (e.department_id =
d.department_id);

15. Examine the structure of the CUSTOMERS table.


Evaluate the following SQL statement:

SQL> SELECT cust_city, COUNT(cust_last_name)


FROM customers
WHERE cust_credit_limit > 1000
GROUP BY cust_city
HAVING AVG(cust_credit_limit) BETWEEN 5000 AND 6000;

Which statement is true regarding the outcome of the above query?

*a. It executes successfully.


b. It returns an error because the BETWEEN operator cannot be used in
the HAVING clause.
c. It returns an error because WHERE and HAVING clauses cannot be
used in the same
SELECT statement.
d. It returns an error because WHERE and HAVING clauses cannot be
used to apply conditions
on the same column.

16. Examine the structure of the CUSTOMERS table.


Which statement would display the highest credit limit available in each income
level in each city
in the CUSTOMERS table?

a. SELECT cust_city, cust_income_level, MAX(cust_credit_limit)


FROM customers
GROUP BY cust_city, cust_income_level, cust_credit_limit;
*b. SELECT cust_city, cust_income_level, MAX(cust_credit_limit)
FROM customers
GROUP BY cust_city, cust_income_level;
c. SELECT cust_city, cust_income_level, MAX(cust_credit_limit)
FROM customers
GROUP BY cust_credit_limit, cust_income_level, cust_city;
d. SELECT cust_city, cust_income_level, MAX(cust_credit_limit)
FROM customers
GROUP BY cust_city, cust_income_level, MAX (cust_credit_limit);
17. How do you remove the view USA_STATES from the schema?

a. ALTER VIEW USA_STATES REMOVE;


*b. DROP VIEW USA_STATES;
c. DELETE VIEW USA_STATES
d. DROP USA_STATES;

18. How many rows will be counted in the last SQL statement that follows?
SELECT COUNT(*) FROM emp;
120 returned

INSERT INTO emp (emp_id)


VALUES (140);
SAVEPOINT emp140;

INSERT INTO emp (emp_id)


VALUES (141);
INSERT INTO emp (emp_id)
VALUES (142);
INSERT INTO emp (emp_id)
VALUES (143);
TRUNCATE TABLE employees;
INSERT INTO emp (emp_id)
VALUES (144);

ROLLBACK;

SELECT COUNT(*) FROM emp;

a. 0
b. 121
*c. 124
d. 143

19. How will the results of the following two statements differ?
Statement 1:
SELECT MAX(longitude), MAX(latitude)
FROM zip_state_city;

Statement 2:
SELECT MAX(longitude), MAX(latitude)
FROM zip_state_city
GROUP BY state;

a. Statement 1 will fail because it is missing a GROUP BY clause.


*b. Statement 2 will return one row, and statement 1 may return more than
one row.
c. Statement 2 will fail because it does not have the columns used in the
GROUP BY clause in the SELECT clause.
d. Statement 1 will display two columns, and statement 2 will display two
values for each state.

20. Identify the SQL that produces the correct result.

*a. SELECT department_id, SUM(salary)


FROM employees
WHERE department_id <> 50
GROUP BY department_id
HAVING COUNT(*) > 30;
b. SELECT department_id, SUM(salary) sum_sal
FROM employees
WHERE department_id <> 50
GROUP BY department_id
HAVING sum_sal > 3000;
c. SELECT department_id, SUM(salary) sum_sal
FROM employees
WHERE department_id <> 50
AND sum_sal > 3000
GROUP BY department_id;
d. SELECT department_id, SUM(salary)
FROM employees
WHERE department_id <> 50
AND SUM(salary) > 3000
GROUP BY department_id;
21. In a join view, on how many base tables can you perform a DML operation
(UPDATE/INSERT/DELETE) in a single step?

*a. One
b. The number of base tables in the view definition
c. The number of base tables minus one
d. None

22. Jim executes the following SQL statement. What will be the result?
DELETE salary, commission_pct
FROM employees
WHERE department_id = 30;

a. The salary and commission_pct columns for all records with


department_id 30 are deleted (changed to NULL).
b. All the rows belonging to department_id 30 are deleted from the table.
c. The salary and commission_pct columns are deleted from the
employees table.
*d. The statement will produce an error.

23. Jim is trying to add records from the ORDER_DETAILS table to


ORDER_DETAIL_HISTORY for orders placed before the current year. Which
insert statement would accomplish his task?

a. INSERT INTO ORDER_DETAIL_HISTORY


VALUES (SELECT * FROM ORDER_DETAIL
WHERE ORDER_DATE < TRUNC(SYSDATE,’YY’));
b. INSERT FROM ORDER_DETAIL
INTO ORDER_DETAIL_HISTORY
WHERE ORDER_DATE < TRUNC(SYSDATE,’YY’);
c. INSERT INTO ORDER_DETAIL_HISTORY
FROM ORDER_DETAIL
WHERE ORDER_DATE < TRUNC(SYSDATE,’YY’);
*d. INSERT INTO ORDER_DETAIL_HISTORY
SELECT * FROM ORDER_DETAIL
WHERE ORDER_DATE < TRUNC(SYSDATE,’YY’);

24. John is trying to find out the average salary of employees in each
department. He noticed that the SALARY column can have NULL values, and he
does not want the NULLs included when calculating the average. Identify the
correct SQL that will produce the desired results.

*a. SELECT department_id, AVG(salary)


FROM employees
GROUP BY department_id;
b. SELECT department_id, AVG(NVL(salary,0))
FROM employees
GROUP BY department_id;
c. SELECT department_id, NVL(AVG(salary), 0)
FROM employees
GROUP BY department_id;
d. SELECT department_id, AVG(salary)
FROM employees
GROUP BY department_id
HAVING salary IS NOT NULL;

25. Read the following SQL carefully, and choose the appropriate option. The
JOB_ID column shows the various jobs.
SELECT MAX(COUNT(*))
FROM employees
GROUP BY job_id, department_id;

a. Aggregate functions cannot be nested.


b. The columns in the GROUP BY clause must appear in the SELECT
clause for the query to work.
c. The GROUP BY clause is not required in this query.
*d. The SQL will produce the highest number of jobs within a department.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy