SELECT (2+3*4/2-5) FROM dual;
A. +
B. *
C. /
D. -
Ans: B
2. Which line of the following code has an error?
SELECT *FROM emp WHERE comm = NULL ORDER BY ename;
A. SELECT *
B. FROM emp
C. WHERE comm = NULL
D. There is no error in this statement.
Ans. D.
Although there is no error in this statement, the statement will not return the desired result. When a NULL is compared, you cannot use the = or != operators; you must use the IS NULL or IS NOT NULL operator. See Chapter 1 for more information about the comparison operators.
3. Which two statements are true about NULL values?
A. You cannot search for a NULL value in a column using the WHERE clause.
B. If a NULL value is returned in the subquery or if NULL is included in the list when using a NOT IN operator, no rows will be returned.
C. Only = and != operators can be used to search for NULL values in a column.
D. In an ascending order sort, NULL values appear at the bottom of the result set.
E. Concatenating a NULL value to a non-NULL string results in a NULL.
Ans: B, D.
You can use the IS NULL or IS NOT NULL operator to search for NULLs or non-NULLs in a column. Since NULLs are sorted higher, they appear at the bottom of the result set in an ascending order sort.
4. Which components are required to run iSQL*Plus from your PC? (Choose all that apply.)
A. SQL*Plus installed on the PC
B. Oracle Net on the PC
C. HTTP Server
D. iSQL*Plus Server
Ans: C, D.
iSQL*Plus architecture includes three layers. The client layer is the web browser. The middle layer has the HTTP Server, iSQL*Plus server, and Oracle Net. The third layer is the Oracle database.
5. When you use the DEFINE variable command, what datatype is the variable?
A. VARCHAR2
B. CHAR
C. LONG
D. NUMBER
E. None of the above; you must specify the datatype along with the variable.
Ans: B.
Variables declared using the DEFINE command take the CHAR datatype. To assign a value to a variable, use DEFINE variable=value
6. Which function can return a non-NULL value if passed NULL arguments?
A. NULLIF
B. LENGTH
C. CONCAT
D. INSTR
E. TAN
Ans C.
CONCAT will return a non-NULL if only one parameter is NULL. Both CONCAT parameters would need to be NULL for CONCAT to return NULL. The NULLIF function returns NULL if the two parameters are equal. The LENGTH of a NULL is NULL. INSTR will return NULL if NULL is passed in, and the tangent of a NULL is NULL.
7. (skip)
8. The following statement will raise an exception on which line?
select dept_name, avg(all salary) ,count(*) "number of employees"
from emp , dept
where deptno = dept_no and count(*) > 5
group by dept_name
order by 2 desc;
A. select dept_name, avg(all salary), count(*) "number of employees"
B. where deptno = dept_no
C. and count(*) > 5
D. group by dept_name
E.order by 2 desc;
Ans C.
Group functions cannot appear in the WHERE clause.
9. Your HR department wants to recognize the most senior employees in each department. You need to produce a report with the following requirements:
Display each department ID
For each department, show the earliest hire date
Show how many employees from each department were hired on the earliest hire date
Will all three requirements be met with the following SQL statement?
select department_id ,min(hire_date) ,count(*) keep (dense_rank last order by hire_date asc)
from hr.employees
group by department_id;
A. The statement meets all three requirements.
B. The statement meets two of the three requirements.
C. The statement meets one of the three requirements.
D. The statement meets none of the three requirements.
E. The statement will raise an exception.
Ans B.
The first two columns (lines 1 and 2) will meet the first two requirements, but the third column (lines 3 and 4) will report the number of employees with the most recent hire date. To report the number of employees with the oldest hire date, you need either count(*) keep (dense_rank first order by hire_date asc) or count(*) keep (dense_rank last order by hire_date desc). See Chapter 4 for more information about group functions.
10. The DEPT table has the following data.
SQL> SELECT * FROM dept;
DEPTNO DNAME LOC
---------- -------------- ----------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Consider this INSERT statement:
INSERT INTO (SELECT * FROM dept WHERE deptno = 10)VALUES (50, 'MARKETING', 'FORT WORTH');
Choose the best answer.
A. The INSERT statement is invalid; a valid table name is missing.
B. 50 is not a valid DEPTNO value, since the subquery limits DEPTNO to 10.
C. The statement will work without error.
D. A subquery and a VALUES clause cannot appear together.
Ans C.
The statement will work without error. Option B would be correct if you used the WITH CHECK OPTION clause in the subquery. See Chapter 5 for more information about subqueries.
11. At a minimum, how many join conditions should there be to avoid a Cartesian join if there are three tables in the FROM clause?
A. 1
B. 2
C. 3
D. There is no minimum.
Ans: B.
There should be at least n-1 join conditions when joining n tables to avoid a Cartesian join. To learn more about joins, see Chapter 5.
12. Which two of the following queries is valid syntax that would return all rows from the EMPLOYEES and DEPARTMENTS tables, even if there are no corresponding/related rows in the other table.
A. SELECT last_name, first_name, department_name FROM employees e FULL JOIN departments d ON e.department_id = d.department_id;
B. SELECT last_name, first_name, department_name FROM employees e OUTER JOIN departments d ON e.department_id = d.department_id;
C. SELECT e.last_name, e.first_name, d.department_name FROM employees e LEFT OUTER JOIN departments d ON e.department_id = d.department_id RIGHT OUTER JOIN employees f ON f.department_id = d.department_id;
D. SELECT e.last_name, e.first_name, d.department_nameFROM employees e CROSS JOIN departments d ON e.department_id = d.department_id;
E. SELECT last_name, first_name, department_name FROM employees FULL OUTER JOIN departments USING (department_id);
Ans: A, E.
An outer join on both tables can be achieved using the FULL OUTER JOIN syntax. The join condition can be specified using the ON clause to specify the columns explicitly or using the USING clause to specify columns with common column names. Options B and D would result in errors. In option B, the join type is not specified; OUTER is an optional keyword. In option D, CROSS JOIN is used to get a Cartesian result, and Oracle9i does not expect a join condition. To learn more about joins, read Chapter 5.
13. Why does the following statement fail?
CREATE TABLE FRUITS&VEGETABLES( NAME VARCHAR2 (40));
A. The table should have more than one column defined.
B. NAME is a reserved word, which cannot be used as a column name.
C. The table name is invalid.
D. Column length cannot exceed 30 characters.
Ans C. Table and column names can have only letters, numbers, and three special characters: dollar sign ($), underscore (_), and pound sign (#).
14. Which datatype stores data outside the Oracle database?
A. UROWID
B. BFILE
C. BLOB
D. NCLOB
E. EXTERNAL
Ans B.
The BFILE datatype stores only the locator to an external file in the database; the actual data is stored as operating system files. BLOB, NCLOB, CLOB, and BFILE are the LOB datatypes in Oracle9i. EXTERNAL is not a valid datatype.
15. Which of the following statements are true? (Choose all that apply.)
A. Primary key constraints allow NULL values in the columns.
B. Unique key constraints allow NULL values in the columns.
C. Primary key constraints do not allow NULL values in columns.
D. A nonunique index cannot be used to enforce a primary key
constraint.
Ans: B, C.
Primary key and unique key constraints can be enforced using nonunique indexes. Unique keys allow NULL values in the columns, but a primary key does not. See Chapter 7 for more information about constraints.
16. Which operation cannot be performed using the ALTER TABLE statement?
A. Rename table
B. Rename column
C. Drop column
D. Drop NOT NULL constraint
Ans:B.
You cannot rename a column in the table. To rename a column, you must re-create a table or create a view on the table with the new column name. See Chapter 7 for more information about modifying tables.
17. INTERVAL datatypes store a period of time. Which components are included in the INTERVAL DAY TO SECOND column? (Choose all that apply.)
A. Years
B. Quarters
C. Months
D. Days
E. Hours
F. Minutes
G. Seconds
H. Fractional seconds
Ans: D, E, F, G.
The INTERVAL DAY TO SECOND datatype is new to Oracle9i and is used to store an interval between two date/time components. See Chapter 7 for more information about Oracle9i datatypes.
18. Which of the following statements are true? (Choose all that apply.)
A. The TRUNCATE statement is used to selectively remove rows from table.
B. The TRUNCATE statement is used to remove all rows from a table.
C. Rows removed using the TRUNCATE command cannot be undone (rolled back).
D. The TRUNCATE statement drops the constraints and triggers associated with the table.
E. The TRUNCATE statement invalidates all the constraints and triggers associated with the table.
Ans: B, C.
You cannot specify a WHERE clause in the TRUNCATE statement; it removes all the rows in the table, releases the storage space (this is the default if you did not explicitly specify KEEP STORAGE), and does not drop or invalidate any of the dependent objects.
19. Which data dictionary view holds information about the columns in a view?
A. USER_VIEWS
B. USER_VIEW_COLUMNS
C. USER_TAB_COLUMNS
D. USER_ALL_COLUMNS
Ans C.
USER_VIEWS shows the SQL used to create the view. The view columns are in the USER_TAB_COLUMNS view. The view USER_UPDATABLE_COLUMNS will show the columns of the view that can be updated. See Chapter 8 for more information about views.
20. The primary key of the STATE table is STATE_CD. The primary key of the CITY table is STATE_CD and CITY_CD. The STATE_CD column of the CITY table is the foreign key to the STATE table. There are no other constraints on these two tables. Consider the following view definition.
CREATE OR REPLACE VIEW state_city
AS SELECT a.state_cd, a.state_name, b.city_cd, b.city_name
FROM state a, city b
WHERE a.state_cd = b.state_cd;
Which of the following operations are permitted on the base tables of the view? (Choose all that apply.)
A. Insert a record into the CITY table
B. Insert a record into the STATE table
C. Update the STATE_CD column of the CITY table
D. Update the CITY_CD column of the CITY table
E. Update the CITY_NAME column of the CITY table
F. Update the STATE_NAME column of the STATE table
Ans: D, E.
In the join view, CITY is the key-preserved table. You can update the columns of the CITY table, except STATE_CD, because STATE_CD is not part of the view definition (the STATE_CD column in the view is from the STATE table). Since we did not include the STATE_CD column from the CITY table, no INSERT operations are permitted (STATE_CD is part of the primary key). If the view were defined as follows, all the columns of the CITY table would have been updatable, and new records could be inserted into the CITY table.
CREATE OR REPLACE VIEW state_city AS
SELECT b.state_cd, a.state_name, b.city_cd, b.city_name
FROM states a, cities b
WHERE a.state_cd = b.state_cd;
See Chapter 8 for more information about views.
Note by Denis:
This question seems missing a condition. That is the operations are performed through the view.
A table in the join view is key-preserved, if the primary and unique keys of the table are unique on the view's result set.
21. In Oracle9i, outer join syntax can be specified using the LEFT JOIN or RIGHT JOIN keywords or by using the (+) operator. Suppose that you have the two tables PRODUCTS and ORDERS. You need to get the ORDER# and PRODUCT# for all orders, even if there is no order placed for a particular product; that is, you want to get all of the rows from the PRODUCTS table. The PRODUCT# column is common to both tables. Which condition would return the desired result?
A. WHERE PRODUCTS.PRODUCT# = ORDERS.PRODUCT#
B. WHERE PRODUCTS.PRODUCT# (+) = ORDERS.PRODUCT#
C. WHERE PRODUCTS.PRODUCT# = ORDERS.PRODUCT# (+)
D. WHERE PRODUCTS.PRODUCT# (+) = ORDERS.PRODUCT# (+)
A (+) is specified after the column name of the table where there may not be a corresponding row. Since we want to get all rows from the PRODUCTS table, the outer-join operator is placed beside the column names of the ORDERS table. See Chapter 5 for more information about joins.
Ans: C.
---
22. Oracle9i supports the ISO SQL99 standard for specifying joins in queries. Which keywords are used to specify a Cartesian join using this syntax?
A. NATURAL JOIN
B. OUTER JOIN
C. INNER JOIN
D. CROSS JOIN
CROSS JOIN specifies a Cartesian join. A Cartesian join occurs when you do not have a common column to join two tables. All combinations of all rows from both tables will be retrieved. If Table A has m rows and Table B has n rows, a Cartesian join would retrieve m × n rows. See Chapter 5 for more information about Cartesian joins.
Ans: D
------
23. Outer joins in Oracle9i can be specified using the syntax
No comments:
Post a Comment