Total Pageviews

July 8, 2015

7/08/2015 10:14:00 PM
Oracle SQL Interview Questions Part 4

1:
You need to display the last names of those employees who have the letter "A" as the second character in their names.
Which SQL statement displays the required results?

A. SELECT last_name FROM EMP
WHERE last_ name LIKE '_A%';
B. SELECT last_name
FROM EMP
WHERE last name ='*A%'
C. SELECT last_name FROM EMP
WHERE last name ='_A%';
D. SELECT last_name FROM EMP
WHERE last name LIKE '*A%'

Answer: A

Explanation:

Statement in this answer will show correct results because usage of operator LIKE and format mask '_A%' extract the last names of those employees
who have the letter "A" as the second character in their names. Symbol '_' in format mask substitute exactly one symbol and cannot be NULL.

Incorrect Answers

B: This statement will return only names starting from symbol '*'. It cannot be used as substitution symbol.
C: Usage of equity operator here is not appropriate in this case: query will look exact for first symbol '_', it will not be considered as substitution symbol.
D: This statement will return only names starting from symbol '*'. It cannot be used as substitution symbol. OCP Introduction to Oracle 9i: SQL Exam Guide, Jason

QUESTION 2

You need to perform certain data manipulation operations through a view called EMP_DEPT_VU, which you previously created.

You want to look at the definition of the view (the SELECT statement on which the view was create.) How do you obtain the definition of the view?

A. Use the DESCRIBE command in the EMP_DEPT VU view.
B. Use the DEFINE VIEW command on the EMP_DEPT VU view.
C. Use the DESCRIBE VIEW command on the EMP_DEPT VU view.
D. Query the USER_VIEWS data dictionary view to search for the EMP_DEPT_VU view.
E. Query the USER_SOURCE data dictionary view to search for the EMP_DEPT_VU view.
F. Query the USER_OBJECTS data dictionary view to search for the EMP_DEPT_VU view.

Answer: D

Explanation:

To look on the view definition you need to query the USER_VIEWS data dictionary view and search for the EMP_DEPT_VU view.

Incorrect Answers
A: You cannot see the definition of the view using the DESCRIBE command.
B: There is no DEFINE VIEW command in Oracle.
C: There is no DESCRIBE VIEW command in Oracle.
E: You cannot use the USER_SOURCE data dictionary view to see the definition of your view: it is used to store system objects definitions only.
F: You can find record about view in the USER_OBJECTS, but it does not contain the definition of the view itself.


QUESTION 3:

Evaluate this SQL statement:

SELECT e.EMPLOYEE_ID,e.LAST_NAME,e.DEPARTMENT_ID, d.DEPARTMENT_NAME FROM EMP e, DEPARTMENT d
WHERE e.DEPARTMENT_ID = d.DEPARTMENT_ID;
In the statement, which capabilities of a SELECT statement are performed?

A. Selection, projection, join
B. Difference, projection, join
C. Selection, intersection, join
D. Intersection, projection, join
E. Difference, projection, product

Answer: A

Explanation:

Selection, projection and join capabilities of a SELECT statement are performed in this view. Incorrect Answers
B: Selection is performed in this query, not difference. There is no capability with name difference for a SELECT statement exists.
C: There is no intersection in this SELECT statement used.
D: There is no intersection in this SELECT statement used.
E: There is no difference or product capabilities exist for a SELECT statement.

QUESTION 4:

Which two are character manipulation functions? (Choose two.)

A. TRIM
B. REPLACE
C. TRUNC
D. TO_DATE
E. MOD
F. CASE

Answer: A, B

Explanation:

TRIM() and REPLACE() are character manipulation functions.
Incorrect Answers
C: TRUNC(x,y) is arithmetic function, it truncates x to the decimal precision of y. If y is negative, it truncates to y number of places to the left of the decimal point. This can also be used on DATE columns.
D: TO_DATE(x,[y]) function converts the non-date value x to a date using the format specified by y.
E: MOD(x,y) is arithmetic function, the modulus of x, defined in long division as the integer remainder when x divided by y until no further whole number can be produced.
F: There is no character manipulation function CASE in Oracle.

QUESTION 5:

Which three statements correctly describe the functions and use of constraints? (Choose three.)

A. Constraints provide data independence.
B. Constraints make complex queries easy.
C. Constraints enforce rules at the view level.
D. Constraints enforce rules at the table level.
E. Constraints prevent the deletion of a table if there are dependencies.
F. Constraints prevent the deletion of an index if there are dependencies.

Answer: C, D, E

Explanation:

Constraints have functions to enforce rules at the view and table levels and to prevent the deletion of data if dependencies exist between tables.
Incorrect Answers
A: Constraints are used to put dependencies on data.
B: Constrains are not used to make complex queries more easy.
F: Constraints does not prevent the deletion of an index if there are dependencies.

QUESTION 6:

You define a multiple-row subquery in the WHERE clause of an SQL query with a comparison operator "=".

What happens when the main query is executed?

A. The main query executes with the first value returned by the subquery.
B. The main query executes with the last value returned by the subquery.
C. The main query executes with all the values returned by the subquery.
D. The main query fails because the multiple-row subquery cannot be used with the comparison operator.
E. You cannot define a multiple-row subquery in the WHERE clause of a SQL query.

Answer: D

Explanation:

The main query fails because the multiple-row sub-query cannot be used with the comparison operator. Only single-row query can use comparison operators, like =, <, >, <=, >, and <>.
Incorrect Answers
A: The main query fails because the multiple-row sub-query cannot be used with the comparison operator.
B: The main query fails because the multiple-row sub-query cannot be used with the comparison operator.
C: The main query fails because the multiple-row sub-query cannot be used with the comparison operator.
E: You can define a multiple-row sub-query in the WHERE clause of a SQL query, but error will be generated by different reason.

Chapter 4: Subqueries

QUESTION 7:

You need to calculate the total of all salaries in the accounting department. Which group function should you use?
A. MAX
B. MIN
C. SUM
D. COUNT
E. TOTAL
F. LARGEST

Answer: C

Explanation:

Function SUM(x) calculates the sum of all values in column x in all rows returned by the SELECT statement. Incorrect Answers
A: Function MAX(x) determines the maximum value in column x for all rows returned by the SELECT statement.
B: Function MIN(x) determines the minimum value in column x for all rows returned by the SELECT statement.
D: Function COUNT(x) counts the number of non-NULL values returned by the SELECT statement for column
x.

E: There is no TOTAL() function in Oracle.
F: There is no LARGEST() function in Oracle.

QUESTION 8:

What is true about joining tables through an equijoin?

A. You can join a maximum of two tables through an equijoin.
B. You can join a maximum of two columns through an equijoin.
C. You specify an equijoin condition in the SELECT or FROM clauses of a SELECT statement.
D. To join two tables through an equijoin, the columns in the join condition must be primary key and foreign key columns.
E. You can join n tables (all having single column primary keys) in a SQL statement by specifying a minimum of n-1 join conditions.

Answer: E

Explanation:


For N joined tables using Oracle or ANSI/ISO syntax for table joins, you need at least N-1 equijoin conditions in the WHERE clause of your
SELECT statement or N-1 JOIN table_name ON join_condition clauses in order to avoid a Cartesian product, respectively.

Incorrect Answers
A: There is no maximum on two tables to join them through an equijoin.
B: There is no maximum on two columns to join them through an equijoin.
C: You can specify an equijoin condition only in the FROM clauses of a SELECT statement.
D: There is no limitation about primary key and foreign key for the columns to use them for an equijoin. OCP Introduction to Oracle 9i: SQL Exam Guide, Jason QUESTION 9:

Scott issues the SQL statements: CREATE TABLE dept

(deptno NUMBER(2), dname VARCHAR2(14), loc VARCHAR2(13)};
GRANT SELECT
ON DEPT
T0 SUE;
If Sue needs to select from Scott's DEPT table, which command should she use?

A. SELECT * FROM DEPT;
B. SELECT *
FROM SCOTT. DEPT;
C. SELECT *
FROM DBA.SCOTT DEPT;
D. SELECT *
FROM ALL_USERS
WHERE USER_NAME = 'SCOTT'
AND TABLE NAME = 'DEPT';

Answer: B

Explanation:
If the table doesn't exist in your schema, you must prefix the table name with the schema information, separating the owner from the table name with a period.
Incorrect Answers
A: If you don't have DEPT table in your schema, this statement will fail.
C: This statement is incorrect.
D: This statement is incorrect. ALL_USERS view is used to extract information about users.

 
Related Posts Plugin for WordPress, Blogger...