Category: sql Certificate

  • Khóa học miễn phí SQL – Subqueries to Solve Queries nhận dự án làm có lương

    SQL – Subqueries to Solve Queries Questions



    1. Which of the following are the types of sub-queries?

    1. Ordered sub-queries
    2. Grouped sub-queries
    3. Single row sub-queries
    4. None of the above

    Answer: C. A subquery is a complete query nested in the SELECT,FROM, HAVING, or WHERE clause of another query.The subquery must be enclosed in parentheses and have a SELECT and a FROM clause, at a minimum. Single row sub-queries and multi-row sub-queries are the main types of sub-queries

    2.Which of the following is true about sub-queries?

    1. They execute after the main query executes
    2. They execute in parallel to the main query
    3. The user can execute the main query and then, if wanted, execute the sub-query
    4. They execute before the main query executes.

    Answer: D. The sub-query always executes before the execution of the main query.Subqueries are completed first.The result of the subquery is used as input for the outer query.

    3.Which of the following is true about the result of a sub-query?

    1. The result of a sub-query is generally ignored when executed.
    2. The result of a sub-query doesn”t give a result, it is just helpful in speeding up the main query execution
    3. The result of a sub-query is used by the main query.
    4. The result of a sub-query is always NULL

    Answer: C. Subqueries are completed first.The result of the subquery is used as input for the outer query.

    4.Which of the following clause is mandatorily used in a sub-query?

    1. SELECT
    2. WHERE
    3. ORDER BY
    4. GROUP BY

    Answer: A. A sub-query is just like any other query which has to start with a SELECT clause. They are contained within an outer query.

    5. Which of the following is a method for writing a sub-query in a main query?

    1. By using JOINS
    2. By using WHERE clause
    3. By using the GROUP BY clause
    4. By writing a SELECT statement embedded in the clause of another SELECT statement

    Answer: D. A subquery is a complete query nested in the SELECT, FROM, HAVING, or WHERE clause of another query.The subquery must be enclosed in parentheses and have a SELECT and a FROM clause, at a minimum.

    6.In the given scenarios, which one would appropriately justify the usage of sub-query?

    1. When we need to sum up values
    2. When we need to convert character values into date or number values
    3. When we need to select rows from a table with a condition that depends on the data from the same or different table.
    4. None of the above

    Answer: C.

    7.In which of the following clauses can a sub-query be used?

    1. HAVING
    2. WHERE
    3. FROM
    4. All of the above

    Answer: D. A sub-query is not different from a normal query. It can make use of all the primary clauses of a SELECT statement.

    8.Which of the following single-row operators can be used for writing a sub-query?

    1. >=
    2. <
    3. =
    4. All of the above

    Answer: D. Single-row operators include =, >, <, >=, <=, and <>.

    9.Which of the following multi-row operators can be used with a sub-query?

    1. IN
    2. ANY
    3. ALL
    4. All of the above

    Answer: D. Multiple-row subqueries return more than one row of results.Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.

    10.What is true about the output obtained from a sub-query?

    1. It remains in the buffer cache
    2. It remains inside the sub-query and can be used later when needed
    3. It is used to complete the outer (main) query
    4. Both A and C

    Answer: C. Subqueries are completed first.The result of the subquery is used as input for the outer query.

    11.You need to find the salaries for all the employees who have a higher salary than the Vice President of a company ”ABC”.Which of the following queries will give you the required result? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1.  SELECT first_name, last_name, salary
      FROM employees
      WHERE salary > (SELECT salary
      FROM employees
      WHERE job_id = ''VICE-PRESIDENT''); 
    2. SELECT first_name, last_name, salary
      FROM employees
      WHERE salary = (SELECT salary
      FROM employees
      WHERE job_id = ''VICE-PRESIDENT''); 
    3. SELECT first_name, last_name, salary
      FROM employees
      WHERE job_id = ''VICE-PRESIDENT''); 
    4. None of the above

    Answer: A. In the option ”A”, the inner sub-query gives the VP”s salary as a result to the outer query.

    12.What among the following is true about sub-queries?

    1. Sub-queries can be written on either side of a comparison operator
    2. Parenthesis is not mandatory for sub-queries
    3. Single-row sub-queries can use multi-row operators but vice versa is not possible
    4. All of the above

    Answer: A. Sub queries can be placed on left or right hand side of the comparison operator depending on the query indentation and usability.

    13. What will be the outcome of the following query? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT first_name, last_name, salary
    FROM employees
    WHERE salary ANY (SELECT salary FROM employees); 
    1. It executes successfully giving the desired results
    2. It executes successfully but does not give the desired results
    3. It throws an ORA error
    4. It executes successfully and gives two values for each row obtained in the result set

    Answer: C. Multi-row operators cannot be used in single-row sub-queries and vice versa.

    14.Which of the following is true about single-row sub-queries?

    1. They give one result from the main query
    2. They give only one row in the result set
    3. They return only one row from the inner SELECT statement
    4. They give multiple rows from the main (outer) query

    Answer: C. A single-row subquery can return a maximum of one value.

    15.What is true about multi-row sub-queries?

    1. They can return more than one column as the result of the inner query
    2. They return multiple rows in the main query but only a single result set in the inner query
    3. They return single row in the main query but multiple rows in the inner sub-query
    4. They return more than one row from the inner SELECT statement

    Answer: D. Multi-column sub-queries return more than one column in their result set, multi-row sub-queries return more than one row from the inner query.

    16.What among the following is true about single-row sub-queries?

    1. They return only one row
    2. They use single-row operators
    3. Both A and B
    4. None of the above

    Answer: C.

    17.Which of the following operators cannot be used in a sub-query?

    1. AND
    2. <
    3. >
    4. <>

    Answer: A. Single-row operators include =, >, <, >=, <=, and <>. Multi-row operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.

    Examine the exhibit and answer the questions 18 to 21 that follow.

    Table EMPLOYEES Table DEPARTMENTS

    18.You need to find out the names of all employees who belong to the same department as the employee ”Jessica Butcher” who is in department 100 and has an employee ID 40. Which of the following queries will be correct?

    1. SELECT first_name, last_name
      FROM employees
      WHERE last_name = ''Butcher''
      And first_name = ''Jessica 
    2. SELECT first_name, last_name
      FROM employees
      WHERE department =100; 
    3. SELECT first_name, last_name
      FROM employees
      WHERE department  = (SELECT department
      FROM employees
      WHERE first_name = ''Jessica''
      AND last_name = ''Butcher''); 
    4. SELECT first_name, last_name
      FROM employees
      WHERE department  = (SELECT department
      FROM employees
      WHERE first_name = ''Jessica''
      AND last_name = ''Butcher''
      AND department = 100
      AND employee_id = 40); 

    Answer: D. ”D” is more appropriate than ”C” because it filters on employee id which is unique and ensures that the sub-query will return single row only. ”C” can fail if there are more than one employee with the same first and last name.

    19.You need to find out the employees which belong to the department of ”Jessica Butcher” and have salary greater than the salary of ”Jessica Butcher” who has an employee ID of 40. Which of the following queries will work?

    1. SELECT first_name, last_name
      FROM employees
      WHERE last_name = ''Butcher''
      AND first_name = ''Jessica''
      AND salary > 10000; 
    2. SELECT first_name, last_name
      FROM employees
      WHERE department = 100; 
    3. SELECT first_name, last_name
      FROM employees
      WHERE department = (SELECT department
      			FROM employees
      			WHERE first_name = ''Jessica''
      			AND last_name = ''Butcher''
      			AND employee_id = 40)
      AND salary > (SELECT salary
      			 FROM employees
      			 WHERE first_name = ''Jessica''
      			 AND last_name = ''Butcher''
      			 AND employee_id = 40); 
    4. SELECT first_name, last_name
      FROM employees
      WHERE department  = (SELECT department
      			FROM employees
      			WHERE first_name = ''Jessica''
      			AND last_name = ''Butcher''
      			AND department = 100); 

    Answer: C. More than one sub-query can be written in one SQL statement to add more than one condition.

    20.Based on the answers for questions 18th and 19th, what type of sub-queries is used by them?

    1. Single row sub-query
    2. Multiple row sub-query
    3. Both A and B
    4. Inline sub-query

    Answer: A. The questions 18th and 19th given above demonstrate the usage sub-queries in a SELECT statement.

    21.Consider two statements about outer and inner queries in context of SQL sub-queries?

    i. The inner queries can get data from only one table

    ii. The inner queries can get data from more than one table

    Which of the above statements are true?

    1. (i)
    2. (ii)
    3. Both (i) and (ii)
    4. Neither (i) nor (ii)

    Answer: B. Sub-queries can fetch data from more than one table.

    Examine the table structure as follows and answer the questions 22 to 27 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    22.What will be the outcome of the following query? (Choose the most appropriate answer)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT last_name, job_id, salary
    FROM employees
    WHERE salary = (SELECT max(salary)
    FROM employees); 
    1. It executes successfully and gives the employees who have salaries equal to the max salary.
    2. It executes successfully but does not give the required results
    3. It throws an error as a group function is used in the sub-query
    4. It throws an error as a single row sub-query should contain a multi-row operator

    Answer: A. A group function can be used within a sub-query.

    23.What will be the outcome of the query that follows?

    SELECT first_name, last_name, min(salary)
    FROM employees
    GROUP BY department_id
    HAVING MIN(salary) >
    		(SELECT min(salary)
    		FROM employees
    		WHERE department_id = 100); 
    1. It executes successfully and gives the names and minimum salary greater than department 100 of all employees
    2. It executes successfully and gives the salaries of the employees in department 100
    3. It executes successfully and gives the names and minimum salaries of all the employees.
    4. It throws an error.

    Answer: A. HAVING clause can be used in sub-queries as shown

    24.You need to find the job which has a maximum average salary.Which of the following queries will give you the required results?

    1. SELECT job_id, avg(salary)
      FROM employees
      GROUP BY job_id; 
    2. SELECT job_id, avg(salary)
      FROM employees
      GROUP BY job_id
      HAVING job_id in (SELECT max(avg(salary) FROM employees); 
    3. SELECT job_id, avg(salary)
      FROM employees
      GROUP BY job_id
      HAVING max(avg(salary) in (SELECT max(avg(salary) FROM employees); 
    4. SELECT job_id, avg(salary)
      FROM employees
      GROUP BY job_id
      HAVING avg(salary) in (SELECT max(avg(salary) FROM employees GROUP BY job_id); 

    Answer: D. Sub-queries can make use of group functions and HAVING clause to restrict the groups.

    25.The following query throws an error. Choose the correct reason for the error as given in the options.

    SELECT first_name, last_name
    FROM employees
    WHERE commission_pct  = (SELECT min(commission_pct )
              FROM employees
              GROUP BY department_id); 
    1. The GROUP BY clause is not required in the sub-query
    2. A function cannot be used in a sub-query SELECT statement
    3. The single row sub-query gives multiple records
    4. The use of “=” operator is invalid; an IN operator will work correctly

    Answer: C, D. The GROUP BY clause gives the minimum commission_pct for each department and hence multiple results are fetched to the main query giving an error.

    26.Consider the query given below.How many records will be returned as a result of the above query? (Assuming the no employee with job id XX exists in the company)

    SELECT first_name, last_name
    FROM employees
    WHERE salary = (SELECT salary
    		FROM employees
    		WHERE job_id = ''XX'');
    
    1. 1
    2. NULL
    3. 0
    4. The query raises ORA error because sub-query is invalid.

    Answer: C. Since there is no employee with job_id “XX” in the company, the sub-query returns no result, which when equated to job_id in the main query gives a 0.

    27.What happens if the WHERE condition in the query given in question 26 is replaced with a new one (WHERE job_id IS NOT NULL)? (Assume the number of records in ”employees” table is 14).

    1. 1
    2. 14
    3. 0
    4. ORA error

    Answer: D. The query execution raises the exception “ORA-01427: single-row subquery returns more than one row”.

    28.Which of the following are valid multi row operators used for sub-queries?

    1. <=
    2. ANY >=
    3. !=
    4. >=

    Answer: B. Multiple-row subqueries return more than one row of results.Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.The multi row operators IN, ANY, ALL must be used with single row operators as shown in the option B.

    Examine the table structure as given. Consider the query given below and answer the questions 29 to 33 that follow

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT first_name, last_name, salary, commission_pct
    FROM employees
    WHERE salary < ANY  (SELECT salary
    		FROM employees
    		WHERE department_id  = 100)
    AND department_id  <> 101; 

    29.What does the ANY operator evaluates to in the above query?

    1. TRUE
    2. FALSE
    3. NULL
    4. 0

    Answer: A. The multi row operators return Boolean results. As there are results of salary in the department 100, it returns TRUE. If there are 0 results, it evaluates to FALSE.

    30.What will be the outcome of the query if we assume that the department 100 has only one employee?

    1. It executes successfully giving the one result
    2. It executes successfully giving salaries of all the employees
    3. NULL
    4. It throws an ORA error

    Answer: D. If the department 100 has one result (single row sub-query), the < ANY operator gives the error as it is a multi-row operator.

    31.What will be the outcome of the query given above if the < ANY operator is replaced with = ANY operator?

    1. Oracle will treat each value of the salary returned from the sub-query as it does with IN operator
    2. There will be no difference in the results
    3. The results will differ
    4. The execution will thrown an ORA error

    Answer: A. = ANY operator is equivalent to IN operator.

    32.What can be said about the < ANY operator in the query given above?

    1. It gives the maximum value of salary
    2. It gives the minimum value of salary
    3. It means it gives the values that are lesser than the highest
    4. None of the above

    Answer: C. The multi row operator < ANY evaluates to the statements “Less than the maximum” of the subquery. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”< ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery

    <

    33.Assume that the < ANY operator is replaced with the > ANY. What is true about this operator?

    1. It gives the maximum salary
    2. It finds only the maximum salary from the sub-query
    3. It gives more than the minimum salary
    4. It gives the minimum salary

    Answer: C. The multi row operator > ANY evaluates to the statements “Greater than the minimum” of the subquery. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”> ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery

    <

    34. Examine the given table structure and consider the following query:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id, first_name, last_name
    FROM employees
    WHERE salary IN (SELECT max(salary)
    		FROM employees
    		GROUP BY department_id );
    

    Which WHERE clause among the following is equivalent to that given in the above query? (Assume that the salaries are 2500, 3000, 3500,4000)

    1. WHERE salary < ANY (SELECT max(salary)
      			FROM employees
      			GROUP BY department_id ); 
    2. WHERE salary < ALL (SELECT max(salary)
      			FROM employees
      			GROUP BY department_id ); 
    3. WHERE salary = (SELECT max(salary)
      			FROM employees
      			GROUP BY department_id ); 
    4. WHERE salary IN (2500,3000,3500,4000); 

    Answer: D. When the IN operator is used, Oracle treats individual results of the sub-query as shown in the option D.

    Examine the structure of the EMPLOYEES table as given below and answer the questions 35 to 37 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    <

    35. You need to find out which of the employees have a salary less than that of the salary for the job ID ”FIN_ACT”. Which of the following queries will give you the required output?

    1. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary < ALL
      		(SELECT salary
      		 FROM employees
      		 WHERE job_id = ''FIN_ACT'')
      		 AND job_id <> ''FIN_ACT 
    2. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary > ALL
      		(SELECT salary
      		FROM employees
      		WHERE job_id = ''FIN_ACT'')
      		AND job_id <> ''FIN_ACT 
    3. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary < ANY
      		(SELECT salary
      		FROM employees
      		WHERE job_id = ''FIN_ACT'')
      		AND job_id <> ''FIN_ACT 
    4. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary = 	(SELECT salary
      		FROM employees
      		WHERE job_id = ''FIN_ACT'')
      		AND job_id <> ''FIN_ACT 

    Answer: A. < ALL means less than the minimum. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”> ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery

    36.What will be the outcome of the above query (the option A in the question above), if the < ALL is replaced with the >ALL?

    1. It will execute successfully giving the same result.
    2. It will throw an ORA error
    3. It will execute successfully but give the employees” details who have salaries lesser than all the employees with job_id ”FI_ACCOUNTANT”.
    4. None of the above

    Answer: C. >ALL means less than the minimum. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”> ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery

    37.You need to find the salaries for all employees who are not in the department 100. Which of the following queries will give you the required result?

    1. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary !=ALL
      		(SELECT salary
      		FROM employees
      		WHERE department_id  = 100)
      		AND department_id  <> 100; 
    2. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary NOT IN
      		(SELECT salary
      		FROM employees
      		WHERE department_id  = 100)
      		AND department_id  <> 100; 
    3. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary NOT ALL
      		(SELECT salary
      		FROM employees
      		WHERE department_id  = 100)
      		AND department_id  <> 100; 
    4. SELECT employee_id, first_name, last_name
      FROM employees
      WHERE salary != (SELECT salary
      		FROM employees
      		WHERE department_id  = 100)
      		AND department_id  <> 100; 

    Answer: C. NOT can be used with the multi row operators IN, ANY and ALL.

    Examine the table structure as given. Consider the following query and answer the questions 38 and 39 that follow. You need to find the employees who do not have a sub-ordinate reporting to them. (Assume there are 0 expected results)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT first_name, last_name
    FROM employees
    WHERE employee_id NOT IN
    		(SELECT manager_id
    		FROM employees); 

    38.What will be the result of the query given above?

    1. 10
    2. NULL
    3. ORA error
    4. 0

    Answer: D. One of the values in the inner sub-query is NULL (all employees are not managers!)

    39.Which of the following WHERE clauses should be added / modified to the above query to give the expected results?

    1. WHERE employee_id != (SELECT manager_id FROM employees); 
    2. WHERE employee_id IN (SELECT manager_id FROM employees);  
    3. WHERE employee_id <>ALL (SELECT manager_id FROM employees); 
    4. WHERE employee_id NOT IN (SELECT manager_id
      			FROM employees
      			WHERE manager_id is NOT NULL); 

    Answer: B, D. If the sub-query is likely to have NULL values, do not use the NOT IN operator or if using, modify the sub-query with an additional WHERE clause (option D)

    40.What is true about sub-queries in general?

    1. Sub-queries have to be executed separately from the main queries
    2. Sub-queries can be executed at the will of the user, they are not related to the main query execution
    3. Sub-queries are equal to two sequential queries where the results of inner query are used by the main query
    4. All of the above

    Answer: C.

    41. Which of the following is true about sub-queries?

    1. A sub-query can return 0 or more rows
    2. A sub-query can be used only in the SELECT clause
    3. Nesting of sub-queries is limited to 2 levels
    4. Group functions cannot be used in sub-queries

    Answer: A. A subquery is a complete query nested in the SELECT, FROM, HAVING, or WHERE clause of another query. The subquery must be enclosed in parentheses and have a SELECT and a FROM clause, at a minimum. A single-row subquery can return a maximum of one value. Multiple-column subqueries return more than one column to the outer query.

    42. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Consider the following query.

    SELECT first_name, last_name
    FROM employees
    WHERE employee_id NOT IN
    		(SELECT manager_id, hire_date
    		FROM employees
    		WHERE manager_id is not null); 

    This query returns an error. What is the reason for error?

    1. The NOT IN operator used is invalid
    2. The WHERE clause in the sub-query is incorrectly written
    3. The column in the sub-query SELECT clause should only be one when there”s an inequality used in the main query
    4. The sub-query uses the same table as the main query

    Answer: C. The columns selected in the sub-query should be same as on the other side of comparison operator. Any inequality of data type or number of columns would result in an ORA error.

    43.A report has to be extracted which displays all the departments that have one or more employees assigned to them. Which of the following queries will give the required output? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT department_name
      FROM employees
      WHERE department_id  IN (SELECT distinct (department_id )
      			FROM employees); 
    2. SELECT department_name
      FROM employees
      WHERE department_id  ANY (SELECT distinct (department_id )
      			FROM employees); 
    3. SELECT department_name
      FROM employees
      WHERE department_id  < ANY (SELECT distinct (department_id )
      			FROM employees); 
    4. SELECT department_name
      FROM employees
      WHERE department_id  = ANY (SELECT distinct (department_id )
      			FROM employees); 

    Answer: A, D.

    44.What is the maximum level of sub-queries allowed in Oracle in a single SQL statement?

    1. 20
    2. 50
    3. Unlimited
    4. 255

    Answer: D. Oracle supports the Nesting of queries to 255 levels.

    45. What should be the best practice to follow when we know what values we need to pass on to the main query in Oracle queries?

    1. Using GROUP BY
    2. Using sub-queries
    3. Using HAVING
    4. None of the above

    Answer: D. It might become possible that the sub-queries give a NULL result, which results in 0 rows in the main result; hence it is a good practice to use them only if we know what values we need.

    Examine the table structure as given. Consider the following query and answer the questions 46 and 47 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id, first_name, last_name, job_id
    FROM employees
    WHERE job_id = (SELECT job_id FROM employees); 

    46.You need to find all the employees whose job ID is the same as that of an employee with ID as 210. Which of the following WHERE clauses would you add / modify to achieve this result? (Consider the table structure as given

    1. WHERE job_id = (SELECT job_id FROM employees WHERE employee_id = 210); 
    2. WHERE job_id IN (SELECT job_id FROM employees WHERE employee_id = 210); 
    3. WHERE job_id > (SELECT job_id FROM employees WHERE employee_id = 210); 
    4. WHERE job_id >= (SELECT job_id FROM employees WHERE employee_id = 210); 

    Answer: A.

    47.Assume that you change the WHERE clause as given in the option A in question 46 as the following.

    WHERE job_id = (SELECT job_id FROM employees WHERE employee_id < 210); 

    What will be the outcome of this change?

    1. The results will be the same
    2. ORA error thrown on execution
    3. The results will differ
    4. The query will execute successfully giving 0 rows.

    Answer: B. The sub-query gives more than one result on the given change and hence a multi row operator should replace the “=” in the main query given above.

    48.Examine the table structures as shown in the exhibit below.

    Table EMPLOYEES Table GRADE

    You need to display the names of the employees who have the highest salary. Which of the following SQL statements will be correct?

    1. SELECT first_name, last_name, grade
      FROM employees, grade
      WHERE (SELECT max (salary) FROM employees) BETWEEN losal and hisal; 
    2. SELECT first_name, last_name, grade
      FROM employees, grade
      WHERE (SELECT max (salary) FROM employees) BETWEEN losal and hisal
      AND salary BETWEEN losal and hisal; 
    3. SELECT first_name, last_name, grade
      FROM employees, grade
      WHERE salary = (SELECT max (salary) FROM employees)
      AND salary BETWEEN losal and hisal; 
    4. SELECT first_name, last_name, grade
      FROM employees, grade
      WHERE salary IN (SELECT max (salary) FROM employees)
      AND max(salary) BETWEEN losal and hisal; 

    Answer: B, C. The sub-queries can be written on either side of the operator

    49.What is the sub-query in the FROM clause of an SQL statement? (Choose the most appropriate answer)

    1. Single row sub-query
    2. Multi row sub-query
    3. Inline View
    4. Co-related sub-query

    Answer: C. If a sub-query appears in the FROM clause of the SELECT statements,it forms an Inline view. Oracle internally creates a temporary view for the query execution.

    50.What is the maximum number of nesting level allowed in an Inline View type sub-query?

    1. 255
    2. 300
    3. 216
    4. Unlimited

    Answer: D. As there is no limit on the number of tables which can be joined, there is no limit on the number of inline view in a query.

    51.What is true about co-related sub-queries?

    1. The tables used in the main query are also used in a co-related sub-query
    2. The sub-queries which reference a column used in the main query are called co-related sub-queries
    3. The sub-queries which are written without parenthesis are called co-related sub-queries
    4. The sub-queries which mandatorily use different tables than those used in the main query are called co-related sub-queries

    Answer: B. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query while Uncorrelated subquery executes the subquery first and passes the value to the outer query.

    52.Which of the following statements cannot be parent statements for a sub-query?

    1. SELECT
    2. GROUP BY
    3. UPDATE
    4. DELETE

    Answer: B. The rest of the options can be in the main query (parent query) of a sub-query.

    53.What is true about a co-related sub-query?

    1. It is evaluated only once for the parent query
    2. It is evaluated only thrice for the parent query
    3. It is evaluated once for each row processed by the parent sub-query
    4. All of the above

    Answer: C. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query;and the EXISTS operator is used to test whether the relationship or link is present.

    54.Examine the given table structure. You need to write a query which returns the names of the employees whose salaries exceed their respective department”s average salary. Which of the following will work? (Choose the most appropriate answer)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT employee_id, first_name, last_name
      FROM employees e
      WHERE salary > (SELECT avg (salary)
      		FROM employees
      		WHERE e.department_id  = department_id )
      		ORDER BY department_id ; 
    2. SELECT employee_id, first_name, last_name
      FROM employees e
      WHERE salary > ANY (SELECT avg(salary)
      		FROM employees
      		WHERE e.department_id  = department_id )
      		ORDER BY department_id ; 
    3. SELECT employee_id, first_name, last_name
      FROM employees e
      WHERE salary = (SELECT avg(salary)
      		FROM employees
      		WHERE e.department_id  = department_id )
      		ORDER BY department_id ; 
    4. SELECT employee_id, first_name, last_name
      FROM employees e
      WHERE salary < ANY  (SELECT avg(salary)
      		FROM employees
      		WHERE e.department_id  = department_id )
      		ORDER BY department_id ; 

    Answer: A. Here the department ID is obtained, used to evaluate the parent query and if the salary in that row is greater than the average salary of the departments of that row, that result is returned.

    55.Examine the given table structure. Which of the following queries will display duplicate records in a table EMPLOYEES?

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT *
      FROM employees E
      WHERE exists (SELECT 1 FROM employees E1
      		WHERE E.employee_id = E1.employee_id); 
    2. SELECT *
      FROM employees E
      WHERE exists (SELECT 1 FROM employees E1
      		WHERE E.employee_id = E1.employee_id
      		AND E.ROWID < E1.ROWID); 
    3. SELECT *
      FROM employees E
      WHERE exists (SELECT 1 FROM employees E1
      		WHERE E.ROWID < E1.ROWID); 
    4. SELECT *
      FROM employees E
      WHERE = ANY (SELECT 1 FROM employees E1
      		WHERE E.employee_id = E1.employee_id
      		And E.ROWID < E1.ROWID); 

    Answer: A. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query;and the EXISTS operator is used to test whether the relationship or link is present. It can be used to find the duplicate rows in a table where duplicity is subjected to a column or set of columns.

    Examine the structures for the tables DEPARTMENTS and EMPLOYEES and answer the questions 56 and 57 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    56.Which of the following queries will display the system date and count of records in the DEPARTMENTS and EMPLOYEES table?

    1. SELECT sysdate,
      		(SELECT * FROM departments) dept_count,
      		(SELECT * FROM employees) emp_count
      FROM DUAL; 
    2. SELECT sysdate,
      		(SELECT count(*) FROM departments) dept_count,
      		(SELECT count(*) FROM employees) emp_count
      FROM DUAL
      GROUP BY department_id ; 
    3. SELECT sysdate,
      		(SELECT * FROM departments) dept_count,
      		(SELECT * FROM employees) emp_count
      FROM DUAL
      GROUP BY employee_id; 
    4. SELECT sysdate,
      		(SELECT count(*) FROM departments) dept_count,
      		(SELECT count(*) FROM employees) emp_count
      FROM DUAL; 

    Answer: D. A single-row subquery can also be nested in the outer query”s SELECT clause. In this case, the value the subquery returns is available for every row of output the outer query generates. Typically, this technique is used to perform calculations with a value produced from a subquery.

    57.Which of the following queries will tell whether a given employee is a manager in a Company ”XYZ”?

    1. SELECT employee_id, manager_id
      FROM employees A
      WHERE employee_id ANY (SELECT manager_id from employees B)
      ORDER BY manager_id desc; 
    2. SELECT employee_id, manager_id
      FROM employees A
      WHERE employee_id < ALL (SELECT manager_id from employees B)
    3. SELECT employee_id, manager_id
      FROM employees A
      WHERE employee_id IN (SELECT manager_id from employees B)
      ORDER BY manager_id desc; 
    4. SELECT employee_id, manager_id
      FROM employees A
      WHERE employee_id in (SELECT manager_id from employees B)
      GROUP BY department_id ; 

    Answer: C.

    Examine the exhibit and answer the question 58 that follows:

    Table EMPLOYEES Table DEPARTMENTS Table LOCATIONS

    58.Which of the following queries will give you maximum salary of an employee in a particular city?

    1. SELECT max (salary), city
      FROM
      (SELECT salary, department_id , loc, city
      FROM employees natural join departments natural join locations); 
    2. SELECT salary, city
      FROM
      (SELECT salary, department_id , loc, city
      FROM employees natural join departments natural join locations); 
    3. SELECT max (salary), city
      FROM
      (SELECT salary, department_id , loc, city
      FROM employees natural join departments natural join locations)
      GROUP BY city; 
    4. SELECT max (avg(salary)), city
      FROM
      (SELECT salary, department_id , loc, city
      FROM employees natural join departments natural join locations); 

    Answer: C. When a multiple-column subquery is used in the outer query”s FROM clause, it creates a temporary table that can be referenced by other clauses of the outer query. This temporary table is more formally called an inline view. The subquery”s results are treated like any other table in the FROM clause. If the temporary table contains grouped data, the grouped subsets are treated as separate rows of data in a table.

    Examine the table structures as given below.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    Consider the following query and answer the questions that 59 to 62 that follow.

    SELECT  department_name
    FROM departments d INNER JOIN employees e
    ON (d.employee_id = e.employee_id)
    GROUP BY department_name; 

    59.Which of the following queries can replace the above query by using sub-queries giving the same result?

    1. SELECT department_name
      FROM departments
      WHERE department_id  = ANY (SELECT department_id  FROM employees); 
    2. SELECT department_name
      FROM departments
      WHERE department_id  IN (SELECT distinct(department_id ) FROM employees); 
    3. SELECT department_name
      FROM departments
      WHERE department_id  = (SELECT distinct(department_id ) FROM employees); 
    4. SELECT department_name
      FROM departments
      WHERE department_id  ANY (SELECT distinct(department_id ) FROM employees); 

    Answer: A, B.

    60.Assume that the sub-query as shown in the query given above is modified to the following.

    (SELECT distinct (department_id ) FROM employees ORDER BY department_id ); 

    What will be the outcome as a result of this change? (Choose the most appropriate answer)

    1. It will order the department_id fetched from the sub-query and display them in ascending order
    2. It will throw an ORA error as the ORDER BY clause should be accompanied by the GROUP BY clause
    3. It will throw an ORA error because an ORDER BY clause cannot be used inside a sub-query
    4. It will execute successfully.

    Answer: C. A subquery, except one in the FROM clause, can”t have an ORDER BY clause.If you need to display output in a specific order, include an ORDER BY clause as the outer query”s last clause.

    61.Assume that the query given above is modified as the below one.

    SELECT department_name
    FROM departments
    WHERE department_id  = ANY (SELECT department_id  FROM employees)
    ORDER BY department_id  desc; 

    What will be the outcome as a result of this change? (Choose the most appropriate answer)

    1. It will order the department_id fetched from the sub-query and display them in ascending order
    2. It will order the department_id fetched from the sub-query and display them in descending order
    3. It will throw an ORA error because an ORDER BY clause cannot be used inside a sub-query
    4. None of the above

    Answer: D. A subquery, except one in the FROM clause, can”t have an ORDER BY clause.If you need to display output in a specific order, include an ORDER BY clause as the outer query”s last clause.

    62.Which of the following can be used to order results in a sub-query?

    1. ORDER BY
    2. HAVING
    3. GROUP BY
    4. All of the above

    Answer: C. By default, the GROUP BY clause performs ordering in a sub-query.

    Examine the exhibit below and answer the questions 63 to 65 that follow:

    Table AUDIT

    Consider the following query:

    SELECT au_id, au_title
    FROM audit
    WHERE au_details in (SELECT au_details
    		  FROM audit
    		  WHERE au_title like ''S%'')
    		  ORDER BY au_title; 

    63.What will be the outcome of the query given above?

    1. It gives all AU_ID and AU_TITLEs starting with the letter ”S%”
    2. It gives all AU_ID and AU_TITLEs starting with the letter ”S%” ordered by the titles in ascending order
    3. It throws an ORA error
    4. It returns a 0 value

    Answer: C. A column with a CLOB, BLOB, NCLOB or an ARRAY cannot be used in a sub-query.

    64. What will be the outcome of the following query?

    SELECT *
    FROM employees
    WHERE salary BETWEEN (SELECT max(salary)
    			FROM employees
    			WHERE department_id  = 100)
    AND (SELECT min(salary) FROM employees where department_id  = 100); 

    This query returns an error. What is the reason for the error?

    1. A GROUP BY clause should be used as the function MAX is used
    2. Both the sub-queries cannot use the same department ID in the same outer query
    3. BETWEEN operator cannot be used with a sub-query
    4. SELECT clause should have columns mentioned and not a asterix (*)

    Answer: C. The BETWEEN operator can be used within a sub-query but not with a sub-query.

    65.What is true about using NOT IN when writing queries with sub-queries in them?

    1. NOT IN ignores all the NULL values and gives only the NOT NULL values
    2. NOT IN puts all the NULL values at the last and gives the NOT NULL to be displayed first
    3. NOT IN should be not be used if a NULL value is expected in the result set
    4. NOT IN is just a negation of the operator IN and can be changed without any caveat.

    Answer: C. SQL handles NULL values in a different way and hence it is a good practice to avoid NOT IN if the result set might contain a NULL.

    Consider the following table structures and answer the questions 66 to 72 that follow:

    Table EMPLOYEES Table DEPARTMENTS

    66. You need to find out the names and IDs of the departments in which the least salary is greater than the highest salary in the department 10. Which of the following queries will give the required result.

    1. SELECT department_id , min(salary)
      FROM employees
      GROUP BY department_id
      HAVING min(salary) >
      		(
      		select max(salary)
      		FROM employees
      		where department_id  = 10
      		)
    2. SELECT department_id , min(salary)
      FROM employees
      GROUP BY department_id
      HAVING min(salary) > ANY
      		(
      		select max(salary)
      		FROM employees
      		)
    3. SELECT department_id , min(salary)
      FROM employees
      HAVING max(salary) < ANY
      		(
      		select min(salary)
      		FROM employees
      		where department_id  = 10
      		)
    4. SELECT department_id , min(salary)
      FROM employees
      GROUP BY department_id
      HAVING min(salary) > ALL
      		(
      		select max(salary)
      		FROM employees
      		where department_id  = 10
      		)

    Answer: A.

    67.Write a query to find the employees whose salary is equal to the salary of at least one employee in department of id 10. (Choose the best answer)

    1. SELECT employee_id, Salary
      FROM employees
      WHERE salary in
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    2. SELECT employee_id, Salary
      FROM employees
      WHERE salary =ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    3. SELECT employee_id, Salary
      FROM employees
      WHERE salary ALL
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    4. SELECT employee_id, Salary
      FROM employees
      WHERE salary  < ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)

    Answer: A, B.

    68.You need to find out all the employees who have salary greater than at least one employee in the department 10. Which of the following queries will give you the required output?

    1. SELECT employee_id, Salary
      FROM employees
      WHERE salary >= ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    2. SELECT employee_id, Salary
      FROM employees
      WHERE salary > ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    3. SELECT employee_id, Salary
      FROM employees
      WHERE salary < ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    4. SELECT employee_id, Salary
      FROM employees
      WHERE salary = ALL
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)

    Answer: B.

    69.You need to find out all the employees who have salary lesser than the salary of all the employees in the department 10. Which of the following queries will give you the required output?

    1. SELECT employee_id, Salary
      FROM employees
      WHERE salary > ALL
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    2. SELECT employee_id, Salary
      FROM employees
      WHERE salary =ALL
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    3. SELECT employee_id, Salary
      FROM employees
      WHERE salary < ALL
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)
    4. SELECT employee_id, Salary
      FROM employees
      WHERE salary < ANY
      		(
      		SELECT salary
      		FROM employees
      		where department_id  = 10
      		)

    Answer: C. Multiple-row subqueries return more than one row of results. Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.Multiple-column subqueries return more than one column to the outer query. The columns of data are passed to the outer query in the same order in which they”re listed in the subquery”s SELECT clause.

    70.You need to find out all the employees who have their manager and department matching with the employee having an Employee ID of 121 or 200. Which of the following queries will give you the required output?

    1. SELECT employee_id, manager_id,department_id
      FROM employees
      WHERE (manager_id,department_id ) = ANY
      		(
      		select manager_id,
      		department_id
      		FROM employees
      		where employee_id in (121,200)
      		)
    2. SELECT employee_id, manager_id,department_id
      FROM employees
      WHERE (manager_id,department_id ) < ANY
      		(
      		select manager_id,
      		department_id
      		FROM employees
      		where employee_id in (121,200)
      		)
    3. SELECT employee_id, manager_id,department_id
      FROM employees
      WHERE (manager_id,department_id ) > ANY
      		(
      		select manager_id,
      		department_id
      		FROM employees
      		where employee_id in (121,200)
      		)
    4. SELECT employee_id, manager_id,department_id
      FROM employees
      WHERE (manager_id,department_id ) in
      		(
      		select manager_id,
      		department_id
      		FROM employees
      		where employee_id in (121,200)
      		)

    Answer: A, D. Multiple-row subqueries return more than one row of results. Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS. Multiple-column subqueries return more than one column to the outer query. The columns of data are passed to the outer query in the same order in which they”re listed in the subquery”s SELECT clause.

    71.You need to find the department name of an employee with employee ID 200. Which of the following queries will be correct? (Choose the most appropriate answer)

    1. SELECT employee_id, first_name, last_name,department_id ,
      (SELECT department_name
      FROM departments d, employees E
      WHERE d.department_id  = e.department_id
      And employee_id = 200
      )
      FROM employees e
    2. SELECT employee_id, first_name, last_name,department_id ,
      (SELECT department_ID
      FROM departments d
      WHERE d.department_id  = department_id
      )
      FROM employees e
      WHERE employee_id = 200; 
    3. SELECT employee_id, first_name, last_name,department_id ,
      (SELECT department_name
      FROM departments d
      WHERE d.department_id  = e.department_id
      And employee_id = 200
      )
      FROM employees e
    4. SELECT employee_id, first_name, last_name,department_id ,
      (SELECT department_name
      FROM departments d,employee E
      WHERE d.department_id  = e.department_id
      )
      FROM employees e

    Answer: C.

    72.You need to find the highest earning employee with the job ID as ”SA_REP”. Which of the following queries will be correct? (Choose the most appropriate answer)

    1. SELECT job_id, employee_id, Salary
      FROM employees e
      WHERE job_id  =
      (
      SELECT  distinct salary
      FROM employees E1
      WHERE E.job_id  = E1.job_id
      AND E.salary <=  E1.salary
      AND job_id  = ''SA_REP''
      
    2. SELECT department_id , employee_id, Salary
      FROM employees E
      WHERE 1 =
      (
      SELECT  count(distinct salary)
      FROM employees E1
      WHERE E.job_id  = E1.job_id
      AND E.salary <=  E1.salary
      AND job_id  = ''SA_REP''
      )
    3. SELECT department_id , employee_id, Salary
      FROM employees E
      WHERE 0 =
      (
      SELECT  count(distinct salary)
      FROM employees E1
      WHERE E.job_id  = E1.job_id
      AND E.salary =  E1.salary
      AND job_id  = ''SA_REP''
      )
    4. SELECT department_id , employee_id, Salary
      FROM employees E
      WHERE 1 =
      (
      SELECT salary
      FROM employees E1
      WHERE E.job_id  < E1.job_id
      AND E.salary <=  E1.salary
      AND job_id  = ''SA_REP''
      )

    Answer: B.

    Consider the EMPLOYEES table structure as shown in the exhibit and answer the questions 73 to 77 that follow:

    Table EMPLOYEES

    73.You need to find the job which has at least one employee in it. Which of the following queries will be correct? (Choose the most appropriate answer)

    1. SELECT employee_id, Job_id
      FROM employees E
      WHERE exists
      (
      SELECT 1
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    2. SELECT employee_id, Job_id
      FROM employees E
      WHERE exists
      (
      SELECT *
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    3. SELECT employee_id, Job_id
      FROM employees E
      WHERE not exists
      (
      SELECT *
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    4. SELECT employee_id, Job_id
      FROM employees E
      WHERE exists
      (
      SELECT 1
      FROM employees E1
      WHERE E.job_id  < E1.job_id )

    Answer: A. The EXISTS operator is used to check and match records between queries. It returns a BOOLEAN value. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query;and the EXISTS operator is used to test whether the relationship or link is present. An Uncorrelated subquery executes the subquery first and passes the value to the outer query.

    74.You need to find the job which has no employees in it. Which of the following queries will be correct? (Choose the most appropriate answer)

    1. SELECT employee_id, Job_id
      FROM employees E
      WHERE exists
      (
      SELECT *
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    2. SELECT employee_id, Job_id
      FROM employees E
      WHERE not exists
      (
      SELECT 1
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    3. SELECT employee_id, Job_id
      FROM employees E
      WHERE not exists
      (
      SELECT *
      FROM employees E1
      WHERE E.job_id  = E1.job_id )
    4. SELECT employee_id, Job_id
      FROM employees E
      WHERE exists
      (
      SELECT 1
      FROM employees E1
      WHERE E.job_id  < E1.job_id )

    Answer: B. The NOT EXISTS is the negation operator for EXISTS.

    75.You need to find the 3rd maximum salary from the EMPLOYEES table. Which of the following queries will give you the required results? (Choose the most appropriate answer)

    1. SELECT *
      FROM employees E
      WHERE salary = (SELECT count(distinct salary )
      		FROM employees
      		WHERE e.salary = salary
      		); 
    2. SELECT *
      FROM employees E
      WHERE 1 = (SELECT count(distinct salary )
      		FROM employees
      		WHERE e.salary < salary
      		); 
    3. SELECT *
      FROM employees E
      WHERE 2 = (SELECT count(distinct salary )
      		FROM employees
      		WHERE e.salary >salary
      		); 
    4. SELECT *
      FROM employees E
      WHERE 3 = (SELECT count(distinct salary )
      		FROM employees
      		WHERE e.salary <= salary
      		); 

    Answer: D.

    76. You need to find the maximum salary by using the user input for getting the value of N. Which of the following queries will give you the required results? (Choose the most appropriate answer)

    1. SELECT salary FROM
      (
      	SELECT rowid as user_sal
      	FROM (SELECT distinct salary  from employees ORDER BY salary  desc)
      )
      WHERE user_sal=&N ; 
    2. SELECT salary FROM
      (
      	SELECT rownum as user_sal
      	FROM (SELECT distinct salary  FROM employees   		GROUP BY salary )
      )
      WHERE user_sal <= &N ; 
    3. SELECT salary FROM
      (
      	SELECT rownum as user_sal, salary 	FROM (SELECT distinct salary  FROM employees 		 ORDER BY salary  desc)
      )
      WHERE user_sal=&N ; 
    4. SELECT salary FROM
      (
      	SELECT max(rownum) as user_sal, salary 	FROM (SELECT distinct salary  FROM employees 		ORDER BY salary  desc)
      )
      WHERE user_sal=&N ; 

    Answer: C. ROWNUM is a pseudo column used for finding the nth order results.

    77.What will happen if a value is provided to the &N variable in the above query (option C in question 76) does not match with any row? (Choose the best answer)

    1. The statement would throw an ORA error
    2. The statement would return all the rows in the table
    3. The statement would return NULL as the output result.
    4. The statement would return no rows in the result.

    Answer: D.

    78.What is the maximum level up to which Sub-queries can be nested?

    1. 255
    2. 100
    3. 2
    4. 16

    Answer: A.

    79.What is true about the EXISTS operator in SQL queries with respect to sub-queries?

    1. The columns selected in the sub-queries are important
    2. The inner query”s should return rows, any result is what is important, not what is SELECTED
    3. Both A and B
    4. Neither A nor B

    Answer: B.

    80.What is true about the ANY operator used for sub-queries?

    1. Returns rows that match all the values in a list/sub-query
    2. Returns rows that match the first 5 values in a list/sub-query
    3. Returns rows that match any value in a list/sub-query
    4. Returns the value 0 when all the rows match in a list/sub-query

    Answer: C.

    81.What is true about the ALL operator used for sub-queries? (Choose the most appropriate answer.)

    1. Returns rows that match all the values in a list/sub-query
    2. Returns rows that match only some values in a list/sub-query
    3. Returns rows only if all the values match in a list/sub-query
    4. All of the above

    Answer: C. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”> ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery.

    82.What is true about using sub-queries in INSERT statements in Oracle?

    1. They can be used in the INSERT clause without any restriction
    2. They can be used in the INSERT clause only for Numeric values
    3. The SELECT list of a sub-query should be the same as the column list of the INSERT statement.
    4. None of the above

    Answer: C.

    Examine the table structures as given below and answer the questions 83 to 86 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    83.You need to find the details of all employees who were hired for the job ID ”SA_REP” in the month of June, 2013. Which of the following queries will give the required results? (Consider the table structure as given)

    1. SELECT first_name
      FROM employees
      WHERE employee_id  =
      (	SELECT employee_id
      	FROM employees
      	WHERE to_char(hiredate, ''MM/YYYY'')= ''02/1981''
      	AND job_id  = ''SA_REP''
      ); 
    2. SELECT first_name
      FROM employees
      WHERE employee_id  = ANY
      (	SELECT employee_id
      	FROM employees
      	WHERE to_char(hiredate, ''MM/YYYY'')= ''02/1981''
      	AND job_id  = ''SA_REP''
      ); 
    3. SELECT first_name
      FROM employees
      WHERE employee_id  ANY
      (	SELECT employee_id
      	FROM employees
      	WHERE to_char(hiredate, ''MM/YYYY'')= ''02/1981''
      	AND job_id  = ''SA_REP''
      ); 
    4. SELECT first_name
      FROM employees
      WHERE employee_id  exists
      (	SELECT employee_id
      	FROM employees
      	WHERE to_char(hiredate, ''MM/YYYY'')= ''02/1981''
      	AND job_id  = ''SA_REP''
      ); 

    Answer: B.

    84.Which of the following statements are equivalent?

    1. SELECT employee_id , salary
      FROM employees
      WHERE salary < ALL (SELECT salary FROM employees WHERE department_id=100); 
    2. SELECT employee_id , salary
      FROM employees WHERE salary < (SELECT min(salary) FROM employees WHERE department_id=100); 
    3. SELECT employee_id
      FROM employees
      WHERE salary not >= ANY (SELECT salary FROM employees WHERE department_id=100); 
    4. None of the above

    Answer: A, B.

    85.Consider the following two queries:

    Query 1:
    SELECT first_name
    FROM employees e join departments d
    ON e.department_id  = d.department_id
    WHERE department_name=''ACCOUNTS 
    Query 2:
    SELECT first_name
    FROM employees  e
    WHERE department_id  = ANY (SELECT department_id 		FROM departments d
    		WHERE department_name=''ACCOUNTS''); 

    What can be said about the two statements?

    1. Both the queries should generate the same result.
    2. Both the queries will throw an error.
    3. If there are two departments with the same name, both the queries will fail.
    4. Both the queries will run successfully even if there is more than one department named ”ACCOUNTS”.

    Answer: A, D.

    86.You need to display all the employees who have the highest salary in a department 100. You fire a query as below.

    SELECT E.first_name, E.last_name , E.salary
    FROM employees E
    WHERE E.salary > ALL (SELECT E1.salary
          FROM employees E1
          WHERE E.department_id  =E1.department_id
          AND E.department_id  = 100); 

    What will be the outcome of the above query?

    1. It executes successfully and gives the required results
    2. It executes successfully but doesn”t give the required output
    3. It throws an ORA error on execution
    4. It executes successfully and gives the required result when >ALL is replaced with >=ALL

    Answer: B, D. >ALL will not give the required result as there may be two employees with the same salary and who are the highest earners in the department 100

    Consider table structures as shown in the exhibit and answer the questions 87 to 89 that follow:

    Table EMPLOYEES Table DEPARTMENTS

    87.You need to fetch the first names (in a reverse alphabetical order) of all the employees in the department ID = 100 and who have the maximum salary in the JOB ID = ”SA_REP”. Which of the following queries will give the required output? (Choose the most appropriate output)

    1. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary =
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE E1.department_id  = 100
      		GROUP BY job_id )
      AND job_id  = ''SA_REP''
      ORDER BY first_name; 
    2. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary in
      		(SELECT max(salary)
      		FROM employees E1
      		where E1.department_id  = 100)
      ORDER BY first_name; 
    3. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary IN
      		(SELECT max(salary)
      		FROM employees E1
      		where job_id  = ''SA_REP''
      		GROUP BY job_id )
      AND WHERE E.department_id  = 100
      ORDER BY first_name desc; 
    4. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary IN
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE E1.department_id  = 100
      		GROUP BY job_id )
      ORDER BY first_name ; 

    Answer: C.

    88.In the queries given above (option C is the correct answer), you need to display all the employees with the JOB ID ”SA_REP” who have the maximum salary in the department 100. Which of the following queries will give the required output?

    1. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary IN
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE E1.department_id  = 100
      		GROUP BY job_id )
      AND job_id  = ''SA_REP''
      ORDER BY first_name; 
    2. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary in
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE E1.department_id  = 100)
      ORDER BY first_name; 
    3. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary in
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE job_id  = ''SA_REP''
      		GROUP BY job_id )
      And WHERE E.department_id  = 100
      ORDER BY first_name desc; 
    4. SELECT E.first_name, job_id , salary
      FROM employees E
      WHERE salary in
      		(SELECT max(salary)
      		FROM employees E1
      		WHERE E1.department_id  = 100
      		GROUP BY job_id )
      ORDER BY first_name ; 

    Answer: A.

    89.Select the query which will give you the maximum salary and maximum comm percentage. The query should also give the maximum comm percentage paid if the highest salaried employee gets the maximum comm percentage.

    1. SELECT employee_id, max(salary), max(commission_pct )
      FROM employees E
      GROUP BY salary, commission_pct ; 
    2. SELECT employee_id, max(salary), max(commission_pct )
      FROM employees E
      GROUP BY salary; 
    3. SELECT employee_id, max(salary)
      FROM employees E
      GROUP BY salary, commission_pct
      HAVING max(commission_pct ) = 100; 
    4. SELECT employee_id,
      (SELECT max(salary) FROM employees) * (SELECT max(commission_pct ) FROM employees)
      FROM DUAL; 

    Answer: D. A single-row subquery can also be nested in the outer query”s SELECT clause. In this case, the value the subquery returns is available for every row of output the outer query generates. Typically, this technique is used to perform calculations with a value produced from a subquery.

    90.What is true about the sub-queries used in the SELECT clause of an SQL statement?

    1. These sub-queries are the same in all aspects as those used in the FROM or WHERE clauses
    2. These sub-queries have to mandatorily be single row sub-queries
    3. We can use multi row operators when writing such sub-queries
    4. None of the above

    Answer: B.

    91.What will be the outcome of the following query? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT sysdate,
    (SELECT max(salary) FROM employees GROUP BY department_id )
    FROM DUAL; 
    1. It gives the system date and the maximum salary for each department
    2. It gives the maximum salary for all the departments
    3. It throws an ORA error
    4. It executes successfully with 0 rows

    Answer: C. A Multi row sub-query cannot be used in the SELECT clause of an SQL statement. Only a single-row subquery can be nested in the outer query”s SELECT clause.

    Examine the given table structure. Consider the following query and answer the questions 92 to 95 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT salary
    FROM employees
    WHERE salary > ALL (10, 20, 30); 

    92.Which of the following queries are equivalent to the above query?

    1. SELECT salary
      FROM employees
      WHERE salary >10 or salary > 20 and salary >30; 
    2. SELECT salary
      FROM employees
      WHERE salary <10 and salary < 20 and salary <30; 
    3. SELECT salary
      FROM employees
      WHERE salary >10 and salary > 20 and salary >30; 
    4. SELECT salary
      FROM employees
      WHERE salary >10 and salary > 20 or salary < 30; 

    Answer: C. The question shows the ALL clause in a simplified manner when it is followed by a list.

    93. If in the above query the list (10,20,30) is replaced by a sub-query, which of the following queries will give the required output for the department number 100?

    1. SELECT E.salary
      FROM employees E
      WHERE E.salary > (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    2. SELECT E.salary
      FROM employees E
      WHERE E.salary >ALL (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    3. SELECT E.salary
      FROM employees E
      WHERE E.salary = (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    4. SELECT E.salary
      FROM employees E
      WHERE E.salary >= (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 

    Answer: B. The question shows the ALL clause in a simplified manner when it is followed by a sub-query

    94.With respect to the question 14 above, what among the following will be an equivalent query if ALL has to be replaced with ANY?

    1. SELECT E.salary
      FROM employees E
      WHERE NOT EXISTS (E.salary =ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    2. SELECT E.salary
      FROM employees E
      WHERE E.salary >ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    3. SELECT E.salary
      FROM employees E
      WHERE E.salary =ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    4. SELECT E.salary
      FROM employees E
      WHERE NOT ( E.salary <= ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100)); 

    Answer: D. The NOT operator used while using ”<= ANY” is used for negation of the results returned by the sub-query

    95.With respect to the question 94, if the operator ANY is not to be used, which of the following queries will be correct?

    1. SELECT E.salary
      FROM employees E
      WHERE NOT EXISTS (E.salary = ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    2. SELECT E.salary
      FROM employees E
      WHERE NOT EXISTS (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100
      And E.salary <= E1.salary); 
    3. Either A or B
    4. None of the above

    Answer: B. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query;and the EXISTS operator is used to test whether the relationship or link is present. An Uncorrelated subquery executes the subquery first and passes the value to the outer query.

    Examine the given table structures. Consider the following query and answer the questions 96 to 98 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT salary
    FROM employees
    WHERE salary > ANY (10, 20, 30); 

    96. Which of the following queries are equivalent to the above query?

    1. SELECT salary
      FROM employees
      WHERE salary >10 or salary > 20 and or >30; 
    2. SELECT salary
      FROM employees
      WHERE salary <10 and salary < 20 and salary <30; 
    3. SELECT salary
      FROM employees
      WHERE salary >10 and salary > 20 or salary >30; 
    4. SELECT salary
      FROM employees
      WHERE salary >10 and salary > 20 or salary < 30; 

    Answer: A. The question shows the ANY clause in a simplified manner when it is followed by a list.

    97. In the above query, if the list (10, 20, 30) is replaced by a sub-query, which of the following queries will give the required output for the department number 100?

    1. SELECT E.salary
      FROM employees E
      WHERE E.salary > (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    2. SELECT E.salary
      FROM employees E
      WHERE E.salary >ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    3. SELECT E.salary
      FROM employees E
      WHERE E.salary = (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    4. SELECT E.salary
      FROM employees E
      WHERE E.salary >= (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 

    Answer: B. The question shows the ANY clause in a simplified manner when it is followed by a sub-query

    98.With respect to the question 97 above, what among the following will be an equivalent query if ANY is removed?

    1. SELECT E.salary
      FROM employees E
      WHERE NOT EXISTS (E.salary =ANY (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 
    2. SELECT E.salary
      FROM employees E
      WHERE EXISTS (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100
      And E.salary >E1.salary); 
    3. SELECT E.salary
      FROM employees E
      WHERE EXISTS (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100
      ); 
    4. SELECT E.salary
      FROM employees E
      WHERE IN (SELECT  E1.salary
      FROM employees E1
      WHERE E1.department_id  = 100); 

    Answer: B. The EXISTS operator can substitute the ANY operator. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query;and the EXISTS operator is used to test whether the relationship or link is present.

    99.Examine the given table structure. How many rows will get generated if the sub-query mentioned returns 0 rows?

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT E.salary
    FROM employees E
    WHERE E.salary > ANY ( select E1.salary FROM employees E1 where E1.department_id  = 100); 
    1. 1 row
    2. No rows
    3. Either A or B
    4. None of the above

    Answer: B. If the sub-query returns zero rows, the ”> ANY” condition evaluates to FALSE, hence “No rows” are returned.

    100. A subquery must be placed in the outer query”s HAVING clause if:

    1. The inner query needs to reference the value returned to the outer query.
    2. The value returned by the inner query is to be compared to grouped data in the outer query.
    3. The subquery returns more than one value to the outer query.
    4. None of the above. Subqueries can”t be used in the outer query”s HAVING clause.

    Answer: B. A HAVING clause is used when the group results of a query need to be restricted based on some condition. If a subquery”s result must be compared with a group function, you must nest the inner query in the outer query”s HAVING clause.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Using the Set Operators nhận dự án làm có lương

    SQL – Using the Set Operators Questions



    1.Which SET operator does the following figure indicate?

    Table UNION
    1. UNION
    2. UNION ALL
    3. INTERSECT
    4. MINUS

    Answer: A. Set operators are used to combine the results of two (or more) SELECT statements.Valid set operators in Oracle 11g are UNION, UNION ALL, INTERSECT, and MINUS. When used with two SELECT statements, the UNION set operator returns the results of both queries.However,if there are any duplicates, they are removed, and the duplicated record is listed only once.To include duplicates in the results,use the UNION ALL set operator.INTERSECT lists only records that are returned by both queries; the MINUS set operator removes the second query”s results from the output if they are also found in the first query”s results. INTERSECT and MINUS set operations produce unduplicated results.

    2.Which SET operator does the following figure indicate?

    Table UNION_ALL
    1. UNION
    2. UNION ALL
    3. INTERSECT
    4. MINUS

    Answer: B. UNION ALL Returns the combined rows from two queries without sorting or removing duplicates.

    sql_certificate

    3.Which SET operator does the following figure indicate?

    Table INTERSECT
    1. UNION
    2. UNION ALL
    3. INTERSECT
    4. MINUS

    Answer: C. INTERSECT Returns only the rows that occur in both queries” result sets, sorting them and removing duplicates.

    4.Which SET operator does the following figure indicate?

    Table MINUS
    1. UNION
    2. UNION ALL
    3. INTERSECT
    4. MINUS

    Answer: D. MINUS Returns only the rows in the first result set that do not appear in the second result set, sorting them and removing duplicates.

    5.What is true about SET operators?

    1. They change values of rows
    2. They combine the results of only two component queries into one result
    3. They combine the results of 10 component queries into two result sets.
    4. They combine the results of two or more component queries into one result

    Answer: D. Set operators are used to combine the results of two (or more) SELECT statements. Valid set operators in Oracle 11g are UNION, UNION ALL, INTERSECT, and MINUS.

    6.What are the queries containing SET operators called?

    1. Sub-queries
    2. Co-related sub-queries
    3. GROUP BY queries
    4. Compound queries

    Answer: D.

    7.What is true about the UNION operator?

    1. It returns rows from the combined queries along with NULL values
    2. It returns rows for the combined queries after eliminating duplicates
    3. It returns rows for the combined queries along with duplicate values
    4. It returns rows for the combined queries ignoring the NULL values

    Answer: B. UNION Returns the combined rows from two queries, sorting them and removing duplicates.

    8.What is true about the UNION ALL operator?

    1. It returns rows from the combined queries along with NULL values
    2. It returns rows for the combined queries after eliminating duplicates
    3. It returns rows for the combined queries along with duplicate values
    4. It returns rows for the combined queries ignoring the NULL values

    Answer: C. UNION ALL Returns the combined rows from two queries without sorting or removing duplicates.

    9.What is true about the INTERSECT operator?

    1. It returns rows from the combined queries along with NULL values
    2. It returns rows for the combined queries after eliminating duplicates
    3. It returns the common rows from the combined queries
    4. None of the above

    Answer: C. INTERSECT Returns only the rows that occur in both queries” result sets, sorting them and removing duplicates.

    10.What is true about the MINUS operator?

    1. It returns rows from the first query but not from the second query
    2. It returns rows for the second query but not from the first query
    3. It returns duplicate rows for the combined queries
    4. It returns rows for the combined queries ignoring the NULL values

    Answer: A. MINUS Returns only the rows in the first result set that do not appear in the second result set, sorting them and removing duplicates.

    11.What is the precedence of the set operators UNION, UNION ALL, INTERSECT and MINUS?

    1. UNION, UNION ALL, INTERSECT and MINUS
    2. MINUS, UNION, UNION ALL and INTERSECT
    3. INTERSECT, MINUS, UNION ALL, UNION
    4. Equal precedence

    Answer: D. SET operators have an equal precedence.

    12.What is the order of evaluation of set operators?

    1. Left to Right
    2. Right to Left
    3. Random Evaluation
    4. Top to Bottom

    Answer: A, D. Assuming that there are no grouping of queries using parentheses, the SET operators will be evaluated from top to bottom and left to right horizontally.

    13.In which of the following cases, parenthesis should be specified?

    1. When INTERSECT is used with other set operators
    2. When UNION is used with UNION ALL
    3. When MINUS is used for the queries
    4. None of the above

    Answer: A. Using parenthesis will explicitly change the order of evaluation when INTERSECT is used with other operators.

    14.What is true about the SELECT clause when SET operators are used?

    1. There is no restriction on the columns being selected
    2. The columns, expressions used in the SELECT clause must match in number in the combined queries
    3. The columns, expressions used in the SELECT clause must be N in the first query and N-1 in the subsequent combined queries
    4. Both B and C

    Answer: B. All the combined should have the same no. of columns when using SET operators. The corresponding columns in the queries that make up a compound query must be of the same data type group.

    15.What is true about the SET operators?

    1. The SELECT clause should have the same number of columns, data types can be different
    2. The SET operators can be used only for combining two queries
    3. The data type of each column in the 2nd query must match the data type of its corresponding column in the first query.
    4. None of the above

    Answer: C. All the combined should have the same no. of columns when using SET operators. The corresponding columns in the queries that make up a compound query must be of the same data type group.

    16.Where can the ORDER BY clause be used in case when SET operators are used?

    1. In each of the queries being combined
    2. In the first query only
    3. At the very end of the compound query
    4. None of the above

    Answer: C. If the ORDER BY clause is used in between any of the queries joined using SET operators, it will throw an ORA error.

    17.What is true about the queries that have SET operators in their WHERE clause?

    1. These queries must have the same no. and data type of columns in their SELECT clause.
    2. The no. of columns used in the WHERE clause query and the main SELECT can be different
    3. The no. of columns used in the WHERE clause should be the same, the data type can be different
    4. None of the above

    Answer: A. All the combined should have the same no. of columns when using SET operators. The corresponding columns in the queries that make up a compound query must be of the same data type group.

    18.What is true about the columns in the second query with respect to the columns in the first query?

    1. The column in the 2nd query must be in the same data type group as the corresponding column in the 1st query
    2. If a column in the 1st query is a NUMBER, the corresponding column in the 2nd query should be a VARCHAR2
    3. If a column in the 1st query is a NUMBER, the corresponding column in the 2nd query should be also be NUMBER.
    4. None of the above

    Answer: A, C.

    19.What among the following is true about SET operators?

    1. SET operators cannot be used in sub-queries
    2. SET operators can only be used in the WHERE clause
    3. ORDER BY can be used for all queries combined by a SET operator
    4. SET operators can be used in sub-queries

    Answer: D.

    20.What is the best way to change the precedence of SET operators given the fact that they have equal precedence?

    1. The order of usage of the SET operators can be changed to change the precedence
    2. The equal precedence cannot be changed
    3. Parenthesis can be used to change the precedence
    4. None of the above

    Answer: C. Parenthesis can be used to group the specific queries in order to change the precedence explicitly. Parentheses are preferred over other SET operators during execution.

    21.What can be said about duplicate values and SET operators?

    1. No SET operator displays duplicate values
    2. All SET operators can display duplicate values
    3. Only UNION ALL operator displays duplicate values
    4. None of the above

    Answer: C. UNION, INTERSECT and MINUS automatically eliminate duplicate values

    Examine the structure of the EMPLOYEES and DEPARTMENTS tables and consider the following query and answer the questions 22 and 23.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT department_id
    FROM employees e
    UNION
    SELECT department_id
    FROM departments
    

    22.What will be displayed in the result of this query?

    1. It will display distinct department id(s) contained jointly in EMPLOYEES and DEPARTMENTS table
    2. It will throw ORA error
    3. No rows selected
    4. None of the above

    Answer: A. UNION Returns the combined rows from two queries, sorting them and removing duplicates.

    23.What is true about the query given above?

    1. This query returns an ORA error
    2. It executes successfully but gives no results
    3. Queries from different tables cannot be used with the SET operators
    4. The query executes successfully and gives the results as expected

    Answer: D. A compound query is one query made up of several queries using different tables.

    24.What is the default sorting order of the results when UNION ALL operator is used?

    1. Descending
    2. Ascending
    3. Either A or B
    4. All of the above

    Answer: B. A compound query will by default return rows sorted across all the columns,from left to right in ascending order.The only exception is UNION ALL, where the rows will not be sorted. The only place where an ORDER BY clause is permitted is at the end of the compound query.

    25.What will be the output of the compound query in which columns in the SELECT are of CHAR and equal length?

    1. The output will have VARCHAR2 data type of equal length
    2. The output will have CHAR data type of equal length
    3. The output will have CHAR data type of different lengths
    4. The output will have NUMBER data type of equal length

    Answer: B. The columns in the queries that make up a compound query can have different names, but the output result set will use the names of the columns in the first query. The corresponding columns in the queries that make up a compound query must be of the same data type group.

    26.What will be the output of the compound query in which columns in the SELECT are of CHAR and different lengths?

    1. The output will have VARCHAR2 data type of equal length
    2. The output will have CHAR data type of equal length
    3. The output will have CHAR data type of different lengths
    4. The output will have VARCHAR2 data type with the length of the larger CHAR value

    Answer: D. While the selected column lists do not have to be exactly the same data type, they must be from the same data type group. The result set of the compound query will have columns with the higher level of precision.

    27.What will be the output of a compound query if either or both queries select values of VARCHAR2?

    1. The output will have VARCHAR2 data type.
    2. The output will have CHAR data type of equal length
    3. The output will have CHAR data type of different lengths
    4. The output will have VARCHAR2 data type with the length of the larger CHAR value

    Answer: A. While the selected column lists do not have to be exactly the same data type, they must be from the same data type group. The result set of the compound query will have columns with the higher level of precision.

    28.What is true if the compound queries select numeric data?

    1. There will be an equal precedence of the numeric values, operators
    2. The return values will be determined by the numeric precedence
    3. The return values will be of NUMBER data type
    4. None of the above

    Answer: B, C. While the selected column lists do not have to be exactly the same data type, they must be from the same data type group. The result set of the compound query will have columns with the higher level of precision.

    29.What will happen if the SELECT list of the compound queries returns both a VARCHAR2 and a NUMBER data type result?

    1. Oracle will convert them implicitly and return a VARCHAR2 data type result
    2. Oracle will convert them implicitly and return a NUMBER data type result
    3. An ORA error is thrown
    4. None of the above

    Answer: C. Oracle does not convert data types implicitly.

    30.What is true about the UNION operator?

    1. It eliminates the duplicate values ignoring NULL values
    2. It returns duplicate values ignoring NULL values
    3. It returns duplicate values including NULL values
    4. It eliminates duplicate values and does not ignore NULL values

    Answer: D. NULL values are not ignored when the UNION operator is used

    31.What can be said about the names and columns of a SQL query which uses the UNION operator?

    1. The names of the columns should be identical
    2. The names and data type of the columns should be identical
    3. The names of the columns need not be identical
    4. None of the above

    Answer: C. The columns in the queries that make up a compound query can have different names, but the output result set will use the names of the columns in the first query.

    Consider the following exhibit of the JOB_HISTORY table and the query that follows. Answer the questions 32 and 33 below the query.

    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id , first_name, last_name, job_id
    FROM employees E
    UNION
    SELECT employee_id , first_name, last_name, job_id
    From job_history;

    32.How many times the each employee will get displayed by the above query?

    1. 0
    2. 1
    3. 2
    4. 4

    Answer: B. UNION Returns the combined rows from two queries, sorting them and removing duplicates.

    33.What will be the outcome of the above query?

    1. It displays the current and previous job details of the employees twice
    2. It displays the current and previous job details of the employees only once
    3. Either A or B
    4. None of the above

    Answer: B.

    Examine the given table structures and consider the following query and answer the questions 34 to 37 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id , job_id, department_id
    FROM employees
    UNION
    SELECT employee_id , job_id, department_id
    From job_history;

    34.Assuming that an employee with ID 121 has held 2 job IDs in his tenure in the company. Considering the above query, how many times will his records be displayed in the results?

    1. Once
    2. Twice
    3. Thrice
    4. None of the above

    Answer: B. UNION Returns the combined rows from two queries, sorting them and removing duplicates. Duplicity is measured by the combination of columns and not the individual column separately.

    35.Assuming that the employee with ID 121 held two positions in two different departments – 10 and 20 in the company.He worked as ”SA_REP” in both the departments 10 and 20. What will be the outcome of the above query ?

    1. 2 rows
    2. 3 rows
    3. No rows
    4. ORA error

    Answer: B.

    36.Which statements best describes the inference drawn from the questions 34 and 35?

    1. There are duplicate values for job codes
    2. The query executes but results produced are unexpected
    3. There are no duplicate values for departments
    4. None of the above

    Answer: C. As the combination of the job codes and departments is unique, there are no duplicates obtained.

    37.What will be the sorting in the result set obtained by the query?

    1. Descending on Employee ID
    2. Descending on Job ID
    3. Ascending on Employee ID
    4. Ascending on Department ID

    Answer: C. The default sorting will be ascending based on the first column i.e.: Employee ID in this case.However, this behavior can be modified by placing a single ORDER BY clause at the end.

    38.Which of the following operators will be used to obtain duplicate records from the component queries?

    1. UNION
    2. UNION ALL
    3. MINUS
    4. None of the above

    Answer: B. UNION ALL doesn”t eliminates the duplicate values.

    39.What is the difference between the UNION and the UNION ALL operators?

    1. There is no difference
    2. UNION ALL displays duplicate values too
    3. The output in the case of UNION ALL is not sorted by default
    4. None of the above

    Answer: B, C. When used with two SELECT statements, the UNION set operator returns the results of both queries. However, if there are any duplicates, they are removed, and the duplicated record is listed only once. To include duplicates in the results, use the UNION ALL set operator

    40.What is true about the INTERSECT operator?

    1. The number of columns and data types of the columns in the component queries should be the same
    2. The names of the columns and data types of the columns in the component queries should be the same
    3. Both A and B
    4. None of the above

    Answer: A. This is common property criteria feature of SET operators.

    41.What can be said about the result set if the order of the intersected tables is altered when using INTERSECT?

    1. The result is altered
    2. The result remains the same
    3. The sorting changes on alteration
    4. None of the above

    Answer: B.

    42.What among the following is true about the INTERSECT operator?

    1. It ignores NULL values
    2. It does not ignore NULL values
    3. It returns all the rows from the first component query
    4. None of the above

    Answer: B.

    Answer the related questions 43 and 44 given below.

    43.You need to display the names and job IDs of those employees who currently have a job title that is the same as their previous one. Which of the following queries will work? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT employee_id , job_id, first_name, last_name
      FROM employees
      UNION
      SELECT employee_id , job_id, first_name, last_name
      FROM job_history;
    2. SELECT employee_id , job_id, first_name, last_name
      FROM employees
      INTERSECT
      SELECT employee_id , job_id, first_name, last_name
      FROM job_history;
    3. SELECT employee_id , job_id, first_name, last_name
      FROM employees
      UNION ALL
      SELECT employee_id , job_id, first_name, last_name
      FROM job_history;
    4. None of the above

    Answer: B.

    44.Considering the above query i.e. Option B in question 43, what will be the result if the department ID is also included in the SELECT clause?

    1. The result will be the same
    2. The result will be different
    3. The result will be the same but the order will be different
    4. None of the above

    Answer: A. The result can be interpreted as – the employees who have worked with the same job title in the same department.

    45.What is true about the MINUS operator?

    1. It returns all the rows from all the component queries
    2. It returns only the common rows from all the component queries
    3. It returns all the rows from the first query and not from the subsequent queries
    4. It returns all distinct rows selected by the first query, but not present in the subsequent queries

    Answer: D. MINUS set operator removes the second query”s results from the output if they are also found in the first query”s results

    46.What can be said regarding the number of columns and data types of the component queries when a MINUS operator is used?

    1. They should be the same, the data type might be different but they should belong to the same data type group.
    2. They should be the same along with the names of the columns
    3. Both A and B
    4. None of the above

    Answer: A. Common feature of SET operators.

    47.You need to display the employee IDs of the employees who have not changed their jobs even once during tenure in the company. Which of the following queries will be correct in this case? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT employee_id
      FROM employees
      UNION
      SELECT employee_id
      FROM job_history;
    2. SELECT employee_id
      FROM employees
      INTERSECT
      Select employee_id
      FROM job_history;
    3. SELECT employee_id
      FROM employees
      MINUS
      Select employee_id
      FROM job_history;
    4. SELECT employee_id
      FROM employees
      UNION ALL
      SELECT employee_id
      FROM job_history;

    Answer: C.

    Examine the given table structures and consider the following query answer the questions 48 and 49 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id , first_name, job_id
    FROM employees
    UNION
    SELECT employee_id , NULL "first_name", job_id
    FROM job_history;

    48.What is true about the above query?

    1. It throws an error as TO_CHAR (NULL) cannot be used
    2. It executes successfully and gives the values for employees” id, first_name and current job role including duplicate rows
    3. It executes successfully and gives the values for employees” id, first_name and all jobs held by the employees excluding duplicate rows
    4. None of the above

    Answer: C. Each query must contain the same number of columns, which are compared positionally. NULL can be substituted in place of column which is missing in the other query within the same compound query.

    49.Considering the above query, if the UNION operator is replaced by the MINUS operator, what will the result mean?

    1. The result shows those employees who have an entry in the JOB_HISTORY table
    2. The result shows those employees who do not have an entry in the JOB_HISTORY, but they are present in the EMPLOYEES table
    3. Either of A or B
    4. None of the above

    Answer: B. MINUS gives the unique results that are present in the first query but not the second query.

    Consider the exhibit given below and answer the questions 50 and 51 that follow:

    Table AUDIT_YEARLY Table AUDIT

    50.What will be the outcome of the following query?

    SELECT AU_DETAILS
    FROM AUDIT
    UNION
    SELECT AU_DETAILS
    FROM AUDIT_YEARLY;
    1. It executes successfully giving the correct results including the duplicate values
    2. It executes successfully giving the correct results excluding the duplicate values
    3. It throws an ORA error
    4. None of the above

    Answer: C. CLOB or LONG columns cannot be in the SELECT clause when using the UNION set operators.

    51.What will be the outcome of the query if UNION is replaced with UNION ALL?

    1. It will execute successfully giving the correct results including duplicate values
    2. It throws an ORA error
    3. It will execute successfully giving the correct results excluding duplicate values
    4. It executes successfully but gives the incorrect results.

    Answer: B. .UNION, UNION ALL, INTERSECT and MINUS operators when used with a LONG or CLOB column throws error.

    52.Assume that there are 4 component queries. How many SET operators can be used to combine them in a single compound query?

    1. 1
    2. 2
    3. 4
    4. 3

    Answer: D. The SET operator to be used will are N-1 where N is the number of component queries.

    53.What are SET operators called owning to the fact that two or more SELECTs are involved based on columns instead of rows when SET operators are used?

    1. Horizontal joins
    2. Cartesian Joins
    3. Vertical joins
    4. Outer joins

    Answer: C.

    54.What is the difference between a UNION and INTERSECT operators? (Choose only the best difference)

    1. UNION combines the results of two component queries into one result set with duplicate values
    2. INTERSECT returns only those rows that are returned by each of the two component queries
    3. UNION gives the distinct values from the component queries, INTERSECT gives the common values from the component queries
    4. Both B and C

    Answer: C.

    Examine the structure of the EMPLOYEES table and consider the following query. Answer the questions 55 to 60 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    Query 1
    SELECT *
    FROM EMPLOYEES
    where department_id = 10
    Query 2
    SELECT *
    FROM EMPLOYEES  E
    where E.job_id IN (select first_name  from EMPLOYEES  E1 where E1.job_id = ''CLERK'' and E.job_id  = E1.job_id )

    55.You need to extract a report where the results from both the queries are displayed. Which of the following operators should be used to get the required results?

    1. UNION
    2. UNION ALL
    3. INTERSECT
    4. None of the above

    Answer: B. UNION ALL Returns the combined rows from two queries without sorting or removing duplicates.

    56.You need to display all the duplicate values along with all the values existing in the result set from both the queries. Which of the following SET operators you can use in the above given queries?

    1. INTERSECT
    2. UNION
    3. MINUS
    4. None of the above

    Answer: D. UNION ALL will give the unsorted results with duplicates.

    57.What is the difference between the result sets when using a UNION and a UNION ALL set operators?

    1. Result set from UNION ALL is filtered including duplicate values
    2. Result set from UNION is filtered and sorted including duplicate values
    3. Result set from UNION ALL is not sorted and it has duplicate values
    4. Result set from UNION is filtered and sorted without duplicate values

    Answer: C, D.

    58.The UNION operator has more overhead on the database than the UNION ALL. What is wrong in this statement?

    1. The statement is correct
    2. UNION ALL operator has more overhead on the Data base than the UNION operator
    3. UNION has to sort and eliminate duplicates which results into additional overhead
    4. None of the above

    Answer: A, C. UNION has to perform more tasks than UNION ALL because it sorts and deduplicates the result sets. Hence it is recommended that unless distinct rows are required, UNION ALL should be used.

    59.What will be the outcome if the two queries given above are combined using the INTERSECT operator?

    1. It will display only those employees who are Clerks in the Department 10
    2. It will display all those employees who are in the department 10
    3. It will display all the Clerks.
    4. None of the above

    Answer: A. INTERSECT returns those records that are present in query 1 AND query 2.

    60.What among the following is the difference between the INTERSECT and the UNION operators?

    1. INTERSECT follows the ”AND” Boolean logic, UNION follows the ”OR” Boolean logic
    2. UNION follows the ”OR” Boolean logic, whereas INTERSECT follows the ”AND” logic
    3. Either of A or B
    4. None of the above

    Answer: A.

    61.In which of the following SET operators, changing the order of the component queries will change the result set?

    1. UNION
    2. UNION ALL
    3. MINUS
    4. INTERSECT

    Answer: C. MINUS Returns only the rows in the first result set that do not appear in the second result set, sorting them and removing duplicates.

    Consider the following query and answer the questions 62 to 66 that follow:

    SELECT 4 from dual
    INTERSECT
    SELECT 1 from dual;

    62.What will be the outcome of the given query?

    1. No rows
    2. 4
    3. 1
    4. NULL

    Answer: A. No rows will be selected as the INTERSECT operator will not get any common results from both the queries – INTERSECT operators gives common results present in query 1 AND query 2.

    63.What will be the outcome of the query if the INTERSECT operator is replaced with MINUS operator?

    1. 3
    2. 4
    3. 0
    4. 1

    Answer: B. MINUS gives results that are present in the first query and not present in the second query.

    64.What will be the outcome of the above query if the INTERSECT operator is replaced with the UNION operator?

    1. 1

      4

    2. 4

      1

    3. NULL
    4. 0

    Answer: A. UNION will produce distinct rows in the result set in ascending order.

    65.What will be the outcome of the above query if the INTERSECT operator is replaced with the UNION ALL operator?

    1. 4

      1

    2. 0
    3. NULL
    4. 1

      4

    Answer: A. UNION ALL displays the results as they are positioned in the query without sorting them.

    66.What will be the outcome if the above query is modified as below?

    SELECT 1 from dual
    UNION ALL
    SELECT 4 from dual;
    1. 1

      4

    2. 4

      1

    3. NULL
    4. None of the above

    Answer: A.

    Examine the JOB_HISTORY_ARCHIVE table structure. It is a backup table for the JOB_HISTORY table with no additional column. Assuming that both the table have dissimilar data, consider the query given below and answer the questions 67 to 70 that follow:

    Table JOB_HISTORY_ARCHIVE
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    (SELECT * FROM job_history;
    MINUS
    SELECT * FROM job_history_archive)
    UNION ALL
    (SELECT * FROM job_history_archive
    MINUS
    SELECT * FROM job_history;);

    67. What will be the outcome of the query given above? (Choose the best answer)

    1. It will return those rows that are different in the two tables
    2. It will return the common rows in the two tables
    3. It will return all the rows from the two tables
    4. None of the above

    Answer: A.

    68.What can concluded if the above given query yields rows only from JOB_HISTORY table?

    1. It shows that the JOB_HISTORY contains two rows different from JOB_HISTORY_ARCHIVE table
    2. It shows that two rows are same in JOB_HISTORY and JOB_HISTORY_ARCHIVE tables
    3. It shows that the JOB_HISTORY_ARCHIVE contains two rows different from JOB_HISTORY table
    4. None of the above

    Answer: A.

    69.What can be said if the above query gives no results?

    1. It shows that the two tables have same data
    2. It shows that the component queries are wrongly placed
    3. It shows that the SET operators are wrongly used in the compound query
    4. None of the above

    Answer: A.

    70.With respect to the query given above, if duplicate records exist in the two tables, which of the following modifications should be made to the above given query?

    1. COUNT(*)
    2. COUNT(*) and GROUP BY employee_id
    3. COUNT (*) and ORDER BY employee_id
    4. None of the above

    Answer: B. COUNT(*) can be used to see the difference between the tables.

    Consider the following query:

    SELECT 1 NUM, ''employee'' TEXT FROM dual
    UNION
    SELECT TO_CHAR(NULL) NUM, ''departments'' TEXT FROM dual;

    71.What will be the outcome of the query given above?

    1.        NUM TEXT
      ---------- -----------
               1 employee
                 departments
    2.        NUM TEXT
      ---------- -----------
               1 employee
            NULL departments
    3. ORA error
    4.        NUM TEXT
      ---------- -----------
                 departments
               1 employee

    Answer: C. Here the numeric 1 is compared to a character NULL which throws the error “ORA-01790: expression must have same datatype as corresponding expression”.

    Consider the following query and answer the questions 72 and 73 that follow:

    SELECT months_between (sysdate, to_date(''21-MAY-2013'',''DD-MON-YYYY'')) FROM dual
    UNION
    SELECT TO_date(NULL) NUM FROM dual;

    72.What will be the outcome of the query given above? (Assume that the SYSDATE is 1st July, 2013)

    1. It executes successfully with correct results
    2. It executes successfully but with no results
    3. It throws an ORA error
    4. None of the above

    Answer: C. NUMBER and DATE do not belong to same data type fail. Here a number obtained by MONTHS_BETWEEN is compared with a DATE and hence the error.

    73.Assume that the SELECT statement in the 2nd query is modified as below:

    SELECT to_number (NULL) NUM FROM dual;

    What will be the outcome because of this change?

    1. It executes successfully with correct results
    2. It executes successfully but with no results
    3. It throws an ORA error
    4. None of the above

    Answer: A.

    74.Examine the table structures and consider the following query:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id  "Employee ID"
    FROM employees
    UNION
    SELECT employee_id  "EMP ID"
    FROM job_history;

    Which of the below column headings will display in the result set?

    1. EMP ID
    2. Employee ID
    3. EMPLOYEE_ID
    4. ORA error because the column names must be same in the component queries.

    Answer: B. The columns in the queries that make up a compound query can have different names, but the output result set will use the names of the columns in the first query.

    Examine the two table structures given and consider the following query and answer the questions 75 and 76 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id
    FROM employees e
    UNION
    SELECT employee_id
    FROM job_history j
    ORDER BY j.employee_id ;

    75.What will be the outcome of the query given above?

    1. The results will be ordered by the employee ID from the JOB_HISTORY table
    2. The results will be ordered by the employee ID from the EMPLOYEES table
    3. There will be no ordering of the results
    4. ORA error

    Answer: D. The ORDER BY should be done based on the names of the columns from the first query and not from the 2nd query columns.

    76.Which of the following ORDER BY clauses can replace the erroneous ORDER BY in the query given above?

    1. ORDER BY e.employee_id
    2. ORDER BY j.2
    3. ORDER BY 1
    4. None of the above, ORDER BY is not allowed in the query

    Answer: C. This is a more generic specification and Oracle will order based on the first column of the first query.

    77.Consider the following exhibit and answer the question below:

    Table AUDIT_YEARLY Table AUDIT
    SELECT au_doc
    From audit
    UNION
    SELECT au_doc
    From audit_yearly;

    What will be the outcome of the above given query?

    1. It gives the Audit documents between the two tables
    2. It gives an ORA error on execution
    3. It gives the Audit documents from the table AUDIT
    4. None of the above

    Answer: B. LONG columns cannot be used with SET operators.

    78.Consider the query given below:

    SELECT col_1
    From TABLE (package1.proc1)
    UNION
    SELECT col_1
    From TABLE (package2.proc2);

    What will be the outcome of the query given above?

    1. It executes successfully with duplicates
    2. It executes successfully without duplicates
    3. It throws an ORA error
    4. None of the above

    Answer: C. TABLE expressions cannot be used with SET operators.

    Examine the two table structures given and consider the following query. Answer the questions 79 and 80 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id , job_id
    FROM employees E
    UNION
    SELECT employee_id , job_id
    FROM job_history J
    FOR UPDATE OF job_id;

    79.What happens when the query is executed?

    1. ORA error
    2. Employee_id and job_id
    3. Employee_id
    4. None of the above

    Answer: A. The FOR UPDATE clause cannot be used with the query combined using the SET operators.

    80.What will be the outcome of the following query?

    SELECT * from employees
    UNION
    SELECT job_id FROM job_history;;
    1. It will give all the columns from the employees tables and only the job_id column from the job_history table
    2. It will throw an error as the number of columns should match in the component queries
    3. Neither B or C
    4. None of the above

    Answer: B.

    81.If UNION, UNION ALL, INTERSECT are used in one SQL statement which of the following is true regarding the SQL statement?

    1. UNION, UNION ALL will be executed first and then the result set will go for the INTERSECT statement.
    2. The execution of INTERSECT will precede the UNION and UNION ALL execution.
    3. The execution will be done from right to left taking into consideration all the operators at the same time.
    4. The execution will be done from left to right taking into consideration all the operators at the same time.

    Answer: D.

    82.Consider the query given below and answer the question that follow:

    SELECT ''3'' FROM dual
    INTERSECT
    SELECT 3f FROM dual;

    What is true regarding the execution of the query given above?

    1. It executes successfully.
    2. It throws an error
    3. It gives the result 3.
    4. It gives the result 3f

    Answer: B. Character literals must be enclosed within single quotes.

    83.Which of the following is false for set operators used in SQL queries?

    1. The set operators are valid when used on columns with the LONG datatype.
    2. The set operators are not valid on columns of type BLOB, CLOB, BFILE, VARRAY, or nested table.
    3. In order for the select query containing an expression, a column alias should be provided in order to refer it to the order_by_clause.
    4. You cannot use these operators in SELECT statements containing TABLE collection expressions.

    Answer: A. SET operators are unsupported for LONG, CLOB and BLOB data types.

    84.Examine the given table structure and evaluate the following SQL statement:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT employee_id , last_name "Last Name"
    FROM employees
    WHERE department_id  = 100
    UNION
    SELECT employee_id  EMPLOYEE_NO, last_name
    FROM employees
    WHERE department_id  = 101;

    Which ORDER BY clauses are valid for the above query? (Choose all that apply.)

    1. ORDER BY 2,1
    2. ORDER BY EMPLOYEE_NO
    3. ORDER BY 2, employee_id
    4. ORDER BY “EMPLOYEE_NO”

    Answer: A, C. The ORDER BY clause must reference column by its position or the name referred by the first query.

    85.Which of the following clauses would you use to exclude the column from the 2nd query out of the two queries combined using SET operators?

    1. GROUP BY
    2. ORDER BY
    3. MINUS
    4. UNION

    Answer: C.

    86.Examine the given table structure as given. What will be the outcome of the below query?

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT distinct department_id
    FROM employees
    WHERE salary > ANY (SELECT AVG (salary)
    FROM employees
    GROUP BY department_id )
    UNION
    SELECT *
    FROM employees
    WHERE salary > ANY (SELECT MAX (salary)
    FROM employees
    GROUP BY department_id );
    1. It will display all the department IDs which have the average salaries and the maximum salaries
    2. It will throw an ORA error as the no. of columns selected in both the query is different
    3. It will display all the department IDs which have the average salaries
    4. It will display all the department IDs which have the maximum salaries

    Answer: B. The no. of columns should be the same.

    87.What among the following is true about the UNION operator?

    1. UNION operates over only the first column in the SELECT list
    2. UNION operates over the first columns of the SELECT lists in the component queries
    3. UNION operates over all the columns being selected.
    4. None of the above

    Answer: C. UNION operates over all the columns in the SELECT list and does not ignore any columns.

    88.You need to display the departments where the employees with the JOB IDs ”SA_REP” or ”ACCOUNTANT” work. Which of the following queries will fetch you the required results? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT department_id
      FROM employees E
      Where job_id = ''SA_RE''
      UNION
      SELECT department_id
      FROM employees E
      Where job_id = ''ACCOUNTANT
    2. SELECT department_id
      FROM employees E
      Where job_id = ''SA_REP''
      UNION ALL
      Select department_id
      FROM employees E
      Where job_id = ''ACCOUNTANT
    3. SELECT department_id
      FROM employees E
      Where job_id = ''SA_REP''
      INTERSECT
      Select department_id
      FROM employees E
      Where job_id = ''ACCOUNTANT
    4. SELECT department_id
      FROM employees E
      Where job_id = ''SA_REP''
      MINUS
      Select department_id
      FROM employees E
      Where job_id = ''ACCOUNTANT

    Answer: A.

    89.Which of the following statement is true about the ordering of rows in a query which uses SET operator?

    1. It is not possible to use ORDER BY in the individual queries that make a compound query.
    2. An ORDER BY clause can be appended to the end of a compound query.
    3. The rows returned by a UNION ALL will be in the order they occur in the two source queries.
    4. The rows returned by a UNION will be sorted across all their columns, right to left.

    Answer: A, B, C.

    90.The UNION operator was used to fulfill which of the following function before the ANSI SQL syntax in place?

    1. RIGHT OUTER JOIN
    2. LEFT OUTER JOIN
    3. EQUI-JOIN
    4. FULL OUTER JOIN

    Answer: D.

    Answer the related questions 91 and 92 given below. Consider the table structures as given here:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)

    91.You need to find the job IDs which do not have any JOB history logged for them. Which of the following queries will work? (Consider the given table structures)

    1. SELECT job_id
      FROM employees
      UNION ALL
      SELECT job_id
      FROM job_history;;
    2. SELECT job_id
      FROM employees
      MINUS
      Select job_id
      FROM job_history;;
    3. SELECT job_id
      FROM employees
      UNION
      SELECT job_id
      FROM job_history;;
    4. None of the above

    Answer: B.

    92.Consider the following query:

    SELECT distinct  job_id
    FROM employees
    NATURAL JOIN job_history ;

    Which of the following queries are identical to the above query?

    1. SELECT job_id
      FROM employees
      UNION
      SELECT   job_id
      FROM job_history;;
    2. SELECT job_id
      FROM employees
      UNION ALL
      SELECT job_id
      FROM job_history;;
    3. SELECT job_id
      FROM employees
      MINUS
      Select job_id
      FROM job_history;;
    4. SELECT job_id
      FROM employees
      INTERSECT
      SELECT job_id
      FROM job_history;;

    Answer: A.

    Examine the table structures given here. Consider the query given below and answer the related questions 93 to 97 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT job_id
    FROM employees
    UNION ALL
    SELECT job_id
    FROM job_history;;

    93.If the EMPLOYEES table contains 5 records and the JOB_HISTORY contains 3 records, how many records will be obtained from the below query?

    1. 4
    2. 3
    3. 0
    4. 8

    Answer: D. UNION ALL Returns the combined rows from two queries without sorting or removing duplicates.

    94.If the UNION ALL operator is replaced with UNION operator, how many records will be obtained? (Assume there are 6 distinct values in both the tables)

    1. 5
    2. 3
    3. 2
    4. 6

    Answer: D. UNION Returns the combined rows from two queries, sorting them and removing duplicates.

    95.If the UNION ALL operator is replaced with MINUS operator, how many records will be obtained? (Assume there are 3 distinct values in EMPLOYEES and 2 in JOB_HISTORY)

    1. 3
    2. 2
    3. 1
    4. 0

    Answer: C. MINUS Returns only the rows in the first result set that do not appear in the second result set, sorting them and removing duplicates.

    96.If the UNION ALL operator is replaced with INTERSECT operator, how many records will be obtained? (Assume there are 3 values common between the two tables)

    1. 8
    2. 6
    3. 3
    4. 2

    Answer: C. INTERSECT Returns only the rows that occur in both queries” result sets, sorting them and removing duplicates.

    97.Consider the following query:

    1.select job_id
    2. from employees
    3.ORDER BY department_id
    4.UNION ALL
    5.select job_id
    6.FROM job_history;
    7.ORDER BY department_id ;

    The above query generates an error. Which line in the above query generates an error?

    1. 3
    2. 7
    3. 2
    4. No error is obtained

    Answer: A. ORDER BY should only appear at the end of the compound query and not in the component queries.

    98.Which of the following SET operator features are supported in SQL/Foundation:2003 but not by Oracle?

    1. UNION ALL
    2. MINUS ALL
    3. INTERSECT ALL
    4. EXCEPT ALL

    Answer: B, C, D.

    99.You need to find out the common JOB IDs (excluding duplicates) in the departments 100 and 200. Which query will you fire to get the required results? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT job_id from employee
      WHERE department_id  = 100
      INTERSECT
      SELECT job_id from employee
      WHERE department_id  = 200;
    2. SELECT job_id from employee
      WHERE department_id  = 100
      UNION ALL
      SELECT job_id from employee
      WHERE department_id  = 200;
    3. SELECT job_id from employee
      WHERE department_id  = 100
      MINUS
      Select job_id from employee
      WHERE department_id  = 200;
    4. SELECT job_id from employee
      WHERE department_id  = 100
      INTERSECT ALL
      Select job_id from employee
      WHERE department_id  = 200;

    Answer: A.

    100.If a compound query contains both a MINUS and an INTERSECT operator, which will be applied first? (Choose the best answer.)

    1. The INTERSECT, because INTERSECT has higher precedence than MINUS.
    2. The MINUS, because MINUS has a higher precedence than INTERSECT.
    3. The precedence is determined by the order in which they are specified.
    4. It is not possible for a compound query to include both MINUS and INTERSECT.

    Answer: C. All set operators have equal precedence, so the precedence is determined by the sequence in which they occur.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Creating Other Schema Objects nhận dự án làm có lương

    SQL – Creating Other Schema Objects Questions



    1. Which database object among the following provides a layer of abstraction between the users and the data?

    1. Table
    2. Rows
    3. Views
    4. Synonyms

    Answer: C, D. Views and Synonyms do not store data themselves. A view is a temporary or virtual table used to retrieve data stored in underlying database tables.

    2. Which of the following data base objects can generate serial numbers?

    1. Synonyms
    2. Views
    3. Tables
    4. Sequences

    Answer: D. A sequence can be created to generate a series of integers. The values generated by a sequence can be stored in any table. A sequence is created with the CREATE SEQUENCE command.

    3. What is true about views?

    1. They are equal to tables
    2. They store data from one or many tables
    3. We can execute SELECT and other DMLs on Simple views
    4. Views share the same namespace as tables and hence a table and a view cannot have the same name

    Answer: C, D. DML operations aren”t permitted on views that include group functions, a GROUP BY clause, the ROWNUM pseudocolumn, or the DISTINCT keyword.

    4. Why are views useful? (Choose the most appropriate answer)

    1. Because they have shorter names than tables
    2. To prevent users from accessing the columns of tables
    3. To simplify user SQL
    4. All of the above

    Answer: B, C. A view is a temporary or virtual table used to retrieve data stored in underlying database tables. The view query must be executed each time the view is used. A view can be used to simplify queries or restrict access to sensitive data.

    5. In which of the below scenarios, DML operations on a view are not possible?

    1. View contains GROUP BY clause
    2. Base tables contain NOT NULL columns but not selected in the view query
    3. View query uses ROWNUM pseudocolumn
    4. All of the above

    Answer: D. DML operations aren”t permitted on views that include group functions, a GROUP BY clause, the ROWNUM pseudocolumn, or the DISTINCT keyword.

    6. Where can views get their data from?

    1. Tables from the same schema
    2. Tables from different schema
    3. Both A and B
    4. None of the above

    Answer: C.

    Consider the given table structure and the following statement and answer the questions 7 to 9 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE VIEW emp_details AS
    SELECT hire_date, job, salary, department_id FROM employees;
    

    7. You issue the below query. How many columns will the user see as a result of the below query?

    SELECT * FROM emp_details WHERE department_id= 100;
    
    1. 0
    2. 1
    3. 2
    4. 4

    Answer: D. Since the view definition is based on four columns from the EMPLOYEES table, a query on a view with all column will show those four columns only.

    8. You need to get the department name in addition to the above 4 columns. Which of the following query will give you the required results?

    1. SELECT E.*, dept_name
      FROM departments D join emp_details E
      ON (E.department_id= D.dept_id);
    2. SELECT hire_date, job, salary, dept_name FROM emp_details
    3. This is not possible a view cannot be joined to other tables
    4. None of the above

    Answer: A. A view can be joined with other tables or views in a SELECT query.

    9. You need to find the maximum salary along with the department name in addition to the 4 columns selected in the view. Which of the following query will give you the required results?

    1. Select dept_name, e.salary
      FROM departments D join emp_details E
      On (E.department_id= D.dept_id);
    2. Select dept_name, max(salary)
      FROM departments D join emp_details E
      On (E.department_id= D.dept_id)
      Group by dept_name;
    3. View cannot appear in queries using group functions
    4. Select dept_name, max(salary)
      FROM departments D join emp_details E
      On (E.department_id= D.dept_id);

    Answer: B.

    10. What among the following is true about synonyms?

    1. PUBLIC and PRIVATE synonyms can have the same name for the same table
    2. DROP SYNONYM will remove a synonym
    3. DROP PUBLIC SYNONYM can be executed only by a SYSDBA
    4. None of the above

    Answer: A, C. A synonym can be a private synonym, which users use to reference objects they own,or a public synonym, which users use to access another user”s database objects. Only SYSDBA or a user with DBA privileges can create a public synonym.

    11. What is true about creating a view? (Choose the most appropriate answer)

    1. A view can only be created from a table
    2. A view can only be created from one table
    3. A view can be created from one or many tables or views
    4. None of the above

    Answer: C. A view containing expressions or functions or joining multiple tables is considered a complex view. A complex view can be used to update only one table.

    12. Which of the following privileges are required to create views in one”s own schema?

    1. CREATE TABLE system privilege
    2. CREATE VIEW system privilege
    3. ALTER VIEW system privilege
    4. CREATE ANY VIEW system privilege

    Answer: B. CREATE VIEW privilege is required by a user to create a view in its own schema.

    13. Which of the following privileges are required to create views in someone else”s schema?

    1. CREATE ANY VIEW
    2. CREATE VIEW
    3. Both A and B
    4. None of the above

    Answer: A. CREATE ANY VIEW privilege is required by a user to create a view in other user”s schema.

    14.Which of the following are supported for an object view or relational view?

    1. LOBs
    2. Object types
    3. REF data types
    4. All of the above

    Answer: D.

    15. What among the following are different types of Views?

    1. Simple views
    2. Complex views
    3. Both A and B
    4. None of the above

    Answer: C. Simple and Complex views are two types of views. Simple views are based on a subquery that references only one table and doesn”t include group functions, expressions, or GROUP BY clauses. Complex views are based on a subquery that retrieves or derives data from one or more tables and can contain functions or grouped data.

    16. What is true about a simple view?

    1. DML statements can be issued most of the times against simple views
    2. There is only one source base table
    3. No group functions are used
    4. All of the above

    Answer: D. Simple views are based on a subquery that references only one table and doesn”t include group functions, expressions, or GROUP BY clauses.

    17.What is true about a complex view?

    1. DML statements cannot be issued against complex views
    2. Contain multiple base tables
    3. Aggregations cannot be performed
    4. All of the above

    Answer: D. Complex views are based on a subquery that retrieves or derives data from one or more tables and can contain functions or grouped data.

    18.Which keyword combination should be used to implicitly drop a view (if it exists) and create a new view with the same name?

    1. CREATE VIEW
    2. REPLACE VIEW
    3. CREATE OR REPLACE VIEW
    4. None of the above

    Answer: C. The OR REPLACE option notifies Oracle 11g that a view with the same name might already exist; if it does, the view”s previous version should be replaced with the one defined in the new command.

    19.How is a view stored in the data dictionary?

    1. As a WHERE clause
    2. As a CREATE statement
    3. As an UPDATE statement
    4. As a SELECT statement

    Answer: D.

    20.Which of the following can contain single-row functions?

    1. Inline Views
    2. Simple Views
    3. Complex Views
    4. Composite Views

    Answer: A, B. Single-row functions can be used in Inline as well as Simple views.

    21.Which of the following can contain a group of data?

    1. Composite View
    2. Simple View
    3. Complex View
    4. None of the above

    Answer: C. Complex view can use group function in the query.

    22.What among the following is true about a View?

    1. Sub-queries can be embedded in a CREATE VIEW statement
    2. A sub-query used in the CREATE VIEW statement has to have a simple SELECT syntax
    3. You cannot use a WHERE clause in a sub-query when it is used in the CREATE VIEW statement
    4. None of the above

    Answer: A. View definition can make use of sub-queries.

    23.Which of the following can create a view even if the base table(s) does not exist?

    1. NOFORCE
    2. FORCE
    3. OR REPLACE
    4. CREATE VIEW

    Answer: B. Ff you include the FORCE keyword in the CREATE clause, Oracle 11g creates the view in spite of the absence of any referenced tables. NOFORCE is the default mode for the CREATE VIEW command, which means all tables and columns must be valid, or the view isn”t created.

    24.Which of the following commands ensures that no DML operations can be performed on a view?

    1. NOFORCE
    2. FORCE
    3. WITH READ ONLY
    4. OR REPLACE

    Answer: C. The WITH READ ONLY option prevents performing any DML operations on the view. This option is used often when it”s important that users can only query data, not make any changes to it.

    25.What is true about the NOFORCE option in CREATE VIEW statement?

    1. It creates a view even if the base table(s) does not exist.
    2. It creates a view only if the base table(s) exists.
    3. It is the default while creating a view.
    4. None of the above

    Answer: B, C. NOFORCE is the default mode for the CREATE VIEW command, which means all tables and columns must be valid, or the view isn”t created.

    26.What is true about the OR REPLACE keyword?

    1. Object privileges are lost when a view is created using this keyword
    2. There is no need of re granting the object privileges previously granted on it
    3. Neither of A nor B
    4. None of the above

    Answer: B. The OR REPLACE option notifies Oracle 11g that a view with the same name might already exist; if it does, the view”s previous version should be replaced with the one defined in the new command.

    27.What is true with respect to accessing the below view? (Assume the table structure given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE VIEW salVU100
    AS SELECT employee_id  ID_NUMBER, last_name NAME, salary*12 ANNUAL_SAL
    FROM employees E
    WHERE department_id= 100;
    
    1. The view has to be accessed by the original column names defined in the base table
    2. The view has to be accessed by the aliases given in the view query
    3. View is a simple view
    4. None of the above

    Answer: B, C. View must refer the column alias if the view definition contains alias for the columns.

    28.What is true with respect to accessing the below view? (Assume the table structure given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE VIEW salVU100 (ID_NUMBER, NAME, ANNUAL_SAL)
    AS SELECT employee_id , last_name, salary*12
    FROM employees E
    WHERE department_id= 100; 
    1. It is not mandatory that the number of aliases match the no. of expressions in the sub-query
    2. It is mandatory that the no. of aliases listed must match the no. of expressions selected in the sub-query
    3. It is mandatory to give aliases while creating a view
    4. None of the above

    Answer: B. If the alias are specified in the view header, same number of columns must be selected in the SELECT query.

    29. Consider the following statement and the given table structure:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    CREATE OR REPLACE VIEW empVU100
    (ID_NUMBER, NAME, ANNUAL_SAL, DEPT_ID)
    AS
    SELECT employee_id , first_name ||'' ''|| last_name, salary, department_id
    FROM employees
    WHERE department_id= 100;
    

    What is true about the column aliases as in the above query?

    1. Column aliases are listed in a random order as the columns in the sub-query
    2. Column aliases are listed in the same order as the columns in the sub-query
    3. Column aliases are mandatory while using the CREATE OR REPLACE keyword
    4. We cannot use concatenation when we use the CREATE OR REPLACE

    Answer: B.

    Consider the following statement and answer the questions 30 to 34 that follow:

    CREATE OR REPLACE VIEW dept_sum_vu (name, minsal, maxsal, avgsal)
    AS
    SELECT d.dept_name, MIN(e.salary), MAX(e.salary), AVG (e.salary)
    FROM employees e JOIN departments d
    ON (e.department_id= d.dept_id)
    GROUP BY d.dept_name;
    

    30.What can be said about the statement given above?

    1. Alternative names have been given for the view
    2. Giving alternative names is mandatory if any column is derived from a function or an expression
    3. Both A and B
    4. None of the above

    Answer: C. Specifying alias name is good practice to improve the readability of the code and the view queries.

    31.What will happen if the above statement is modified as below?

    CREATE OR REPLACE VIEW dept_sum_vu(name, maxsal, minsal, avgsal)
    AS
    SELECT d.dept_name, MIN(e.salary), MAX(e.salary), AVG (e.salary)
    FROM employees e JOIN departments d
    ON (e.department_id= d.dept_id)
    GROUP BY d.dept_name;
    
    1. It will be no different than the original statement
    2. It will execute successfully giving the same results but change in alias names.
    3. It will throw an ORA error
    4. None of the above

    Answer: B. The sequence of the column alias not matters much as they don”t carry any behavioral attribute.

    32.Determine the output of the below DELETE statement.

    DELETE FROM dept_sum_vu; 
    1. It will delete the view
    2. It will remove all the rows from the view but the structure of the view will remain the same
    3. It will throw an ORA error
    4. None of the above

    Answer: C. The view DEPT_SUM_VU is a complex view. DML operations cannot be performed on a complex view.

    33.Suppose you modify the query given above to the following:

    CREATE OR REPLACE VIEW dept_sum_vu(name, sal)
    AS
    SELECT d.dept_name, e.salary
    FROM employees e JOIN departments d
    ON (e.department_id= d.dept_id)
    Where rownum < 10;
    

    What will be the impact of the modification?

    1. The view can be updated to update the values in EMPLOYEES and DEPARTMENTS tables
    2. Data in EMPLOYEES and DEPARTMENTS tables cannot be deleted through view
    3. Data in EMPLOYEES and DEPARTMENTS tables can be inserted through view
    4. A column can be added to EMPLOYEES table through the view

    Answer: B. DML operations cannot be performed on complex views. DEPT_SUM_VU is a complex view as it joined multiple tables. DDL operations are not possible on views.

    34.Suppose you select DISTINCT departments and employee salaries in the view query used in above question. What will be the outcome if you try to remove rows from the view dept_sum_vu?

    1. The rows will get removed without any error
    2. Only the first 10 rows will get removed
    3. The rows cannot be deleted.
    4. None of the above

    Answer: C. The view DEPT_SUM_VU is still a complex view as it uses DISTINCT keyword. Hence, DML operations are not possible on it.

    35.When can the rows from a view be removed?

    1. Deletion of rows through a view is not possible
    2. It should be a simple view
    3. It should be a complex view
    4. None of the above

    Answer: B. DML operations are possible only on simple views.

    36.When can the data in a view not be modified?

    1. When there are group expressions
    2. When there is a GROUP BY clause
    3. When ROWNUM is used in the view query
    4. All of the above

    Answer: D. UPDATE is not possible on a view containing group functions, pseudocolumns or DISTINCT keyword.

    37. The JOB_HISTORY table is owned by a user “Andy”. Andy grants the SELECT privilege on the JOB_HISTORY table to another user “HR”. Which statement would create a synonym EMP_JOBS so that “HR” can execute the following query successfully?(Assume the structure of tables as given)

    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT * from EMP_JOBS; 
    1. Andy issues –
      CREATE SYNONYM EMP_JOBS for JOB_HISTORY
    2. HR issues –
      CREATE SYNONYM EMP_JOBS for andy.JOB_HISTORY
    3. HR issues –
      CREATE PUBLIC SYNONYM EMP_JOBS FOR andy.JOB_HISTORY
    4. None of the above

    Answer: B. Only SYSDBA or a user with DBA privileges can create public synonyms.

    38.Which keyword can assure that the DML operations performed on the view stay in the domain of the view?

    1. OR REPLACE
    2. CREATE
    3. WITH CHECK OPTION
    4. None of the above

    Answer: C. The WITH CHECK OPTION constraint ensures that any DML operations performed on the view (such as adding rows or changing data) don”t prevent the view from accessing the row because it no longer meets the condition in the WHERE clause.

    Consider the following table structure and the given statement and answer the questions 39 and 40 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE OR REPLACE VIEW empvu100
    AS
    SELECT * FROM employees
    WHERE department_id= 100
    WITH CHECK OPTION CONSTRAINT empvu100_ck;
    

    39.What will the above statement do?

    1. It will allow the users to perform INSERT or UPDATE on all departments
    2. It will allow the user to perform INSERT or UPDATE any row which has department 100
    3. The user can UPDATE any row in the employees table
    4. The user can INSERT rows without any restriction in the employees table

    Answer: B. The WITH CHECK OPTION constraint ensures that any DML operations performed on the view (such as adding rows or changing data) don”t prevent the view from accessing the row because it no longer meets the condition in the WHERE clause. An ORA error will be thrown if an INSERT or UPDATE will be executed on any row with a department_id other than 100.

    40.Suppose you fire an UPDATE statement as shown below:

    UPDATE empvu100
    Set department_id = 200
    Where employee_id  = 121;
    

    What will be the outcome of this statement?

    1. No rows are updated
    2. An ORA error is thrown
    3. Both A and B
    4. None of the above

    Answer: C. If the view with CHECK OPTION is updated and new record”s value violates the scope of the view, ORA exception “ORA-01402: view WITH CHECK OPTION where-clause violation” is raised.

    41.What is true about the WITH CHECK CONSTRAINT?

    1. INSERTs or UPDATEs performed through the view cannot create rows that the view cannot select
    2. Only INSERTs performed through the view cannot create rows that the view cannot select
    3. Only UPDATEs performed through the view cannot create rows that the view cannot select
    4. None of the above

    Answer: A.

    42.How can you prevent DML operations on a View?

    1. By defining a WITH CHECK OPTION constraint
    2. By defining a WITH READ ONLY option
    3. Neither of A nor B
    4. None of the above

    Answer: B. The WITH READ ONLY option prevents performing any DML operations on the view. This option is used often when it”s important that users can only query data, not make any changes to it.

    Consider the table structure and the given statement and answer the questions 43, 44 and 45 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE OR REPLACE empvu100(employee_id , first_name, job)
    AS
    SELECT employee_id , last_name, job
    FROM employees
    WHERE department_id = 100
    WITH READ ONLY;
    

    43.What is true about the above statement?

    1. The view will not be created
    2. INSERT operation on this view an will throw an ORA error
    3. On UPDATING the rows for all the employees in department 100, an ORA error will be thrown
    4. None of the above

    Answer: B, C. DML operations are not permitted on view which are created with READ ONLY option.

    44.How many rows can be deleted from the view as shown above?

    1. All rows of the view
    2. All the rows of only the department 100
    3. No rows
    4. None of the above

    Answer: C. DML operations are not permitted on view which are created with READ ONLY option.

    45.Which of the following statements will drop the view created as above?

    1. DROP READ ONLY VIEW empvu100;
    2. DROP NOFORCE empvu100;
    3. DROP VIEW empvu100;
    4. None of the above

    Answer: C. Read only view can be dropped using the DROP VIEW command.

    46.What is true about dropping a View?

    1. The columns in the view from the base tables are also dropped
    2. The definition of the view is removed from the database
    3. Dropping of a view has no effect on the underlying base table
    4. None of the above

    Answer: B, C.

    47.Which of the following privileges should a user have to drop a view?

    1. CREATE ANY VIEW
    2. CREATE VIEW
    3. DROP ANY VIEW
    4. DROP VIEW

    Answer: C.

    48.What is true about sequences?

    1. It generates integers
    2. It is a shareable object
    3. Can be used to create a PRIMARY KEY value
    4. All of the above

    Answer: D. A sequence speeds up the efficiency of accessing sequence values when cached in memory

    49.What is true about a sequence?

    1. It is created when the Oracle Database is installed
    2. It is created by a user who has CREATE SEQUENCE system privilege
    3. It cannot be shared by more than two users
    4. It drops automatically when the database is disconnected.

    Answer: B, C. CREATE SEQUENCE system privilege is required by a user to create a sequence in its own schema which cannot be shared by other users.

    50.What among the following options is true about Sequences?

    1. The integers generated through a sequence for one table cannot be used by other tables
    2. A sequence can only be incremented
    3. A sequence becomes invalid if another sequence generates the same integers
    4. A sequence can be used by many tables and they can be incremented or decremented

    Answer: D.

    Consider the following statement and answer the questions 51 to 59 that follow:

    CREATE SEQUENCE dept_deptid_seq
    INCREMENT BY 100
    START WITH 101
    MAXVALUE 9999
    NOCACHE
    NOCYCLE;
    

    51.What will be the first value generated by this sequence?

    1. 1
    2. 100
    3. 101
    4. 9999

    Answer: C. The START WITH clause establishes the starting value for the sequence. Oracle 11g begins each sequence at 1 unless another value is specified in the START WITH clause.

    52.What can be the last value generated by this sequence?

    1. 0
    2. 100
    3. 101
    4. 9999

    Answer: D. The MINVALUE and MAXVALUE clauses establish a minimum or maximum value for the sequence.

    53.What will be the 2nd value generated by this sequence?

    1. 102
    2. 100
    3. 99
    4. 9999

    Answer: A. The INCREMENT BY clause specifies the interval between two sequential values. If the sequence is incremented by a positive value, the values the sequence generates are in ascending order. However, if a negative value is specified, the values the sequence generates are in descending order. If the INCREMENT BY clause isn”t included when the sequence is created, the default setting is used, which increases the sequence by one for each integer generated.

    54.What will be the next value after the maximum integer 9999 is reached by this sequence?

    1. 101
    2. No value
    3. It will throw an ORA error
    4. None of the above

    Answer: B. The CYCLE and NOCYCLE options determine whether Oracle 11g should begin reissuing values from the sequence after reaching the minimum or maximum value.

    55.How many values will Oracle pre allocate in memory based on the sequence given above?

    1. 20
    2. 0
    3. 100
    4. 9999

    Answer: A.

    56.You execute the below query:

    SELECT dept_depid_seq.NEXTVAL from dual; 
    Assuming that the last value the sequence generated was 200, what will be the outcome of this query?
    1. 200
    2. 101
    3. 9999
    4. 201

    Answer: D. The NEXTVAL pseudocolumn will generate the next unique integer of the sequence.

    57.You execute the below query:

    SELECT dept_depid_seq.CURRVAL from dual; 
    Assuming that the last value the sequence generated was 200, what will be the outcome of this query?
    1. 200
    2. 101
    3. 9999
    4. 201

    Answer: A. The CURRVAL pseudocolumn will generate the current unique integer already generated by the sequence.

    58.Suppose you need to change the start value of this sequence to 1000. Which of the following statements will help?

    1. ALTER dept_deptid_seq
      INCREMENT BY 100
      START WITH 1000
      MAXVALUE 9999
      NOCACHE
      NOCYCLE; 
    2. The sequence has to be dropped and re-created to start the sequence from 1000.
    3. ALTER SEQUENCE dept_deptid_seq
      START WITH 101
    4. ALTER SEQUENCE dept_deptid_seq
      INCREMENT BY 100
      START WITH 101
      CYCLE;

    Answer: B. Starting number of a sequence cannot be modified. Oracle raises the exception “ORA-02283: cannot alter starting sequence number”.

    59.Suppose that the above sequence is altered as below:

    ALTER SEQUENCE dept_deptid_seq
    INCREMENT BY 100
    START WITH 101
    MAXVALUE 99
    NOCACHE
    NOCYCLE; 

    What will be the outcome of this alteration?

    1. ORA error
    2. The maximum value for the altered sequence will now be 99
    3. Neither of A nor B
    4. None of the above

    Answer: A. The MAXVALUE cannot be less than the START WITH value while altering a sequence.

    60.When can we use the CYCLE option in Sequences?

    1. If we want to purge the old rows faster
    2. If we do not want to use the sequence to generate PRIMARY KEY values
    3. Both A and B
    4. None of the above

    Answer: C. The CYCLE and NOCYCLE options determine whether Oracle 11g should begin reissuing values from the sequence after reaching the minimum or maximum value. If the CYCLE option is specified and Oracle 11g reaches the maximum value for an ascending sequence or the minimum value for a descending sequence, the CYCLE option initiates the cycle of numbers again.

    61.What is true about NEXTVAL pseudo column?

    1. It re-generates the CURRVAL of a sequence
    2. It returns the next available sequence value
    3. It can return duplicate values
    4. It generates the same values for different users

    Answer: B. The pseudocolumn NEXTVAL (NEXT VALUE) is used to actually generate the sequence value. In other words, it calls the sequence object and requests the value of the next number in the sequence. After a value is generated, it”s stored in the CURRVAL (CURRENT VALUE) pseudocolumn so that you can reference it again.

    62.What is true about CURRVAL pseudo column?

    1. CURRVAL can be used before NEXTVAL with respect to a sequence
    2. CURRVAL gives the current value of a sequence
    3. CURRVAL can give duplicate values
    4. None of the above

    Answer: B.

    63.When can NEXTVAL and CURRVAL be used?

    1. SET clause of an INSERT statement
    2. VALUES clause of an UPDATE statement
    3. The SELECT list of a SELECT statement that is not part of a sub-query
    4. The SELECT list of an INSERT statement

    Answer: C, D. The sequence can be used in SELECT query, PL/SQL cursor or in IAS (INSERT-AS-SELECT)direct operations.

    64.When can NEXTVAL and CURRVAL not be used?

    1. The SELECT list of a view
    2. The SELECT statement with the DISTINCT keyword
    3. A sub-query in SELECT, DELETE or UPDATE statement
    4. All of the above

    Answer: D.

    Consider the given statement and answer the questions 65 and 66 that follow:

    CREATE TABLE employees
    (employee_id  NUMBER(4) DEFAULT emp_empid_seq.CURRVAL,
     department_id NUMBER(4));
    

    65.What will be the outcome of this statement? (Assume that emp_empid_seq is sequence used to generate employee ID values)

    1. Table will be created
    2. The department_id column will have the values from the sequence generated for the employee ID
    3. The department_id column will have a DEFAULT value
    4. ORA error

    Answer: D. Pseudocolumns cannot be specified in DEFAULT clause of a column definition.

    66.What will be the outcome of this statement if the CURRVAL is replaced with NEXTVAL? (Assume that emp_empid_seq is generated to generate employee ID values)

    1. Table will be created
    2. The department_id column will have the values from the sequence generated for the employee ID
    3. The department_id column will have a DEFAULT value
    4. ORA error

    Answer: D. Pseudocolumns cannot be specified in DEFAULT clause of a column definition.

    Examine the given exhibit giving the structures of the tables Departments and Location. Answer the questions 67 and 68 that follow:

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SQL> desc locations
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     LOCATION_ID		 NOT NULL NUMBER(4)
     STREET_ADDRESS 		  VARCHAR2(40)
     POSTAL_CODE			  VARCHAR2(12)
     CITY			 NOT NULL VARCHAR2(30)
     STATE_PROVINCE 		  VARCHAR2(25)
     COUNTRY_ID			  CHAR(2)

    67.You need to insert a new department named “HR” in the location ID 1000. Which of the following statements will give you the required results?

    1. INSERT INTO departments (dept_id, dept_name, location_id)
      VALUES (dept_deptid_seq.NEXTVAL, ''HR'', 1000); 
    2. INSERT INTO departments (dept_id, dept_name, location_id)
      VALUES (dept_deptid_seq.NEXTVAL, "HR", 1000); 
    3. INSERT INTO departments (dept_id, dept_name, location_id)
      VALUES (dept_deptid_seq.CURRVAL, ''HR'', 1000); 
    4. None of the above

    Answer: A.The option C will cause a ”Unique constraint violation” as it will try to insert current value of department id which aleady exists in the DEPARTMENTS table.

    68.Suppose you execute the below query before inserting the values as shown in the option A in question 67. What will be the outcome of the query?

    SELECT dept_deptid_seq.CURRVAL FROM DUAL; 
    1. ORA error
    2. It will give the current value of the sequence
    3. Neither of A nor B
    4. None of the above

    Answer: B. When a user logs in to Oracle 11g, no value is initially stored in the CURRVAL pseudocolumn; the current value is NULL. After a NEXTVAL call has been issued to generate a sequence value, CURRVAL stores that value until the next value is generated. CURRVAL contains only the last value generated.

    69.How can gaps occur in the values of a sequence?

    1. When a rollback occurs
    2. The system crashes
    3. A sequence is used in another table
    4. All of the above

    Answer: D.

    70.What is true about caching sequence values?

    1. Caching sequence values is not possible in Oracle
    2. The cache is populated when the maximum limit of the sequence is reached
    3. Caching starts the first time when the sequence is referred
    4. None of the above

    Answer: C. If the NOCACHE option is specified when the sequence is created, each number is generated when the request is received. However, if an organization”s transactions require large amounts of sequential numbers throughout a session, the CACHE option can be used to have Oracle 11g generate a set of values ahead of time and store them in the server”s memory. Then, when a user requests a sequence value, the next available value is assigned-without Oracle 11g having to generate the number. On the other hand, if the CACHE option isn”t specified, Oracle 11g assumes a default option of CACHE 20 and stores 20 sequential values in memory automatically for users to access.

    71.The following query for the sequence EMP_EMPID_SEQ is executed after a transaction which inserted five employee details.

    Select emp_empID_seq.CURRVAL from dual; 

    Suppose the employee transaction rolled back. What will be the result of the above query?

    1. The sequence value at the starting of employee transaction
    2. NULL
    3. The sequence value at the end of employee transaction
    4. None of the above

    Answer: C. Sequence values are unaffected by commit or rollback. If a transaction which uses sequence generator is rolled back, the sequence values are wasted and cannot be recovered.

    72.Which of the following privileges are required to modify a sequence?

    1. CREATE OR REPLACE privilege
    2. ALTER privilege for the sequence
    3. ALTER TABLE privilege
    4. UPDATE privilege

    Answer: B. To alter a sequence, the sequence must be in your own schema, or you must have the ALTER object privilege on the sequence, or you must have the ALTER ANY SEQUENCE system privilege.

    73.What happens when a sequence is altered?

    1. The existing integers already generated by the sequence are altered as well
    2. Only the future integers are affected
    3. The sequence stops caching the future integers
    4. None of the above

    Answer: B. By using the ALTER SEQUENCE command, any changes are applied only to values generated after the modifications are made.

    74.Suppose you need to drop a sequence. Which of the following commands will help?

    1. ALTER SEQUENCE sequence_name START WITH NULL;
    2. DROP sequence_name;
    3. DROP SEQUENCE sequence_name;
    4. None of the above

    Answer: C. The DROP command is used to drop a sequence

    75.Which of the following privileges will allow you to drop a sequence? (Choose the most appropriate answer)

    1. ALTER SEQUENCE
    2. ALTER TABLE
    3. DROP SEQUENCE
    4. DROP ANY SEQUENCE

    Answer: D. To drop a sequence, either the sequence must be in your own schema or you must have the DROP ANY SEQUENCE system privilege.

    76.What is true about Indexes?

    1. Indexes are only manually created
    2. Indexes are only automatically created
    3. Both A and B
    4. None of the above

    Answer: D. Indexes can be created manually as well as automatically following certain actions like creating a primary key or unqiue constraint.

    77.Which of the following is used by an index to locate the data quickly?

    1. ROWNUM
    2. ROWID
    3. Sequence
    4. None of the above

    Answer: B. An Oracle 11g index is a database object that stores a map of column values and the ROWIDs of matching table rows. A ROWID is the physical address of a table row.

    78.What happens when there is no index on a column of a table?

    1. The data is located quickly
    2. There is a full table scan
    3. The table cannot be created
    4. The table cannot be altered

    Answer: B.

    79.What among the following is true about an Index?

    1. Index reduces the disk I/O
    2. Index locates data quickly
    3. Indexes are logically and physically independent of the table that they index
    4. All of the above

    Answer: D.

    80.What will happen if an index is dropped?

    1. The column on which the index is created, is dropped too
    2. The table on which the index is created, is dropped too
    3. Indexes once created cannot be dropped
    4. As Indexes are logically and physically independent objects, they can be dropped without affecting other objects

    Answer: D. Indexes are the objects which are physically stored in schema. Dropping an index doesn”t impacts other objects.

    81.What happens when a table is dropped?

    1. The indexes still remain as they are logically and independent objects
    2. The indexes in the table are also dropped
    3. Neither of A nor B
    4. None of the above

    Answer: B.

    82.How are indexes created automatically?

    1. When we create a table
    2. When a table is altered
    3. When a PRIMARY KEY is defined on a column (or group of columns) of a table
    4. When a UNIQUE KEY constraint is defined in the table definition

    Answer: C, D.

    83.For which of the following objects, a synonym can be created?

    1. Tables and views only
    2. Table, view and sequence
    3. Stored procedure, function, or package
    4. Synonym

    Answer: B, C, D. The schema object for which you are creating the synonym can be of the following types:Table or object table, View or object view, Sequence, Stored procedure, function, or package, Materialized view, Java class schema object, User-defined object type, Synonym

    84. Which of the following can you use to reference a table owned by another user?

    1. INDEX
    2. TABLE
    3. SYNONYMS
    4. SEQUENCES

    Answer: C. A synonym is an alternative name or alias for a database object.

    85.What among of the following is an example of a Non-unique index?

    1. PRIMARY KEY
    2. UNIQUE KEY
    3. FOREIGN KEY
    4. None of the above

    Answer: C.

    86.Which of the following is the main and basic type of an Index?

    1. Bitmap
    2. B-tree
    3. Unique
    4. Non-unique

    Answer: A, B. The B-tree (balanced-tree) index is the most common index used in Oracle. You can create this type of index with a basic CREATE INDEX statement. A bitmap index varies in structure and use from a B-tree index. This index is useful for improving queries on columns that have low selectivity (low cardinality, or a small number of distinct values).

    87.You need to speed up a query by creating an index on the FIRST_NAME of the EMPLOYEES table. Which of the following statements can you use? (Assume the table structure as shown)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. CREATE INDEX emp_first_name_idx
      ON employees (first_name); 
    2. CREATE INDEX emp_first_name_idx
      ON employees first_name; 
    3. ALTER INDEX emp_first_name_idx
      ON employees (first_name); 
    4. None of the above

    Answer: A.

    88.What does the UNIQUE keyword do while creating indexes?

    1. It specifies that the value of the column(s) upon which the index is created must be unique
    2. You cannot use the UNIQUE keyword when creating indexes
    3. It specifies that the index that is created can be used only by one table
    4. None of the above

    Answer: A. A unique index is typically created automatically when a PRIMARY KEY or UNIQUE constraint is defined on a column. Unique indexes can also be explicitly created by including the UNIQUE keyword in the CREATE INDEX statement.

    89.What will happen when you specify the keyword BITMAP while creating an Index?

    1. It creates the index with a bitmap for each distinct key.
    2. It does not create the index on each row separately
    3. Both A and B
    4. None of the above

    Answer: C.

    90.You have queries written which are expected to retrieve less than 2% to 4% of rows. Which of the following can be applied on the relevant tables to achieve the query performance of such query? (Choose the best answer)

    1. Indexes
    2. UNION set operator
    3. MINUS set operator
    4. None of the above

    Answer: A. Indexes are the best way to achieve query performance. Heavy IO operations can be reduced and simplified using index scans.

    91.In what scenarios can Indexes be useful?

    1. If the table(s) is very large
    2. If a column has less values
    3. If a column contains a large number of NULL values
    4. If a column has a wide range of values

    Answer: C, D.

    92.The table EMPLOYEES is updated frequently. When can Indexes be created on this table? (Choose the most appropriate answer)

    1. Indexes should not be created if a table is updated frequently
    2. Indexes should be created at the time when the table is created
    3. Neither of A nor B
    4. None of the above

    Answer: A. Frequent or bulk DML operations on a table with an index add an overhead of maintaining the index segment, which might affect the DML operation performance.

    93.Consider the following query and answer the following query. Assume that the EMPLOYEE_ID , DEPARTMENT_ID and FIRST_NAME columns of EMPLOYEES table are indexed. (Assume the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT first_name, last_name
    FROM employees
    WHERE comm IS NULL; 

    Will the existing indexes help in this case if there are 1 million rows in the table EMPLOYEES?

    1. Yes
    2. No
    3. It might help
    4. None of the above

    Answer: B. Indexes are not used when the query predicates do not contain the columns on which the index is created.

    94.Which of the following will remove an Index?

    1. DELETE FROM index_name; 
    2. DROP INDEX index_name; 
    3. DROP INDEX;
    4. None of the above

    Answer: B. You must have the DROP ANY INDEX privilege to drop an index.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Manipulating Data nhận dự án làm có lương

    SQL – Manipulating Data Questions



    1.What does ACID mean with respect to relational database?

    1. Accuracy, Consistency, Isolation, Database
    2. Accuracy, Concurrency, Isolation, Durability
    3. Atomicity, Consistency, Isolation, Durability
    4. Atomicity, Concurrency, Isolation, Durability

    Answer: C. All Oracle transactions comply with the basic properties of a database transaction, known as ACID properties. Atomicity states that all tasks of a transaction are performed or none of them are. There are no partial transactions. Consistency implies the transaction takes the database from one consistent state to another consistent state. Isolation means the effect of a transaction is not visible to other transactions until the transaction is committed. Durability means that changes made by committed transactions are permanent. After a transaction completes, the database ensures through its recovery mechanisms that changes from the transaction are not lost.

    2. What does the word DML stands for in Oracle SQL?

    1. Durability Management Language
    2. Database Management Language
    3. Database Manipulation Language
    4. None of the above

    Answer: C. DML stands for Data Manipulation Language.

    3. Which of the following are DML commands in Oracle Database?

    1. SELECT
    2. GROUP BY
    3. INTERSECT
    4. INSERT

    Answer: A, D. On strict grounds, SELECT is a DML command as it is one of the mandatory clauses for manipulation of data present in tables.

    4.Which of the following DML commands can be considered to be a hybrid of INSERT and UPDATE in a single statement?

    1. INTERSECT
    2. INSERT
    3. SELECT
    4. MERGE

    Answer: D. MERGE can perform INSERT and UPDATE actions in a single statement in Oracle.

    5. What all operations can MERGE statement perform in SQL?

    1. INSERT
    2. DELETE
    3. GROUP BY
    4. None of the above

    Answer: A, B. In some conditions MERGE can perform the DELETE operation too, along with INSERT and UPDATE.

    6.Which of following commands is a DDL (Data Definition Language) command but is often considered along with DML commands?

    1. DELETE
    2. INSERT
    3. TRUNCATE
    4. None of the above

    Answer: C. TRUNCATE is a DDL command. It removes the records from the table without any condition. It is not the part of any ongoing transaction and an uncommitted transaction in the session is committed after TRUNCATE is executed.

    7.Which of the following commands manipulate data basically?

    1. MINUS
    2. UPDATE
    3. TRUNCATE
    4. All of the above

    Answer: B, C. UPDATE is a DML statement to modify a column value in a table. TRUNCATE manipulates the data by removing them unconditionally from a table.

    8. Which of the following commands is used to populate table rows with data?

    1. DELETE
    2. INSERT
    3. SELECT
    4. UPDATE

    Answer: B. INSERT command is used to insert rows in a table.

    9. What is true about the INSERT statement? (Choose the most appropriate answer)

    1. It can insert data in one row of one table at a time
    2. It can insert data in many rows of one table at a time
    3. It can insert data in many rows of many tables at a time
    4. All of the above

    Answer: C. The INSERT statement is capable of inserting a row or set of rows in a single table at a time.

    10.What is true about the insertion of rows in tables?

    1. The rows can be inserted randomly
    2. Any number of rows can be inserted in a table without any restrictions
    3. Generally the rows are inserted in a table based on certain rules known as constraints
    4. All of the above

    Answer: C. Constraints are business rules imposed on the columns so as to ensure the behavior of the data coming in the column. These constraints are validated for the data during the INSERT process.

    11. What is true about the INSERT statement in Oracle SQL? (Choose the most appropriate answer)

    1. An INSERT statement can override any constraint put on the table
    2. An INSERT statement cannot be used on a table if a constraint is already placed on the table
    3. An INSERT statement can be used on a table only if a constraint is already placed on the table
    4. An INSERT statement can never insert a row that violates a constraint.

    Answer: D. Oracle raises exception if any of the data contained in the insert statement violates the constraint.

    Consider the following data set from the EMPLOYEES table along with its structure and answer the questions 12, 13 and 14:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER (6)
     FIRST_NAME			  VARCHAR2 (20)
     LAST_NAME		 NOT NULL VARCHAR2 (25)
     EMAIL			 NOT NULL VARCHAR2 (25)
     PHONE_NUMBER			  VARCHAR2 (20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2 (10)
     SALARY 			  NUMBER (8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    EMPLOYEE_ID FIRST_NAME   JOB_ID
    ------------------- ------------------ --------
    5100 	             BRUCE             CLERK
    5101 	             JESSICA           SALESMAN
    5102 	             DEBBY             SALESMAN
    

    12. Examine the structure of the EMPLOYEES table. You issue the following command:

    INSERT INTO EMPLOYEES (employee_id  , first_name , job_id) VALUES (5100, ''BRUCE'', ''CLERK'');
    

    Assuming that there is a duplicate value check constraint on the EMPLOYEE_ID column, what will be the outcome of the above statement?

    1. It will insert another row with 5100 BRUCE CLERK values
    2. It will insert another row with 51002 BRUCE CLERK values
    3. It will throw a ”Constraint violated” ORA error
    4. None of the above

    Answer: C. As the row with values “5100, BRUCE, CLERK” already exists in the table, the insert statement with same data set is not possible.

    13.You issue the following command to the data set shown above:

    INSERT INTO EMPLOYEES (employee_id  , first_name , job_id) VALUES (51003,''BRUCE'',''CLERK'');
    

    What will be the output of this statement?

    1. It will insert a new row with 51003 BRUCE CLERK values
    2. It will throw an ORA error as there cannot be another BRUCE who is a CLERK
    3. It will throw an ”Constraint violated” ORA error
    4. None of the above

    Answer: A. As there is no constraint on the columns FIRST_NAME and job_id, the INSERT will work without any error

    14. You issue the following command to the data set shown above:

    INSERT INTO EMPLOYEES (employee_id  , first_name , job_id ) VALUES (51003,''BRUCE'', NULL);
    

    What will be the output of this statement?

    1. It will insert a new row with 51003 BRUCE CLERK values
    2. It will throw an ORA error as there cannot be another BRUCE who is a CLERK
    3. It will throw an ”Constraint violated” ORA error
    4. It will insert a new row with 51003 BRUCE NULL values

    Answer: D. As there is no NOT NULL constraint on the columns FIRST_NAME and JOB_ID , the NULL value will get inserted.

    15. What among the following can be said regarding inserting of rows in tables?

    1. The user cannot interactively insert rows
    2. A query can be written with substitution variables for an interactive insertion of rows by the users
    3. When a user is prompted for inserting rows, the insert doesn”t work and it throws an ORA error
    4. None of the above

    Answer: B. An INSERT statement can make use of substitution variable to prompt the user to key in values during the runtime. It provides an interactive way of inserting data into tables

    16.Which of the following can be used to insert rows in tables?

    1. SELECT
    2. INSERT
    3. Sub-queries
    4. All of the above

    Answer: D. INSERT statement can make use of explicit INSERT, INSERT-SELECT or a sub-query method to insert data into tables.

    17. Which among the following is a common technique for inserting rows into a table? (Choose the most sensible and appropriate answer)

    1. Using SELECT clause
    2. Manually typing each value into the INSERT clause
    3. Using SET operators
    4. None of the above

    Answer: A. Using the SELECT clause is the most common technique for inserting rows into tables. It reduces the effort of manually keying in values for each column.

    18.Which of the following commands is used to change the rows that already exist in a table?

    1. INSERT
    2. UNION
    3. UPDATE
    4. SELECT

    Answer: C. UPDATE is a DML statement which is used to modify the column values in a table.

    19.What is true about the UPDATE command?

    1. It can update only one row at a time
    2. It can update only 100 rows at a time
    3. It can update unlimited rows at a time in bulk
    4. None of the above

    Answer: C. An UPDATE can update multiple rows in one or more rows at a time based on the WHERE clause conditions.

    20.Which of the following clauses decides how many rows are to be updated?

    1. SELECT
    2. WHERE
    3. FROM
    4. All of the above

    Answer: B. UPDATE statement makes use of WHERE clause to capture the set of rows which needs to be updated.

    21.What among the following is true about the UPDATE statement? (Choose the most appropriate answer)

    1. An UPDATE can update rows from only one table
    2. An UPDATE can update rows from multiple tables
    3. A single UPDATE command cannot affect rows in multiple tables
    4. None of the above

    Answer: A, C. An UPDATE statement affects rows of only one table and not multiple tables.

    Consider the following data set from the EMPLOYEES table and its structure. Answer questions 22 to 24 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    EMPLOYEE_ID FIRST_NAME   JOB_ID
    ------------------- ------------------ --------
    5100 	             BRUCE             CLERK
    5101 	             JESSICA           SALESMAN
    5102 	             DEBBY             SALESMAN
    

    22. You need to change the JOB_ID for Bruce (Employee Id 7389) to ”ACCOUNTANT”. Which of the following statements will you fire?

    1. UPDATE employees
      SET job_id  = ''ACCOUNTANT''
      WHERE employee_id   = 7389;
    2. INSERT INTO EMPLOYEES (employee_id  , first_name , job_id ) VALUES (5100,''BRUCE'', ''ACCOUNTANT'');
    3. UPDATE employees
      SET job_id  = ''ACCOUNTANT''
      WHERE job_id  = ''CLERK
    4. UPDATE employees
      SET job_id  = ''ACCOUNTANT

    Answer: A. Option B fails because it modifies the job code of all clerks to ACCOUNTANT. Option C is wrong because it update job code to ACCOUNTANT for all the employees in the table.

    Answer the following questions 23 and 24 based on the below actions –

    You issue the following query to the EMPLOYEES table with the data set as shown above.

    UPDATE employees
    Set job_id  = NULL
    Where employee_id   = 51000;

    The data set will be as shown below: (Assume that there is a duplicate value constraint on the EMPLOYEE_ID column)

    EMPLOYEE_ID FIRST_NAME   JOB_ID
    ------------------- ------------------ --------
    5100 	             BRUCE
    5101 	             JESSICA           SALESMAN
    5102 	             DEBBY             SALESMAN
    

    23. Suppose you fire an UPDATE statement to update Bruce”s JOB_ID to ”SALESMAN” (with respect to the data set shown above). What will be the outcome of the query?

    1. Bruce”s job code will still be NULL
    2. Bruce”s job code will be modified to ”SALESMAN”
    3. ORA error
    4. No action

    Answer: B. The UPDATE will add the new value to the NULL value changing the NULL to the new value

    24. You issue an UPDATE statement to update the employee id 7389 to 7900. You query the employee by its id ”7389” before committing the transaction. What will be the outcome?

    1. Update will work successfully while select will show 7389.
    2. Update will work successfully while select will show no records.
    3. Constraint on EMPLOYEE_ID will not allow it to be updated
    4. It will update successfully but all the values for the EMPLOYEE_ID 7389 will become NULL.

    Answer: B. A query in a session is consistent with the ongoing transactions. If the same query would have been executed in a different session, it would have shown the employee record with id 7389 because the active transaction in the first session is not yet committed.

    25. What among the following is a typical use of an UPDATE statement? (Select the most appropriate answer)

    1. To retrieve a row and update one of more columns of that row
    2. To modify all the rows for some columns
    3. To modify all the rows for all the columns of a table
    4. None of the above

    Answer: A. Although, the UPDATE statement can modify all column values in all rows, but typically it is used to select a row and update one or more columns.

    26. Which of the following practices appropriately describe for selecting which row set to update using the UPDATE statement?

    1. If some rows are to be updated, PRIMARY KEY constraint can be used
    2. If all rows are to be updated, WHERE clause can be considered
    3. To update a set of rows use WHERE, to update all rows of a table, put a PRIMARY KEY constraint on the table
    4. None of the above

    Answer: C.

    27. Which of the following columns in a table are not usually updated?

    1. LONG type columns in the table
    2. LOB columns in the table
    3. A primary key column which also serves as foreign key reference in another table
    4. All of the above

    Answer: C. As a common practice, the primary key columns which serve as foreign key reference in other tables, should not be updated. Though they can be updated by deferring the constraints which is usually not recommended.

    Consider the following data set and structure of the EMPLOYEES table and answer the questions 28 and 29 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    EMPLOYEE_ID FIRST_NAME   JOB_ID
    ------------------- ------------------ --------
    5100 	             BRUCE             NULL
    5101 	             JESSICA           SALESMAN
    5102 	             DEBBY             SALESMAN
    

    28. You issue an UPDATE statement as follows:

    UPDATE employees
    SET job_id  = NULL;
    

    What will be the outcome of the above statement?

    1. The first row of the data set will get updated to NULL
    2. The 3rd column of the first row will get updated to NULL
    3. The 3rd column of all the rows will get updated to NULL
    4. And ORA error will be thrown

    Answer: C. An UPDATE statement without a WHERE clause will update all the rows of the table.

    29. You issue an UPDATE statement as follows:

    UPDATE employees
    SET employee_id   = NULL;
    WHERE job_id  = ''CLERK
    

    What will be the outcome of the above statement? (Here the column EMPLOYEE_ID is marked as mandatory by putting a constraint)

    1. The first column of the data set will get updated to NULL
    2. The 3rd column of the first row will get updated to NULL
    3. The 3rd column of all the rows will get updated to NULL
    4. And ORA error will be thrown

    Answer: D. The constraints on the column must be obeyed while updating its value. In the given UPDATE statement, error will be thrown because the EMPLOYEE_ID column is a primary key in the EMPLOYEES table which means it cannot be NULL.

    30. Which of the following commands can be used to remove existing records from a table?

    1. UPDATE
    2. INSERT
    3. MINUS
    4. DELETE

    Answer: D. DELETE is used to remove the records from the table which can be optionally based upon a condition. Being a DML statement, it is the part of a transaction.

    31. What among the following is true about the DELETE statement?

    1. The DELETE statement has to be accompanied by the WHERE clause
    2. It is not mandatory to write a WHERE clause with the DELETE statement
    3. DELETE can remove data from multiple tables at a time
    4. None of the above

    Answer: B. The WHERE clause predicate is optional in DELETE statement. If the WHERE clause is omitted, all the rows of the table will be deleted.

    32.What among the following happens when we issue a DELETE statement on a table? (Choose the most appropriate answer)

    1. A prompt pops up asking the user whether he/she is sure of deleting the rows requested
    2. The rows obeying the condition given in the DELETE statement are removed immediately
    3. The requested rows are removed immediately without any prompt.
    4. None of the above

    Answer: C. As a part of the active or a new transaction, the rows in the table will be deleted.

    33.Consider the following data set from the EMPLOYEES table and its structure:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
     EMPLOYEE_ID FIRST_NAME   JOB_ID
    ------------------- ------------------ --------
    5100 	             BRUCE
    5101 	             JESSICA           SALESMAN
    5102 	             DEBBY             SALESMAN
    

    You need to delete the data from the JOB_ID column in the row with employee_id 51001. Which of the following queries will be correct?

    1. UPDATE employees
      SET job_id  = NULL
      WHERE employee_id   = 51001;
    2. DELETE job_id  FROM employees
      WHERE employee_id   = 51001;
    3. DELETE FROM employees;
    4. None of the above

    Answer: D. You cannot delete a particular column value for a particular row with the DELETE statement. The entire row gets deleted based on the conditions given. Unwanted values in a column can be updated to NULL. Option ”A” is near but not correct in the context of the question.

    34. What is the difference between the UPSERT and MERGE statements?

    1. There is no difference
    2. UPSERT is the latest term adopted for MERGE statement, which has turned obsolete
    3. UPSERT can perform delete operation which MERGE cannot
    4. MERGE does INSERT, UPDATE and DELETE, UPSERT does only UPDATE and INSERT

    Answer: D. UPSERT is an obsolete statement and MERGE took over with new capabilities.

    35. What is the difference between the MERGE command and the commands INSERT, UPDATE and DELETE?

    1. MERGE statement consumes more time than each operation (INSERT, UPDATE, DELETE) done separately
    2. MERGE is obsolete after Oracle 10g
    3. MERGE can perform all three operations on a table while INSERT, UPDATE and DELETE perform one operation at a time.
    4. None of the above.

    Answer: C. The MERGE statement can embed all three operations on a table in a single statement while INSERT, UPDATE and DELETE perform one operation at a time.

    36. Which of the following objects can be the data source in a MERGE statement?

    1. A table only
    2. A sub-query only
    3. A table or a sub-query
    4. Both A or B

    Answer: C. MERGE works well with a table or a subquery.

    37. What among the following is a TRUNCATE statement equivalent to? (Choose the most suitable answer)

    1. To a DELETE statement
    2. To an UPDATE statement
    3. A DELETE statement without a WHERE clause
    4. None of the above

    Answer: C. TRUNCATE deletes all the rows in one command.

    38.Which of the following situations indicate that a DML operation has taken place?

    1. When new rows are added to a table
    2. When two queries are combined
    3. When a table is truncated
    4. None of the above

    Answer: A. When existing rows in a table are inserted, modified or removed from a table, it is done through a DML statement.

    39.Which of the following best defines a transaction?

    1. A transaction consists of DDL statements on the database schema
    2. A transaction consists of COMMIT or ROLLBACK in a database session
    3. A transaction consists of either a collection of DML statements or a DDL or DCL or TCL statement to form a logical unit of work in a database session
    4. A transaction consists of collection of DML and DDL statements in different sessions of the database

    Answer: C. A database transaction consists of one or more DML statements to constitute one consistent change in data, or a DDL statement or a DCL command (GRANT or REVOKE). It starts with the first DML statement and ends with a DCL or DDL or TCL (COMMIT or ROLLBACK) command. Note that DDL and DCL commands hold auto commit feature.

    40. What does a collection of DML statements that form a logical unit work known as?

    1. ACID property
    2. UNION
    3. UNION ALL
    4. Transaction

    Answer: D.

    41.What happens when a DML statement in an active transaction encounters an error on execution?

    1. The complete transactions is rolled back
    2. The DMLs in the transaction are mutually exclusive and hence can continue their execution
    3. The other DMLs in the transactions are interrupted and wait until the error is resolved
    4. None of the above

    Answer: A. If any of the DML statement in an active transaction encounters error, the whole transaction ends up in a rollback.

    42.What is true about the keyword VALUES in INSERT statements?

    1. VALUES can add multiple rows at a time during the INSERT
    2. VALUES can add only 100 rows at a time during the INSERT
    3. VALUES is mandatory to be used if we use the keyword INSERT
    4. VALUES add only one row at a time

    Answer: D. The VALUES keyword is used only when the column values are explicitly specified in the INSERT statement.

    Consider the following statement and the table structure. Answer the questions 43 to 45 that follow:

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    INSERT INTO departments (department_id , department_name , manager_id, location_id )
    VALUES (100, ''Human Resources'', 121, 1000);
    

    43. How many rows will be inserted by the above statement?

    1. 0
    2. 2
    3. 3
    4. 1

    Answer: D. When the keyword VALUES is used, it inserts only one row at a time.

    44. In which order the values will get inserted with respect to the above INSERT statement?

    1. Location_id , manager_id, department_name , department_id
    2. department_id , department_name , manager_id, location_id
    3. department_id , manager_id, department_name , location_id
    4. department_id , department_name , location_id , manager_id

    Answer: B. If the columns are mentioned in the INSERT clause, the VALUES keyword should contain values in the same order

    45. Suppose the above given statement is modified as below:

    INSERT INTO departments VALUES (100, ''Human Resources'', 121, 1000);
    

    What will be the outcome of this modification? Assume that the DEPARTMENTS table has four columns namely, department_id ,DEPARTMENT_NAME ,MANAGER_ID and LOCATION_ID .

    1. It will insert values into all the columns of the departments table assuming that column values are provided in the same sequence as the column in the table
    2. It will throw an ORA error because column names are not explicitly mentioned
    3. It will throw an ORA error because VALUES clause is wrongly used in the INSERT
    4. None of the above

    Answer: A. Including the column names in the INSERT statement is optional provided the values must comply with the count and sequence of the columns in the table.

    46. What will be the outcome of the below INSERT statement? (Consider the table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT INTO EMPLOYEES (employee_id , hire_date) VALUES (210,"21-JUN-2013");
    
    1. It will insert only the employee_id and the hire date of the employee, leaving all other columns as blanks
    2. It will insert only the employee_id
    3. It will throw an ORA error
    4. None of the above

    Answer: C. The date literal formatting contains error. It should be enclosed within single quotation marks and not double quotation marks.

    47.What will be the outcome of the below INSERT statement? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT INTO EMPLOYEES (employee_id , first_name) VALUES (210,"Bryan"); 
    1. It will insert only the employee_id and the first name of Bryan, leaving all other columns as blanks
    2. It will insert only the first name
    3. It will throw an ORA error
    4. None of the above

    Answer: C. The string literal formatting contains error. It should be enclosed within single quotation marks and not double quotation marks.

    48. Suppose you need to insert the name O”Callaghan as the last name of the employees table. Which of the following queries will give you the required results? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,''O''callahan''); 
    2. INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,''O"callahan''); 
    3. INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,''O'' ''Callahan''); 
    4. INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,"O''callahan"); 

    Answer: C.

    49. What will be the outcome of the below INSERT statement? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT INTO EMPLOYEES (employee_id , first_name) VALUES ("210",''Bryan'');
    
    1. It will throw a numeric value error
    2. It will insert only the employee_id and the first name of Bryan, leaving all other columns as NULL
    3. It will insert only the employee_id
    4. None of the above

    Answer: A. Number values should not be enclosed within quotes.

    50. What will be the outcome of the below INSERT statement? (Consider the given table structure)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT INTO departments VALUES (200,''Accounts'', NULL, NULL);
    
    1. It will throw an ORA error
    2. It will execute successfully but with wrong values might get inserted in the columns
    3. It will execute successfully
    4. None of the above

    Answer: C. NULLs can be used in the VALUES clause to fill up the column values alternatively.

    51. What will be the outcome of the below INSERT statement? (Assume there is a NOT NULL constraint on the department_id column and consider the table structure given)

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    INSERT INTO departments VALUES (NULL, ''Accounts'', NULL);
    
    1. It will throw an ORA error
    2. It will execute successfully but with wrong results
    3. It will execute successfully but with correct results
    4. None of the above

    Answer: A. NULL values cannot be inserted into non null columns.

    52. What will be the outcome of the below INSERT statement? (Assume there is a NOT NULL constraint on the department_id column and consider the given table structure)

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    INSERT INTO departments VALUES (200, 34, NULL);
    
    1. It will execute successfully but with wrong results
    2. It will throw an ORA error
    3. It will execute successfully but with correct results
    4. None of the above

    Answer: B. Data type of the value mismatches with the data type of the column in the table.

    53. Which of the following commands is used to save the changed data in a table permanently?

    1. ROLLBACK
    2. COMMIT
    3. INSERT
    4. UPDATE

    Answer: B. The TCL command COMMIT is used to end the current active transaction in a session by making all the pending data changes permanent in the tables.

    54. Which of the following commands allows undoing the changed data?

    1. ROLLBACK
    2. COMMIT
    3. INSERT
    4. UPDATE

    Answer: A. The TCL command ROLLBACK is used to end the current active transaction in a session by discarding all the pending data changes.

    55. Which of the following commands allows enabling markers in an active transaction?

    1. ROLLBACK
    2. COMMIT
    3. SAVEPOINT
    4. None of the above

    Answer: C. SAVEPOINT marks a point in a transaction which divides the transaction into smaller sections.

    56. Which of the following commands prevents other users from making changes to a table?

    1. ROLLBACK
    2. COMMIT
    3. LOCK TABLE
    4. SAVEPOINT

    Answer: C.

    57. What is true about an INSERT statement which tries to insert values into a virtual column? (Choose the most appropriate answer)

    1. It cannot insert values in the Virtual column
    2. It can insert values
    3. It throws an ORA error
    4. All of the above

    Answer: A. A Virtual column is a column which is always auto generated based on the derivation expression defined in the column specification. Its value cannot be explicitly inserted by the user.

    58.Which of the following commands allows the user to insert multiple rows with a single statement?

    1. INSERT
    2. INSERT ALL
    3. UNION ALL
    4. None of the above

    Answer: B. Bulk insert operations can be carried out using INSERT ALL.

    59. Which of the following is the syntax for inserting rows through a sub-query?

    1. INSERT INTO tablename [{column_name,..}]
      subquery; 
    2. INSERT INTO tablename  VALUES [{column_name,..}]
      subquery; 
    3. Both A and B
    4. None of the above

    Answer: A.

    Consider the following exhibit of the EMPLOYEES table and answer the questions 60 to 63 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    60. Which of the following queries will execute successfully?

    1. UPDATE employees
      SET salary = salary + 1000
      WHERE to_char (hire_date, ''YYYY'') > ''2006 
    2. UPDATE employees
      SET salary = salary + 1000
      WHERE to_date (hire_date, ''YYYY'') > ''2006 
    3. UPDATE employees
      SET salary = salary + 1000
      WHERE hire_date > to_date (substr (''01-jan-200'',8)); 
    4. UPDATE employees
      SET salary = salary + 1000
      WHERE hire_date in (to_date (''JUN 01 11'', to_date (''JUL 01  11'')); 

    Answer: A.

    61.Due to structural reorganization in the organization, you are asked to update department IDs for all the employees to NULL before the final decision is made public. Only those records should be updated which have the JOB_ID as NULL. Which of the following queries will work?

    1. UPDATE employees
      SET department_id  = NULL
      Where job_id  = NULL; 
    2. UPDATE employees
      SET department_id  = NULL
      Where job_id  = TO_NUMBER(NULL); 
    3. UPDATE employees
      SET department_id  = NULL
      Where job_id  IS NULL; 
    4. UPDATE employees
      SET department_id  = TO_NUMBER ('' '', 9999)
      Where job_id  = TO_NUMBER(NULL); 

    Answer: C. Use IS NULL operator to check column value for nullity.

    62.You need to add a basic employee data into EMPLOYEES table. The basic data contains the last name as ”Bond” and department ID as 300. Which of the following statements will give the correct results?

    1. INSERT INTO employees (employee_id , last_name, department_id )
      (100,''Bond'',
      (select department_id  from departments where department_id  = 300));  
    2. INSERT INTO employees (employee_id , last_name, department_id )
      VALUES (100,''Bond'',
      (select department_id  from departments where department_id  = 300));
    3. INSERT INTO employees (employee_id , last_name, department_id )
      VALUES (''100'',''Bond'',300);
    4. None of the above

    Answer: B, C. Sub queries do work in INSERT statements provided they return a scalar value of data type matching or compatible to the column for which they are used.

    63. You fire the following query:

    DELETE FROM EMPLOYEES;
    

    Assuming that there are no active transactions on the EMPLOYEES table in any sessions, which of the following statements is true?

    1. It removes all the rows and structure of the table
    2. It removes all the rows which can be rolled back
    3. It removes all the rows permanently
    4. None of the above

    Answer: B. Being a DML statement, the data changes due to DELETE operation are made permanent only after COMMIT is issued in the session.

    64.Consider the structure of the COUNTRY table as shown:

    SQL> desc countries
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     COUNTRY_ID		 NOT NULL CHAR(2)
     COUNTRY_NAME			  VARCHAR2(40)
     REGION_ID			  NUMBER

    You issue the following statements in a session.

    INSERT INTO COUNTRIES (1, ''Whales'')
    /
    INSERT INTO COUNTRIES (2, ''England'')
    /
    SAVEPOINT A;
    UPDATE COUNTRIES
    SET country_id= 100 where country_id= 1
    /
    SAVEPOINT B;
    DELETE FROM COUNTRIES where country_id= 2
    /
    COMMIT
    /
    DELETE FROM COUNTRIES where country_id= 100
    /
    

    What will happen when a ROLLBACK TO SAVEPOINT command is issued for the user session?

    1. The rollback generates an error
    2. Only DELETE statements are rolled back
    3. No SQL statement is rolled back
    4. None of the above

    Answer: A, C. Since there are two savepoints – A and B, and the ROLLBACK command does specifies the actual savepoint mark, Oracle throws error.

    65.If a user issues a DML command and exits the SQL Developer abruptly without a COMMIT or ROLLBACK, what will be the outcome? (Assume the session is not auto commit)

    1. Automatic COMMIT
    2. Automatic ROLLBACK
    3. Might be a COMMIT or a ROLLBACK to end the transaction
    4. None of the above

    Answer: B. When transaction is interrupted by a system failure, the entire transaction is automatically rolled back.

    66. Which of the following commands / statements would end a transaction?

    1. COMMIT
    2. SELECT
    3. SAVEPOINT
    4. CREATE

    Answer: A, D. Apart from TCL commands i.e. COMMIT or ROLLBACK, the DDL commands and DCL commands possess auto commit feature. The active transaction will be committed if the DDL statement is executed in the same session.

    67.When does a transaction complete?

    1. When a ROLLBACK is executed
    2. When a COMMIT is executed
    3. When TRUNCATE is executed
    4. All of the above

    Answer: D. Transaction completes if a TCL, DCL or a DDL command is executed in the session.

    68. Examine the given table structures and consider the following query:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    INSERT INTO EMPLOYEES (department_id ) VALUES
    (select department_id  FROM departments);
    

    What will be the outcome of the above query?

    1. The columns in the EMPLOYEES table and the departments table do not match
    2. The WHERE clause is mandatory to be used in a sub-query
    3. The VALUES keyword cannot be used with the INSERT clause when sub-queries are used
    4. None of the above

    Answer: C. Wrong usage of VALUES keyword. It must be used only when you have column data in hand, which has to be inserted in the table.

    69.Examine the given table structure and consider the following query:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    UPDATE (select employee_id , job_id  from employees)
    SET hire_date = ''01-JAN-13''
    WHERE employee_id  = (select employee_id  FROM job_history);
    

    Which of the following is true regarding the given query?

    1. It would not execute as we cannot use two tables in a single update statement
    2. It would not execute as UPDATE cannot use a sub-query
    3. It would execute with the restrictions on the column specified
    4. It would not execute as sub-query is used in the WHERE clause

    Answer: C.

    70.What happens when a transaction is committed?

    1. The changes made during the transaction are saved for a particular user session
    2. The changes made during the transaction are discarded
    3. If the transaction is a DDL, the commit doesn”t work
    4. None of the above

    Answer: D. Committing a transaction saves the pending data changes permanently into the database.

    71. Which of the following reasons will the best one on the usage of string?

    1. Using sub-queries
    2. Syntax errors
    3. Access permissions
    4. Constraint violations

    Answer: C, B, D. References to non-existing objects / columns, Space issues might be other reasons.

    72. What happens when an INSERT statement tries to insert records in an old table?

    1. All the columns will get NULL values
    2. A new table with the same name would get created automatically and the values would get inserted
    3. INSERT cannot work and it throws an ORA error
    4. None of the above

    Answer: C.

    73. A user named ”Jonathan Adams” is able to SELECT columns from the EMPLOYEES table but he is unable to insert records into EMPLOYEES. What can be the reason?

    1. Jonathan is connected to a database which does not support INSERT statements
    2. The INSERT statement cannot be applied on the table EMPLOYEES
    3. Jonathan has access to SELECT but no access to INSERT INTO the table EMPLOYEES
    4. None of the above

    Answer: C. Users can enjoy table access based on their responsibilities. One can have only read access on a table while other can enjoy read and write access.

    74. Suppose 1 million rows are to be inserted into the AUDIT table. An INSERT transaction runs successfully for the first 1000 rows and an ORA error is thrown ”Constraint violated”. What will happen to the values inserted in the first 1000 rows?

    1. They will remain as it is
    2. They all will get deleted
    3. They all will get rolled back
    4. None of the above

    Answer: C. If any of the DML statement during the transaction encounters error(s), the complete transaction will be rolled back.

    Examine the table structure and consider the following query and answer the questions 75, 76 and 77 that follow:

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    INSERT INTO departments values (15, NULL);
    

    75. What will be the outcome of this statement?

    1. It will insert a row with department_id = 15 and all the other values as NULL
    2. It will execute successfully but insert 0 rows in the table
    3. It will throw an ORA error as the no. of columns and values do not match
    4. None of the above

    Answer: C. The DEPARTMENTS table contains four columns but the INSERT statement supplies value for two columns only without mentioning the columns too. Hence, the ORA error is thrown.

    76. What is true about the above INSERT statement?

    1. If the columns are not mentioned in the INSERT statement, the values are inserted positionally in the columns
    2. It is mandatory to mention columns after the INSERT statement
    3. Both A and B
    4. None of the above

    Answer: A. If the columns are not specified in the INSERT statement, Oracle sequentially and positionally maps each value to the column in the table.

    77. With respect to the statement given above, what will happen if the table is altered to add a new column?

    1. The statement will still work
    2. The statement execution will throw an error as there will be a mismatch in the no. of columns and values
    3. There will be no change and the statement will execute as before
    4. None of the above

    Answer: B. Since the columns were not specified earlier, the problem will still exist. Mismatch in the column-value mapping would throw an ORA error.

    Examine the table structure given below and consider the following queries and answer the questions 78 and 79 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    Query 1:
    INSERT INTO employees (employee_id , last_name, hire_date)
    VALUES (100, ''ADAMS'',''21-DEC-12'');
    
    Query 2:
    INSERT INTO employees (employee_id , last_name, hire_date)
    VALUES (100, upper(''ADAMS''),to_date(''21-DEC-12'',''DD-MON-YY''));
    

    78. Which of the above two queries is better?

    1. Both are better
    2. Only Query 1 is better
    3. Only Query 2 is better
    4. None of the queries is correct

    Answer: C. Query-2 is better because it inserts date value as a date and not as a string. Though Oracle will perform implicit conversion of string literal specified as a date, but not recommended.

    79. Which of the following queries is equivalent of the query 2 given above?

    1. INSERT INTO employees (employee_id , last_name, hire_date)
      VALUES (101-1, upper(''ADAMS''),to_date(''21-DEC-12'',''DD-MON-YY''));
      
    2. INSERT INTO employees (employee_id , last_name, hire_date)
      VALUES (99+1, upper(''ADAMS''),to_date(''22-DEC-12'',''DD-MON-YY'') +1 );
      
    3. INSERT INTO employees (employee_id , last_name, hire_date)
      VALUES (100, upper(''ADAMS''),to_date(''21-DEC-12'',''DD-MON-YY'') - 1);
      
    4. INSERT INTO employees (employee_id , last_name, hire_date)
      VALUES (100, upper(''ADAMS''),to_date(''28-DEC-12'',''DD-MON-YY'')-7 );
      

    Answer: A, C, D. Arithmetic operations /functions can be used to insert values as shown above.

    80. You need to copy the data from one table to another table. Which of the following methods can be used?

    1. You can use the COPY command
    2. You can use the INSERT command
    3. You can use the UPDATE command
    4. None of the above

    Answer: B. The direct path operations INSERT-AS-SELECT (IAS) is the most commonly used method to copy data from one table to another.

    81.Which of the following statements will copy data from the JOB_HISTORY table to the JOB_HISTORY_ARCHIVE table? (Consider the table structure as given)

    SQL> desc job_history
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     START_DATE		 NOT NULL DATE
     END_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     DEPARTMENT_ID			  NUMBER(4)
    1. INSERT INTO job_history values (select * from job_history);
    2. INSERT INTO JOB_HISTORY_ARCHIVE values (select * from job_history_archive);
    3. INSERT INTO JOB_HISTORY_ARCHIVE select * from job_history;
    4. None of the above

    Answer: C. The option ”C” correctly shows the usage of IAS (INSERT-AS-SELECT) method.

    Examine the given table structure. Consider the following query and answer the questions 82 and 83 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT ALL
    WHEN job_id   = ''SA_REP'' then
    INTO employees (employee_id , department_id , salary, hire_date)
    VALUES (employee_id , 10, salary, hire_date)
    WHEN job_id  <> ''SA_REP'' then
    INTO employees (employee_id , department_id  , salary, hire_date)
    VALUES (employee_id , 20, salary, hire_date)
    SELECT employee_id , department_id , job_id, salary, commission_pct , hire_date
    FROM employees
    WHERE hire_date > sysdate - 30;
    

    82. Interpret the output of the above INSERT statement.

    1. Thrown an error
    2. It will insert the records for all the employees who were hired a month before the sysdate.
    3. It will insert the records for all the employees who are Sales Representatives in department 10
    4. None of the above

    Answer: B, C. INSERT ALL can make conditional inserts into the target tables.

    83. Which employees” data will be inserted in the department 20?

    1. Sales Representatives
    2. Accountants
    3. Both A or B
    4. None of the above

    Answer: B. As per the INSERT ALL statement, the details of employees whose job_id is not ”Sales Representative”.

    84. What will be the outcome of the below query? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    INSERT INTO employees (employee_id , salary) VALUES (&employee_id , &salary);
    COMMIT;
    
    1. Syntax error as substitution variables cannot be used in DML statements
    2. The user will be prompted for entering the employee ID and the salary but substitution variables cannot insert data in the table
    3. The user will be prompted for entering the employee ID and the salary and record will be successfully created in the EMPLOYEES table
    4. None of the above

    Answer: C. Substitution variables work well with the DML statements.

    85. Evaluate the following SQL statements that are executed in a user session in the specified order:

    CREATE SEQUENCE id_seq;
    SELECT id_seq.nextval
    FROM dual;
    
    INSERT INTO employees (employee_id ,first_name,job_id )
    VALUES (ord_seq.CURRVAL, ''Steyn'',''Trainee'');
    
    UPDATE employees
    SET employee_id = id_seq.NEXTVAL
    WHERE first_name = ''Steyn''
    AND job_id =''Trainee
    

    What would be the outcome of the above statements?

    1. The CREATE SEQUENCE command would throw error because the minimum and maximum value for the sequence have not been specified
    2. All the statements would execute successfully and the employee_id column would contain the value 2 for the employee STEYN.
    3. The CREATE SEQUENCE command would not execute because the starting value of the sequence and the increment value have not been specified.
    4. All the statements would execute successfully and the employee_id column would have the value 20 for the employee STEYN because the default CACHE value is 20.

    Answer: B.

    86. What is the restriction on the sub-query used in the UPDATE statement?

    1. The sub-query should be a multi row sub-query
    2. The sub-query should be a single row sub-query
    3. There”s no restriction
    4. The sub-query can be either a single row or a multi row sub-query

    Answer: B. The sub-query should not return multiple rows when being used in an UPDATE statement

    Examine the given table structure and consider the query given below and answer the questions 87 and 88 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    UPDATE employees
    SET salary = (SELECT salary FROM employees WHERE employee_id =7382);
    

    87. What will be the outcome of the above query?

    1. It throws an ORA error on execution
    2. Salary of all the employees will be updated with the same salary as the employee 7382
    3. Salary of all the employees will be updated to NULL
    4. None of the above

    Answer: B. Query results can be used to update the column values in a table.

    88. Suppose if the employee 7382 doesn”t exist in the EMPLOYEES table. What will be the outcome of the query?

    1. It throws an ORA error on execution because query results cannot be updated to the columns
    2. Salary of all the employees will be updated to NULL
    3. ORA exception ”NO_DATA_FOUND” will be raised because employee 7382 doesn”t exists
    4. None of the above

    Answer: B. UPDATE statements do not raise any exception except for syntactical errors.

    Examine the given table structure and consider the query given below and answer the questions 89 and 90 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    UPDATE employees
    set salary = (select salary from employees where last_name = ''Adams'');
    

    89. What will be the outcome of the query?

    1. It executes successfully
    2. All the rows of the table have the same salary
    3. It might throw an ORA error ”TOO_MANY_ROWS” upon execution
    4. None of the above

    Answer: C. The sub-query might return more than one row causing an error.

    90. What changes in the above query will make sure there are no errors caused?

    1. Use a single row function like MAX, MIN or AVG to reduce multi row results into a scalar result
    2. Adding a Primary key constraint on SALARY column
    3. No change required
    4. None of the above

    Answer: A.

    Examine the given table structure and consider the following query and answer the questions 91 and 92 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    UPDATE employees
    SET salary = (select max (salary) from employees where last_name = ''Adams'');
    

    91. What will be the outcome of the query given above?

    1. It will update the salaries of all the employees equal to the salary of the employee named Adam
    2. It will update the salaries of all the employees equal to the average salary of all with last name as ”Adam”
    3. It will update 0 rows
    4. It will update only one row

    Answer: B. Arithmetic functions MAX or a MIN can be used with sub-queries to get scalar values and avoid errors.

    92. Assume that the sub-query above is replaced with the following:

     SELECT distinct salary from employees where last_name = ''Adam 

    What will be the outcome of the main query given above?

    1. It will execute successfully giving incorrect results
    2. It will execute successfully giving correct results
    3. It will throw an ORA error
    4. None of the above

    Answer: C. it gives an error because as there are many with the last name as ”Adam” there will many distinct salaries.

    Examine the given table structure and consider the following query and answer the questions 93 and 94 that follow:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    UPDATE employees
    SET salary = 50000;
    WHERE job_id  in (select job_id  from job_history where department_id  = 10);
    

    93. What will the above statement do? (Choose the most appropriate answer)

    1. It will update all the salaries for all the employees as 50000
    2. It will update all the salaries for all the employees who are in department 10
    3. It will update the salaries for all the employees who have one of the job IDs similar to those in department 10
    4. None of the above

    Answer: C.

    94. What will happen if the WHERE clause given above is replaced with the following?

     WHERE job_id = (select job_id from job_history where department_id  = 10);
    1. It will execute successfully with incorrect results
    2. It will execute successfully with correct results
    3. It will throw an ORA error
    4. None of the above

    Answer: C. The equal sign will raise the error.

    Examine the given table structure and consider the following statement. Answer the questions 95 to 97 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    DELETE FROM employees where last_name = ''A%
    COMMIT;
    

    95. What will be the outcome of the query given above?

    1. Executes successfully but no rows are deleted
    2. All the employees whose last_name starts with “A” will be deleted
    3. ORA error because DELETE statement cannot have WHERE predicate
    4. All the rows from the employees table will get deleted

    Answer: A. DELETE statement can have WHERE clause predicate. Based on conditions, the records will be removed from the table.

    96. Consider the following statement:

    DELETE FROM employees where employee_id  IS NULL and job_id = NULL;
    COMMIT;
    

    Assuming there is a NOT NULL constraint on the column employee_id , what will be the outcome of the above query?

    1. It will raise ORA error because of invalid WHERE predicates
    2. It will execute successfully and no rows will be deleted
    3. It will raise ORA error because multiple predicates cannot work in DELETE statements
    4. None of the above

    Answer: B. Multiple predicates can be applied to the DML statements UPDATE and DELETE.

    97. Consider the following query:

    DELETE FROM employees where department_id  = &deptID;
    COMMIT;
    

    What will happen when the above statement is executed?

    1. It will raise error because DML statements cannot use substitution variables
    2. It will prompt for the department ID to be deleted from the user and delete the record with the given department ID
    3. It will prompt for the department ID but transaction cannot be committed
    4. None of the above

    Answer: B. Substitution variables can be used with DML statements.

    98. All parts of a transaction should complete or none of them. Which property of ACID rule complies with the given statement?

    1. Atomicity
    2. Consistency
    3. Isolation
    4. Durability

    Answer: A. ACID refers to the basic properties of a database transaction: Atomicity, Consistency, Isolation, and Durability. Atomicity implies that entire sequence of actions must be either completed or aborted. Consistency implies that the transaction takes the resources from one consistent state to another. Isolation implies that a transaction”s effect is not visible to other transactions until the transaction is committed. Durability implies that the changes made by the committed transaction are permanent and must survive system failure.

    99. What does the principle of Durability in the ACID property state?

    1. It states that a database can lose completed transactions
    2. It states that a transaction cannot get completed
    3. It states that once a transaction completes, it must be impossible for the DB to lose it.
    4. None of the above

    Answer: C.

    100. An incomplete transaction should be invisible to all the other users. Which of the properties of the ACID state this?

    1. Isolation
    2. Consistency
    3. Atomicity
    4. Durability

    Answer: A. “I” stands for Isolation.

    101. What does the principle of consistency states?

    1. It states that the results of a query must be consistent with the state of the DB at the time the query started
    2. It states that an incomplete transaction should be invisible to all the other users
    3. It states that once a transaction completes, it must be impossible for the DB to lose it
    4. None of the above

    Answer: A. the “C” in ACID property stands for Consistency

    102. What among the following best describes a Transaction?

    1. INSERT to COMMIT/ROLLBACK
    2. UPDATE to COMMIT/ROLLBACK
    3. DELETE to COMMIT/ROLLBACK
    4. INSERT/UPDATE/DELETE to COMMIT/ROLLBACK

    Answer: D.

    103. A user named “Jonathan” inserts data in the table EMPLOYEES. When will the other users be able to see the new data?

    1. When Jonathan provides access permission to the users
    2. When Jonathan executes a ROLLBACK statement in the session
    3. When Jonathan executes a COMMIT statement in the same session
    4. When Jonathan opens a new session and issues a COMMIT

    Answer: C. The active transaction must be committed in the same session.

    104. What can be said about the nesting of transactions?

    1. Maximum 2 levels of nesting are possible
    2. Maximum 255 levels of nesting are possible
    3. Nesting of a transaction is impossible
    4. Only 1 level of nesting is possible

    Answer: C.

    105. Which of the following reasons will terminate a transaction?

    1. A DDL statement
    2. Exiting a client
    3. System crashes
    4. All of the above

    Answer: D. DDL is auto commit and will end the ongoing active transaction.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Using DDL Statements nhận dự án làm có lương

    SQL – Using DDL Statements Questions



    1.What is the full form of DDL in Oracle DB?

    1. Data Deleting Language
    2. Data Definition Language
    3. Data Delegating Language
    4. Dummy Data Language

    Answer: B. DDL is one of the categories of SQL which stands for Data Definition Language. Other SQL types are DML, DCL, and TCL.

    2.DDL statements are used for which of the following Oracle database objects?

    1. Tables
    2. Sub-queries
    3. Rows
    4. Columns

    Answer: A. DDL contains commands like CREATE, ALTER and ANALYZE which are used to CREATE TABLEs, view stored subprograms and packages in a database schema.

    3.What is the basic unit of storage in Oracle Database that contains data?

    1. View
    2. Column
    3. Query
    4. Table

    Answer: D. Table is the basic unit of physical storage of data in Oracle database.

    4.Which of the below options best define a View?

    1. It is the shorter form of a table
    2. It is the logical representation of the subsets from one or more tables
    3. It has only one row and one column
    4. None of the above

    Answer: B. View is a query which behaves like a window to format the data contained in one or more tables. Views do not contain any physical data but just a query which are created during runtime.

    5. Which of the following are database objects?

    1. Table
    2. Sequence
    3. Synonym
    4. All of the above

    Answer: D. Objects which are physically stored in database schema are database objects.

    6. Which of the following database objects generate numeric values?

    1. Table
    2. View
    3. Index
    4. Sequence

    Answer: D. Sequence are used to generate unique values starting with a definite value and incremented by a specified factor. A sequence can be created to generate a series of integers. The values generated by a sequence can be stored in any table. A sequence is created with the CREATE SEQUENCE command.

    7.Which of the following database objects gives an alternative name to an object?

    1. Synonym
    2. Sequence
    3. View
    4. Index

    Answer: A. A synonym provides a permanent alias for a database object. A public synonym is available to any database user. A private synonym is available only to the user who created it. A synonym is created by using the CREATE SYNONYM command. A synonym is deleted by using the DROP SYNONYM command. Only a user with DBA privileges can drop a public synonym.

    8.Which of the following database objects improves the performance of some queries?

    1. Table
    2. Synonym
    3. View
    4. Index

    Answer: D.

    9. When a table can be created?

    1. When the database is not being used by any user
    2. When the database is newly created
    3. It can be created any time, even when a user is using the database
    4. None of the above

    Answer: C. An index can be created to speed up the query process. DML operations are always slower when indexes exist. Oracle 11g creates an index for PRIMARY KEY and UNIQUE constraints automatically. An explicit index is created with the CREATE INDEX command. An index can be used by Oracle 11g automatically if a query criterion or sort operation is based on a column or an expression used to create the index.

    10. What is true about a table?

    1. It is not mandatory to specify the size of a table
    2. The size of each table is the same
    3. A table can be modified online
    4. None of the above

    Answer: A, C.

    11. A table named 123_A is created for storing the number of employees in an organization. What is wrong in the name of the table?

    1. The name of a table cannot start with a digit
    2. Nothing is wrong in this name.
    3. You cannot use an underscore while naming a table
    4. None of the above

    Answer: A. As per the object naming conventions, table name must start with an alphabet.

    12. What is the range of number of letters a table name can have?

    1. 1-20 characters
    2. 1-10 characters
    3. 1-30 characters
    4. 1-50 characters

    Answer: C. A table name cannot exceed more than 30 characters.

    13 Which of the following characters can be used to name a table?

    1. A to Z
    2. a to z
    3. 0 to 9
    4. All of the above

    Answer: D. As per the standard naming convention in Oracle, object”s name can contain alphabets in any case. Mandatorily, first place is for letters while the rest can be mix of letters and digits.

    14. Which of the following special characters can be used to name a table?

    1. @
    2. #
    3. $
    4. _ (underscore)

    Answer: B, C, D. No other special character, except (#, $, _), are allowed while naming a table. Use of special characters in the table name is discouraged.

    15. What is true about the name of a table?

    1. A table can have a name which is used by some other object owned by the same user
    2. A sequence and a table can have same names
    3. A view and a table can have the same name
    4. A table name must not duplicate the name of another object owned by the same user

    Answer: D. By virtue of namespace, a table name cannot be same as any other schema objects. Schema objects which share the same namespace include tables, views, sequences, private synonyms, stored procedures, stored functions, packages, materialized views, and user-defined types.

    16.You create a table and name it as COUNT. What will be the outcome of CREATE TABLE script?

    1. The table will not be created
    2. The table will be created and an underscore will be added automatically to the name COUNT_
    3. An ORA error will be thrown
    4. The table COUNT will be created without any errors

    Answer: A, C. You cannot create a table with the name same as an Oracle Server reserved word.

    17. You create a table using quoted identifiers ” ”. How will you refer this table?

    1. ”table_name”
    2. “table_name”
    3. Either of A or B
    4. None of the above

    Answer: B. If the table is created with the name having a quoted identifier, it must be addressed using double quotes. Using quoted identifiers is not recommended. Quoted identifiers are case-sensitive

    18. You create a table named EMPLOYEES. What among the following is possible?

    1. It can be referred to as eMPLOYEES
    2. It can be referred to as EMPLoyees
    3. It can be referred to as employees
    4. All of the above

    Answer: D. Unquoted objects names are not case-senstive in Oracle.

    19. What among the following are the pre-requisites for creating a table?

    1. CREATE TABLE privilege
    2. Storage space
    3. Data in the table
    4. None of the above

    Answer: A, B. A user must possess the CREATE TABLE privilege and must have sufficient space to allocate the initial extent to the table segment.

    20. What is the syntax for creating a table?

    1. CREATE TABLE [schema.] table (column datatype [DEFAULT expr] [,..] );
    2. CREATE TABLE INTO [schema.] table (column datatype [DEFAULT expr] [,..] );
    3. CREATE TABLE VALUES [schema.] table (column datatype [DEFAULT expr] [,..] );
    4. None of the above

    Answer: A.

    21. Pick the element which you must specify while creating a table.

    1. Column name
    2. Column Data type
    3. Column size
    4. All of the above

    Answer: D. A table must have atleasr one column, its data type specification, and precision (if required).

    22. A user named “Kevin” wants to access a table which is owned by another user named “Jonathan”. Which of the following will work for Kevin?

    1. Select * from Kevin.employees;
    2. Select * from jonathan.employees;
    3. Either of A or B
    4. None of the above

    Answer: B.

    23. What is true about a schema?

    1. A schema is owned by a database user and has the same name as that user
    2. Each user owns a single schema
    3. Schema objects include database links
    4. All of the above

    Answer: D. The user space in a database is known as schema. A schema contains the objects which are owned or accessed by the user. Each user can have single schema of its own.

    24. What among the following is true about tables?

    1. A default value is given to a table
    2. A default value can be given to a column of a table during an INSERT statement
    3. Either of A or B
    4. None of the above

    Answer: B. A default value can be specified for a column during the definition using the keyword DEFAULT.

    25. Which of the following can be used with the DEFAULT option while creating a table?

    1. Strings
    2. Expressions
    3. SQL functions
    4. All of the above

    Answer: D. The default value for a column can either be a literal or a derivative using SQL function.

    26. Which of the following command is used to see the structure of a table?

    1. UPDATE
    2. SHOW
    3. DESCRIBE
    4. SPOOL

    Answer: C. DESCRIBE is a SQL*Plus command to list the structure of the table.

    27.What is the limit of CHECK constraints on a column?

    1. No limit
    2. 1
    3. 2
    4. 4

    Answer: A. Oracle imposes no limit on the check constraints on a column.

    28. Which of the following commands will drop table employees? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. DROP employees
    2. DROP TABLE employees
    3. TRUNCATE employees
    4. None of the above

    Answer: B.

    29. What is true about a namespace?

    1. It is a group of object types
    2. Within a namespace, all the object names should be uniquely identified by schema and name
    3. The same type of objects in different namespaces can share the same name
    4. All of the above

    Answer: D. A namespace defines a group of object types,within which all names must be uniquely identified-by schema and name.Objects in different namespaces can share the same name.

    30. Which of the following object types share the same namespace?

    1. Synonyms
    2. Table
    3. Views
    4. All of the above

    Answer: D.

    31. What among the following is true about a table and an index?

    1. An index and a table can have the same name in a schema
    2. An index and a table within a schema cannot have the same name
    3. Neither of A nor B
    4. None of the above

    Answer: A. As the index and constraints share the same namespace, a table and an index can have the same name.

    32. What is true about creating a table?

    1. While creating a table, each column should be assigned a data type
    2. Data type assignment to columns is not mandatory
    3. A data type has to be assigned to a table and not to a column
    4. None of the above

    Answer: A. Each column must possess behavioral attributes like data types and precision in order to build the structure of the table.

    33. Suppose you create a table as shown below:

    CREATE TABLE employees
    (emp_id NUMBER(4),
    last_name VARCHAR2 (20)
    );
    

    How much space will Oracle allocate to the LAST_NAME column?

    1. If there are no rows, then Oracle will not allocate any space to the last_name column
    2. If rows are populated then Oracle will allocate unlimited space to the last_name column
    3. Neither of A nor B
    4. None of the above options

    Answer: A.

    34. What is the range of size that a VARCHAR2 data type can take?

    1. 1 byte to 2 byte
    2. 1 byte to 2000 bytes
    3. 1 byte to 4000 bytes
    4. None of the above

    Answer: C. Until Oracle 11g Release 2, string data type VARCHAR2 can maximum contain 4000 bytes.

    35.What is the range of size that a CHAR data type can take?

    1. 1 byte to 2 byte
    2. 1 byte to 2000 bytes
    3. 1 byte to 4000 bytes
    4. 1 byte to 3000 bytes

    Answer: B. Until Oracle 11g Release 2, string data type CHAR can maximum contain 2000 bytes.

    36. What is true about the CHAR data type?

    1. If the data is not the length of the column, then it will be replaced with NULL values
    2. If the data is not the length of the column, then it will be padded with spaces
    3. It is mandatory to have the data of the same size as mentioned in the CHAR size, else it throws an ORA error
    4. None of the above

    Answer: B. CHAR provides a fixed length storage to a value while VARCHAR2 is flexible. If the data of length less than CHAR precision is inserted in a CHAR column, the remaining length will be padded to the column value.

    37. Which of the following is a data type for variable length binary data?

    1. VARCHAR
    2. VARCHAR2
    3. RAW
    4. NVARCHAR2

    Answer: C.

    38. What is the precision allowed for the NUMBER data type?

    1. 1 to 20
    2. 1 to 4K
    3. 1 to 30
    4. 1 to 38 digits

    Answer: D. Until Oracle 11g Release 2, primary data type NUMBER had the maximum precision of 38 digits.

    39. What is the scale allowed for the NUMBER data type?

    1. 1 to 20
    2. -84 to 100
    3. -84 to 127
    4. None of the above

    Answer: C.

    40. Which of the following are the data types for date and time data?

    1. TIMESTAMP
    2. INTERVAL DAY TO SECOND
    3. TIMESTAMP WITH LOCAL TIMEZONE
    4. All of the above

    Answer: D.

    41. Which of the following data types are for large objects?

    1. CLOB
    2. BLOB
    3. RAW
    4. All of the above

    Answer: A, B. LOB data types in SQL are BLOB, CLOB, and BFILE.

    42. What will happen if the inserted value is of a smaller length as defined for a VARCHAR2 data type column?

    1. It will throw an ORA error
    2. It will get inserted successfully and the value will take up as much space as it needs.
    3. It will get inserted and the remaining space will be padded with spaces
    4. None of the above

    Answer: B. VARCHAR2 contains variable length character data.

    43. What does NUMBER (8, 2) in oracle mean?

    1. It means there are 8 digits in total, 6 digits before the decimal and 2 after the decimal
    2. It means there are 10 digits in total with 8 digits before the decimal and 2 after decimal
    3. It means there are 2 digits before the decimal and 8 after the decimal point
    4. None of the above

    Answer: A. The p indicates precision,the total number of digits to the left and right of the decimal position, to a maximum of 38 digits; the s, or scale, indicates the number of positions to the right of the decimal.Example: NUMBER(7, 2) can store a numeric value up to 99999.99. If precision or scale isn”t specified, the column defaults to a precision of 38 digits.

    44. Which of the following queries will create a table with no rows in it?

    1. CREATE TABLE emp AS SELECT 0 from dual;
    2. CREATE TABLE emp AS SELECT * from employees where 1=1;
    3. CREATE TABLE emp AS SELECT * from employees where 1=2;
    4. CREATE TABLE emp AS SELECT 0 from employees;

    Answer: C. The direct path operation CTAS (CREATE TABLE .. AS SELECT..) can be used to copy the structure of an existing table without copying the data.

    45. Which of the following statements would add a column to a table already created?

    1. ALTER TABLE table_name add column (job varchar2(20));
    2. ALTER TABLE table_name add job varchar2(20);
    3. ALTER TABLE table_name add (job varchar2(20));
    4. ALTER TABLE table_name add column (job);

    Answer: C. The ALTER TABLE command allows a user to add a new column to a table.The same rules for creating a column in a new table apply to adding a column to an existing table.The new column must be defined by a column name and datatype (and width, if applicable).A default value can also be assigned. The difference is that the new column is added at the end of the existing table-it will be the last column.

    46. Which of the following statements will modify the data type of an already existing column?

    1. ALTER TABLE table_name MODIFY (job varchar2(10) );
    2. ALTER TABLE table_name MODIFY job varchar2(10);
    3. ALTER TABLE table_name MODIFY column (job varchar2(10) );
    4. ALTER TABLE table_name MODIFY (job varchar2(10) );

    Answer: A. The ALTER TABLE..MODIFY is used to modify column definition in a table. The admissible changes are increasing column precision, change datatype within a datatype family, or change the default value of the column.

    47. Which of the following statements will remove a column from the table?

    1.  ALTER TABLE table_name DROP (job varchar2(10) );
    2. ALTER TABLE table table_name DROP COLUMN (job varchar2(10) );
    3. ALTER TABLE table table_name DROP COLUMN (job);
    4. ALTER TABLE table_name MODIFY (job varchar2(10) );

    Answer: C. The ALTER TABLE..DROP COLUMN can be used to drop a column from the table.

    48. Which of the following will rename the column emp_id to empno?

    1. ALTER TABLE employees RENAME column emp_id to empno;
    2. ALTER TABLE employees RENAME emp_id to empno;
    3. ALTER TABLE employees RENAME column emp_id to empno;
    4. None of the above;

    Answer: A. The ALTER TABLE..RENAME can be used to rename an existing column in teh table.

    49. You need to mark the table employees as read only. Which of the following statements will you execute to get the required result?

    1. ALTER TABLE employees set READ;
    2. ALTER TABLE employees READ ONLY;
    3. ALTER TABLE employees READ_ONLY;
    4. ALTER TABLE employees set READ ONLY;

    Answer: B. A table can be marked read only to make it passive against the DML and DDL statements. The read only feature was introduced in Oracle 11g.

    50. What among the following is true about DDL statements?

    1. DDL commands become the part of ongoing transaction
    2. DDL commands are auto commit and end the ongoing active transaction
    3. If the DDL command fails, the current transaction is still committed
    4. If the DDL command fails, the current transaction is rolled back

    Answer: B. DDL commands are auto commit only if they are successfully executed without errors. If DDL command fails, the ongoing transaction is still active in the session and not committed into the database.

    51. What happens if there is an active transaction against a table on which a DDL is issued?

    1. The transaction rolls back
    2. The transaction is committed and terminated
    3. Both A and B
    4. None of the above

    Answer: B.

    52. Which of the following commands will remove unused columns in an SQL statement?

    1. ALTER TABLE tablename DROP COLUMN column_name;
    2. ALTER TABLE tablename DROP unused columns;
    3. ALTER TABLE tablename set unused column;
    4. ALTER TABLE tablename DROP columns;

    Answer: C. The SET UNUSED command drops only the un-used columns from a table and is faster

    53. What happens when a table which is marked Read Only is attempted for drop?

    1. It will throw an error
    2. It will no longer remain Read Only but cannot be dropped either
    3. It will be dropped without errors
    4. It will remain un-touched

    Answer: C. The DROP command affects the data dictionary definition of the tables which are not Read Only and hence dropping is possible

    Consider the following statement and answer the questions 54 and 55 that follow:

    CREATE TABLE departments
    (dept_id NUMBER (2),
     dept_name VARCHAR2(14),
     create_date DATE DEFAULT SYSDATE);
    

    54. What will happen if the DEFAULT clause specification is removed from the statement?

    1. The script will throw error because DATE columns must be specified with a default value
    2. A system generated default value will be assigned to the column
    3. Table will be created with no default value for CREATE_DATE column
    4. None of the above

    Answer: C.

    55.What is true about the above statement?

    1. It will automatically commit the transaction in session
    2. It will create the table DEPARTMENTS in the schema
    3. It will set a default value for CREATE_DATE column
    4. None of the above

    Answer: A, B, C.

    56. Up to which limit can a BLOB data type column hold values?

    1. 1 KB
    2. 2 GB
    3. 4 GB
    4. 3 KB

    Answer: C. As per Oracle 11g, the maximum size of data accomodated in a BLOB can be 4GB.

    57.What is the difference between CLOB and BLOB data types? (Choose the most appropriate answer)

    1. CLOB is character data , BLOB is binary data
    2. CLOB is character data up to 2GB, BLOB is binary data up to 4 GB
    3. CLOB is character data up to 4 GB, BLOB is binary data up to 4 GB
    4. None of the above

    Answer: C. CLOB is a character large object which is used to store character files like PDF, docs and text files while BLOB is a binary LOB used to store media files.

    58.What among the following is a ROWID?

    1. It is a serial number given to a set of rows starting with 1
    2. It is an alphanumeric address given to a row in a table
    3. Both A and B
    4. None of the above

    Answer: B. It is a base-64 system representing the unique address of a row in its table.

    59.What is the data type used for storing Binary data stored in an external file (up to 4 GB)?

    1. BLOB
    2. CLOB
    3. CFILE
    4. BFILE

    Answer: D. BFILE is an external LOB type which is used to refer external media files. Internal LOB types are BLOB and CLOB which are used for binary large files and character large files stored in the database.

    60. What is true about a table created with a sub-query?

    1. A VARCHAR2 data type column is not copied when a table is created using a sub-query
    2. A CLOB data type column is not copied when a table is created using a sub-query
    3. A LONG column is not copied when a table is created using a sub-query
    4. None of the above

    Answer: C. The CTAS method to create a table doesn”t copies the LONG column.

    61. Which of the following data types cannot be used with a GROUP BY and an ORDER BY clause?

    1. CLOB
    2. VARCHAR2
    3. CHAR
    4. LONG

    Answer: D. LONG data types cannot be used in GROUP BY and ORDER BY clause.

    62. How many LONG columns can a table contain?

    1. None
    2. Maximum 2
    3. Minimum 2
    4. Only one

    Answer: D. A table can contain maximum one column of LONG type.

    63.Which of the following data types cannot be constrained in SQL?

    1. VARCHAR2
    2. LONG
    3. CHAR
    4. DATE

    Answer: B. Constraints cannot be created on LONG type columns.

    64. Which of the following data types can you use if you want a date with fractional seconds?

    1. DATE
    2. VARCHAR2
    3. TIMESTAMP
    4. None of the above

    Answer: C. The TIMESTAMP data type provides additional precised information of date values. It provides fractional seconds and time zone information.

    65. You need to store an interval of days, hours, minutes and seconds in a column. Which of the data type would help?

    1. TIMESTAMP
    2. INTERVAL YEAR TO MONTH
    3. INTERVAL DAY TO SECOND
    4. None of the above

    Answer: C.

    66.You need to find how many employees were hired in June, 2011 and June, 2012. Which of the following data types will help?

    1. INTERVAL DAY TO SECOND
    2. TIMESTAMP
    3. DATE
    4. INTERVAL YEAR TO MONTH

    Answer: D.

    67. What is true about constraints?

    1. They enforce rules at the row level
    2. They enforce rules at the table level
    3. It is mandatory to have constraints created while creating a table
    4. None of the above

    Answer: B. A constraint is a rule applied to data being added to a table. It represents business rules, policies, or procedures.Data violating the constraint isn”t added to the table.A constraint can be included during table creation as part of the CREATE TABLE command or added to an existing table with the ALTER TABLE command. A constraint based on composite columns (more than one column) must be created by using the table-level approach.

    68. How are constraints helpful?

    1. They limit the storage capacity of a table and hence save DB space
    2. They prevent the modification of a table
    3. They prevent deletion of a table if there are dependencies
    4. None of the above

    Answer: C. A constraint is a rule applied to data being added to a table.It represents business rules, policies, or procedures.Data violating the constraint isn”t added to the table.

    69.A RAW data type column can store variable-length binary strings up to what value?

    1. 10 GB
    2. 1 TB
    3. 2 GB
    4. 4 GB

    Answer: C.

    70. Which of the following are valid constraints in Oracle?

    1. INDEX
    2. GENERAL
    3. UNIQUE
    4. PRIMARY KEY

    Answer: C, D. A NOT NULL constraint can be created only with the column-level approach. A PRIMARY KEY constraint doesn”t allow duplicate or NULL values in the designated column. Only one PRIMARY KEY constraint is allowed in a table. A FOREIGN KEY constraint requires that the column entry match a referenced column entry in the table or be NULL. A UNIQUE constraint is similar to a PRIMARY KEY constraint, except it allows storing NULL values in the specified column. A CHECK constraint ensures that data meets a given condition before it”s added to the table.

    71. Which of the below DML operations consider constraints on a column?

    1. INSERT
    2. UNION
    3. DELETE
    4. UPDATE

    Answer: A, C, D. All the DML operations obey constraints on the columns of the table.

    72. When can a constraint be created?

    1. While creating a table
    2. After creating a table
    3. Both A and B
    4. None of the above

    Answer: C. A constraint can be included during table creation as part of the CREATE TABLE command or added to an existing table with the ALTER TABLE command.

    73 Where are constraints stored?

    1. In the SGA
    2. In a table
    3. In data dictionary
    4. None of the above

    Answer: C.

    74. You create a constraint but do not name it. What will be the default name given to the constraint?

    1. SYS_Cn
    2. SYS_constraint
    3. SYS_Const
    4. SYS_C0

    Answer: A. By default, Oracle gives a generic name to the constraints SYS_Cn, where the n is an integer to keep the name of a constraint unique.

    75. What is the functional difference between a column-level constraint and a table-level constraint?

    1. Column-level constraint applies to all the columns of a table
    2. Table-level constraint applies to all the columns of a table
    3. They both are functionally the same, only the syntax is different
    4. None of the above

    Answer: C. Functionally, the table level constraints and column level constraints work similar. Composite constraints can be defined at table level only.

    76. What is true about column-level constraints?

    1. They can be created before the creation of a table
    2. They can be created before the defining of a column
    3. They are included when the column is defined
    4. None of the above

    Answer: C. Column level constraints are defined along with the column specification.

    77. What is true about NOT NULL constraints in SQL?

    1. They should be defined at the table level
    2. They should be defined at the column level
    3. They should be defined only on one column
    4. They should be defined only on one row

    Answer: B. A NOT NULL constraint can be created only with the column-level approach.

    Consider the following statement and answer the questions 78 and 79 that follow:

    CREATE TABLE employees (
    emp_id NUMBER (6)  CONSTRAINT emp_emp_id_PK PRIMARY KEY,
    first_name VARCHAR2(20),
    last_name VARCHAR2(20),
    hire_date DATE
    );
    

    78.Which type of constraint is created in the above statement?

    1. Column level constraint
    2. Table level constraint
    3. Named constraint
    4. Specification constraint

    Answer: A. A column level constraint is created along with the column definition.

    79. What modification can be made to the above statement to give it a table level constraint?

    1. CONSTRAINT emp_emp_id_PK PRIMARY KEY
    2. CONSTRAINT emp_emp_id_PK PRIMARY KEY (EMP_ID)
    3. CONSTRAINT emp_emp_id_PK EMP_ID PRIMARY KEY
    4. CONSTRAINT PRIMARY KEY emp_emp_id_PK

    Answer: B.

    80. What is true about PRIMARY KEY constraint?

    1. It applies a NOT NULL constraint implicitly to the column on which it is defined
    2. It applies a UNIQUE KEY constraint implicitly to the column on which it is defined
    3. It applies a CHECK constraint implicitly to the column on which it is defined
    4. It applies a DEFAULT constraint implicitly to the column on which it is defined

    Answer: A. A PRIMARY KEY constraint doesn”t allow duplicate or NULL values in the designated column. Only one PRIMARY KEY constraint is allowed in a table.

    81. What among the following is true regarding a UNIQUE KEY constraint?

    1. UNIQUE KEY constraint and PRIMARY KEY constraint are the same
    2. UNIQUE KEY constraint allows NULL values if there is no NOT NULL defined on the column(s)
    3. We can have two identical rows when a UNIQUE KEY constraint is defined on a column
    4. None of the above

    Answer: B. A UNIQUE constraint is similar to a PRIMARY KEY constraint, except it allows storing NULL values in the specified column.

    Consider the following statement and answer the questions 82 and 83 that follow:

    CREATE TABLE employees (
    emp_id NUMBER (6)
    first_name VARCHAR2(20),
    last_name VARCHAR2(20),
    job VARCHAR2(20),
    hire_date DATE
    CONSTRAINT emp_job_UK UNIQUE (job));
    

    82. Which of the below statements interpret the above CREATE TABLE script?

    1. This table cannot have two identical Job IDs
    2. This table can have two or more identical Job IDs
    3. This table can have NULL values in the JOB column
    4. None of the above

    Answer: A, C. A UNIQUE constraint on the JOB column will restrict duplicate value but allows nulls.

    83. If the constraint emp_job_UK is modified as emp_job_PK PRIMARY KEY (job), what will be outcome?

    1. This change can happen only if there”s no NULL value in the JOB column
    2. This change can happen without any restrictions
    3. This change will change the values of the column JOB
    4. None of the above

    Answer: A.

    84. What is true about the UNIQUE key constraint?

    1. A unique key index is implicitly created when a UNIQUE constraint is defined on a column
    2. A PRIMARY KEY constraint is implicitly created when a UNIQUE constraint is defined on a column
    3. A NOT NULL constraint is implicitly created when a UNIQUE constraint is defined on a column
    4. None of the above

    Answer: A. When a unique constraint is imposed on a table, Oracle internally creates a unique key index on the column to restrict the duplication of values.

    85. Which of the following is true about indexes?

    1. If an UPDATE statement is executed on a table, the indexes need to be manually updated as well
    2. If a DELETE statement is executed on a table, the indexes need to manually deleted as well
    3. When a table is dropped, the indexes are automatically dropped
    4. If an UPDATE statement is executed on a table, the corresponding indexes are updated as well.

    Answer: C, D.

    86.Which of the following CREATE TABLE statements is valid?

    1. CREATE TABLE EMPLOYEES
      (emp_id NUMBER (2) PRIMARY KEY,
      first_name VARCHAR(20),
      last_name VARCHAR(20),
      hire_date DATE NOT NULL); 
    2. CREATE TABLE EMPLOYEES
      (emp_id NUMBER (2) PRIMARY KEY NOT NULL,
      first_name VARCHAR(20),
      last_name VARCHAR(20),
      hire_date DATE NOT NULL PRIMARY KEY); 
    3. CREATE TABLE EMPLOYEES
      (emp_id NUMBER (2) PRIMARY KEY,
      first_name VARCHAR(20),
      last_name VARCHAR(20),
      hire_date DATE NOT NULL UNIQUE);
    4. CREATE TABLE EMPLOYEES
      (emp_id NUMBER (2),
      first_name VARCHAR(20),
      last_name VARCHAR(20),
      hire_date DATE NOT NULL,
      CONSTRAINT emp_emp_id_PK PRIMARY KEY (emp_id)); 

    Answer: A, C, D. All the CREATE TABLE scripts are valid.

    87. How many PRIMARY KEY constraints can a table have?

    1. 0
    2. Unlimited
    3. 2
    4. 1

    Answer: D. A table can have one and only one primary key.

    88. You want to put a CHECK constraint on the EMP_ID such that it should be equal to the current value of a Sequence through which it is getting its values. Which of the following statements will help you achieve this?

    1. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (emp_id = EMPNO.CURRVAL);
    2. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (emp_id = EMPNO.NEXTVAL);
    3. Emp_id NUMBER (10) CONSTRAINT emp_emp_id_chk CHECK (EMPNO.CURRVAL);
    4. None of the above

    Answer: D. You cannot use CURRVAL, NEXTVAL, LEVEL and ROWNUM pseudo columns in the CHECK constraint

    89. Which of the following commands will help in converting the foreign key values to NULL?

    1. ON DELETE CASCADE
    2. ON DELETE SET NULL
    3. CASCADE
    4. REFERENCES

    Answer: B.

    90. You need to add a constraint to the EMPLOYEES table which restricts the addition of those employees who have salaries less than 10000. Which of the following commands will give you the required results?

    1. ALTER TABLE employees ADD CONSTRAINT emp_emp_sal_CHECK CHECK (salary >= 10000); 
    2. ALTER TABLE employees ADD CHECK CONSTRAINT emp_emp_sal_CHECK (salary>10000); 
    3. ALTER TABLE employees ADD CONSTRAINT CHECK emp_emp_sal_CHECK (salary = 10000); 
    4. ALTER TABLE employees ADD CONSTRAINT emp_emp_sal_CHECK (salary < 10000); 

    Answer: A.

    91. You need to add a constraint to the EMPLOYEES table which imposes a restriction that the HIRE_DATE for all the employees should be equal to SYSDATE-7. Which of the following statements will give you the required results?

    1. ALTER TABLE employees ADD CHECK CONSTRAINT emp_emp_sal_CHECK  ( to_char(hire_date,''DD-MON-YY'') = SYSDATE -7); 
    2. ALTER TABLE employees ADD CONSTRAINT CHECK emp_emp_sal_CHECK ( to_char(hire_date,''DD-MON-YY'') = SYSDATE -7); 
    3. ALTER TABLE employees ADD emp_emp_sal_CHECK CHECK ( to_char(hire_date,''DD-MON-YY'') = SYSDATE -7); 
    4. None of the above

    Answer: D. You cannot use SYSDATE, UID, USER and USERENV functions in the CHECK constraint.

    Consider the following query and answer the questions 92 to 94 that follow:

    CREATE TABLE EMPLOYEES
    (emp_id NUMBER (2),
    first_name VARCHAR(20),
    last_name VARCHAR(20),
    dept_id NUMBER (10),
    hire_date DATE DEFAULT SYSDATE
    CONSTRAINT emp_emp_id_PK PRIMARY KEY (emp_id, hire_date)
    CONSTRAINT emp_dept_FK FOREIGN KEY (dept_id)
    REFERENCES departments (dept_id)
    );
    

    92. Which of the below statements interpret the CREATE TABLE script?

    1. A FOREIGN KEY constraint is defined at the table level on the column DEPT_ID
    2. The FOREIGN KEY constraint defined references the DEPT_ID from the DEPARTMENTS table
    3. Both A and B
    4. None of the above

    Answer: C. The keywords FOREIGN KEY and REFERENCES are used when we define a FOREIGN KEY constraint for referential integrity.

    93. You need to delete all the dependent rows in DEPARTMENTS table when you delete the EMPLOYEES table. Which of the following command will solve the purpose? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    1. ON DELETE SET NULL
    2. ON DELETE CASCADE
    3. DELETE ALL
    4. FOR UPDATE

    Answer: B. If ON DELETE CASCADE is included in the constraint definition and a record is deleted from the parent table,any corresponding records in the child table are also deleted automatically.

    94. The EMPLOYEES table as shown below, has 5 employees who work in department 10. An executive from admin department issues the below query.

    DELETE FROM departments
    WHERE dept_id = 10;
    

    What will be the outcome of this query? (Assume the table structures as shown)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    1. Integrity constraint error
    2. Successful execution
    3. Neither of A nor B
    4. None of the above

    Answer: A. The DEPT_ID from DEPARTMENTS is the foreign key in the table EMPLOYEES and there are employees in department 10 ,hence a value cannot be deleted from the parent table unless the child record is found.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL Certificate – Useful Resources nhận dự án làm có lương

    SQL Certificate – Useful Resources



    The following resources contain additional information on SQL Certificate. Please use them to get more in-depth knowledge on this topic.

    Useful Links on SQL Certificate

    • − Database Language SQL (Proposed revised text of DIS 9075) July 1992 (Second Informal Review Draft).

    • − DB2 resource for SQL users.

    • − Oracle SQL Developer is a free and fully supported graphical tool for database development.

    • − A small article on SQL, worth to go through it.

    • − Here you can download the latest MySQL release, get the MySQL news update. The mailing list is also a great resources for anyone who want to build dynamic websites using MySQL.

    • − Its a tutorial from Tutorials Point which explains you how to use MySQL along with PERL and DBI module. Here you will learn all the required MySQL operations alongwith examples.

    Useful Books on SQL Certificate

    To enlist your site on this page, please drop an email to contact@tutorialspoint.com


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL Certificate – Mock Exams nhận dự án làm có lương

    SQL Certificate Mock Exams



    1. What will be the outcome of the following query?

    SELECT ROUND(144.23,-1) FROM dual;
    1. 140
    2. 144
    3. 150
    4. 100

    2.In which of the following cases, parenthesis should be specified?

    1. When INTERSECT is used with other set operators
    2. When UNION is used with UNION ALL
    3. When MINUS is used for the queries
    4. None of the above

    3. Which of the following are DML commands in Oracle Database?

    1. SELECT
    2. GROUP BY
    3. INTERSECT
    4. INSERT

    4. Write a query to display employee details (Name, Department, Salary and Job) from EMP table.

    1. SELECT ename, deptno, sal, job FROM emp;
    2. SELECT * FROM emp;
    3. SELECT DISTINCT ename, deptno, sal, job FROM emp;
    4. SELECT ename, deptno, sal FROM emp;

    5.What among the following are different types of Views?

    1. Simple views
    2. Complex views
    3. Both A and B
    4. None of the above

    6.What is true about the SET operators?

    1. The SELECT clause should have the same number of columns, data types can be different
    2. The SET operators can be used only for combining two queries
    3. The data type of each column in the 2nd query must match the data type of its corresponding column in the first query.
    4. None of the above

    7.Which of the following multi-row operators can be used with a sub-query?

    1. IN
    2. ANY
    3. ALL
    4. All of the above

    8. When a table can be created?

    1. When the database is not being used by any user
    2. When the database is newly created
    3. It can be created any time, even when a user is using the database
    4. None of the above

    9. Which among the following is a common technique for inserting rows into a table? (Choose the most sensible and appropriate answer)

    1. Using SELECT clause
    2. Manually typing each value into the INSERT clause
    3. Using SET operators
    4. None of the above

    10. What among the following is true about a View?

    1. Sub-queries can be embedded in a CREATE VIEW statement
    2. A sub-query used in the CREATE VIEW statement has to have a simple SELECT syntax
    3. You cannot use a WHERE clause in a sub-query when it is used in the CREATE VIEW statement
    4. None of the above

    11. Predict the output when below statement is executed in SQL* Plus?

    DESC emp
    1. Raises error “SP2-0042: unknown command “desc emp” – rest of line ignored.”
    2. Lists the columns of EMP table
    3. Lists the EMP table columns, their data type and nullity
    4. Lists the columns of EMP table along with their data types

    12. What will be the outcome of the query given below?

    SELECT 100+NULL+999 FROM dual;
    1. 100
    2. 999
    3. NULL
    4. 1099

    13. With respect to the given query, if the JOIN used is replaced with NATURAL JOIN, it throws an error. What is the reason for this error?

    1. When the NATURAL JOIN is used, a WHERE clause is mandatory, omitting which gives an error
    2. The ON clause should be replaced with the USING clause
    3. The words NATURAL, JOIN and USING are mutually exclusively in the context of the same join clause
    4. A query can”t combine the NATURAL JOIN and ON (or USING) clauses while joining.

    14.Which of the following syntax models is used in extensively in the software systems worldwide?

    1. ANSI SQL: 1999
    2. Both traditional Oracle syntax and the ANSI SQL: 1999 syntax
    3. Traditional Oracle syntax
    4. All of the options

    15.What is true about co-related sub-queries?

    1. The tables used in the main query are also used in a co-related sub-query
    2. The sub-queries which reference a column used in the main query are called co-related sub-queries
    3. The sub-queries which are written without parenthesis are called co-related sub-queries
    4. The sub-queries which mandatorily use different tables than those used in the main query are called co-related sub-queries

    16. You issue an UPDATE statement as follows:

    UPDATE employees
    SET employee_id   = NULL;
    WHERE job_id  = ''CLERK
    

    What will be the outcome of the above statement? (Here the column EMPLOYEE_ID is marked as mandatory by putting a constraint)

    1. The first column of the data set will get updated to NULL
    2. The 3rd column of the first row will get updated to NULL
    3. The 3rd column of all the rows will get updated to NULL
    4. And ORA error will be thrown

    17.What is true with respect to the query given above?

    1. It gives an ORA error as the mandatory WHERE clause is not present
    2. The JOIN..ON clause can”t contain more than one condition
    3. The query ignores the last condition and executes without an ORA error
    4. The JOIN..ON clause can be written in the form given above for putting more conditions.

    18. Consider the following query.

    SELECT e.job_id , e.first_name, d.department_id
    FROM departments D JOIN employees e JOIN BONUS b
    USING (job_id );
    

    This query results in an error. What is the reason of the error?

    1. A JOINOUSING can happen only between two tables at a time
    2. USING clause in the query doesn”t have any column from the department
    3. There is no WHERE clause in the query
    4. None of the above

    19. Predict the output of the below query

    SELECT 50 || 0001
    FROM dual
    1. 500001
    2. 51
    3. 501
    4. 5001

    20. You create a table and name it as COUNT. What will be the outcome of CREATE TABLE script?

    1. The table will not be created
    2. The table will be created and an underscore will be added automatically to the name COUNT_
    3. An ORA error will be thrown
    4. The table COUNT will be created without any errors

    21. What will be the outcome of the following query?

    SELECT *
    FROM employees
    WHERE salary BETWEEN (SELECT max(salary)
    			FROM employees
    			WHERE department_id  = 100)
    AND (SELECT min(salary) FROM employees where department_id  = 100); 

    This query returns an error. What is the reason for the error?

    1. A GROUP BY clause should be used as the function MAX is used
    2. Both the sub-queries cannot use the same department ID in the same outer query
    3. BETWEEN operator cannot be used with a sub-query
    4. SELECT clause should have columns mentioned and not a asterix (*)

    22. Which of the following is not a property of functions?

    1. Perform calculations on data
    2. Convert column data types
    3. Modify individual data items
    4. None of the above

    23.What is true with respect to INNER JOINS and OUTER JOINS in Oracle DB?

    1. INNER JOIN returns only the rows that are matched
    2. OUTER JOIN returns only the rows that are not matched
    3. OUTER JOIN returns the rows that are matched as well as those which do not match
    4. None of the above

    24. Which of the following can create a view even if the base table(s) does not exist?

    1. NOFORCE
    2. FORCE
    3. OR REPLACE
    4. CREATE VIEW

    25. Which of the following ANSI SQL: 1999 join syntax joins are supported by Oracle?

    1. Cartesian products
    2. Natural joins
    3. Full OUTER join
    4. Equijoins

    26. What among the following are the pre-requisites for creating a table?

    1. CREATE TABLE privilege
    2. Storage space
    3. Data in the table
    4. None of the above

    27. What is the syntax for creating a table?

    1. CREATE TABLE [schema.] table (column datatype [DEFAULT expr] [,..] );
    2. CREATE TABLE INTO [schema.] table (column datatype [DEFAULT expr] [,..] );
    3. CREATE TABLE VALUES [schema.] table (column datatype [DEFAULT expr] [,..] );
    4. None of the above

    28.You need to display all the non-matching rows from the EMPLOYEES table and the non-matching rows from the DEPARTMENT table without giving a Cartesian product of rows between them. Which of the following queries will give the desired output?

    1. SELECT *
      FROM employees e, department d
      WHERE e.department_id  = d.department_id ;
      
    2. SELECT *
      FROM employees e NATURAL JOIN department d;
      
    3. SELECT *
      FROM employees e FULL OUTER JOIN department d
      ON  e.department_id  = d.department_id ;
      
    4. SELECT *
      FROM employees e JOIN  department d
      ON ( e.department_id  > d.department_id ) ; 

    29. Which of the below alphanumeric characters are used to signify concatenation operator in SQL?

    1. +
    2. ||
    3. ::

    30.What is the best way to change the precedence of SET operators given the fact that they have equal precedence?

    1. The order of usage of the SET operators can be changed to change the precedence
    2. The equal precedence cannot be changed
    3. Parenthesis can be used to change the precedence
    4. None of the above

    31.What will be displayed in the result of this query?

    1. It will display distinct department id(s) contained jointly in EMPLOYEES and DEPARTMENTS table
    2. It will throw ORA error
    3. No rows selected
    4. None of the above

    32. Which of the following commands ensures that no DML operations can be performed on a view?

    1. NOFORCE
    2. FORCE
    3. WITH READ ONLY
    4. OR REPLACE

    33. What is true about the NOFORCE option in CREATE VIEW statement?

    1. It creates a view even if the base table(s) does not exist.
    2. It creates a view only if the base table(s) exists.
    3. It is the default while creating a view.
    4. None of the above

    34. What is true about the OR REPLACE keyword?

    1. Object privileges are lost when a view is created using this keyword
    2. There is no need of re granting the object privileges previously granted on it
    3. Neither of A nor B
    4. None of the above

    35. What among the following is a type of Oracle SQL functions?

    1. Multiple-row functions
    2. Single column functions
    3. Single value functions
    4. Multiple columns functions

    36. What among the following is a type of single-row function?

    1. VARCHAR2
    2. Character
    3. LONG
    4. NULLIF

    37. What is the most appropriate about Multiple Row Functions?

    1. They return multiple values per each row. 
    2. They return one result per group of rows and can manipulate groups of rows. 
    3. They return one result per row and can manipulate groups of rows. 
    4. They return multiple values per a group of row.

    38. Which of the following are also called Group functions?

    1. Single row functions
    2. Multi group functions
    3. Multiple row functions
    4. Single group functions.

    39. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (*) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    40. Pick the element which you must specify while creating a table.

    1. Column name
    2. Column Data type
    3. Column size
    4. All of the above

    41. What can be said about the statement given above?

    1. Alternative names have been given for the view
    2. Giving alternative names is mandatory if any column is derived from a function or an expression
    3. Both A and B
    4. None of the above

    42. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    43. You need to find the results obtained by the above query only for the departments 100 and 101. Which of the following clauses should be added / modified to the above query?

    1. ON (e.department_id = d.department_id ) should be added
    2. USING (e.department_id ) should be added
    3. WHERE e.department_id in (100,101) should be added
    4. None of the above

    44. Which of the following is NOT a GROUP BY extensions in SQL?

    1. GROUP BY
    2. GROUPING SETS
    3. CUBE
    4. ROLLUP

    45. What will happen if the above statement is modified as below?

    CREATE OR REPLACE VIEW dept_sum_vu(name, maxsal, minsal, avgsal)
    AS
    SELECT d.dept_name, MIN(e.salary), MAX(e.salary), AVG (e.salary)
    FROM employees e JOIN departments d
    ON (e.department_id= d.dept_id)
    GROUP BY d.dept_name;
    
    1. It will be no different than the original statement
    2. It will execute successfully giving the same results but change in alias names.
    3. It will throw an ORA error
    4. None of the above

    46. What among the following is true about the DELETE statement?

    1. The DELETE statement has to be accompanied by the WHERE clause
    2. It is not mandatory to write a WHERE clause with the DELETE statement
    3. DELETE can remove data from multiple tables at a time
    4. None of the above

    47. Assuming the last names of the employees are in a proper case in the table employees, what will be the outcome of the following query?

    SELECT employee_id, last_name, department_id  FROM employees WHERE last_name = ''smith
    1. It will display the details of the employee with the last name as Smith
    2. It will give no result.
    3. It will give the details for the employee having the last name as ”Smith” in all Lower case.
    4. It will give the details for the employee having the last name as ”Smith” in all INITCAP case.

    48.What among the following happens when we issue a DELETE statement on a table? (Choose the most appropriate answer)

    1. A prompt pops up asking the user whether he/she is sure of deleting the rows requested
    2. The rows obeying the condition given in the DELETE statement are removed immediately
    3. The requested rows are removed immediately without any prompt.
    4. None of the above

    49.What is true about the query given above?

    1. This query returns an ORA error
    2. It executes successfully but gives no results
    3. Queries from different tables cannot be used with the SET operators
    4. The query executes successfully and gives the results as expected

    50.What will happen if a value is provided to the &N variable in the above query (option C in question 76) does not match with any row? (Choose the best answer)

    1. The statement would throw an ORA error
    2. The statement would return all the rows in the table
    3. The statement would return NULL as the output result.
    4. The statement would return no rows in the result.

    51.What is the default sorting order of the results when UNION ALL operator is used?

    1. Descending
    2. Ascending
    3. Either A or B
    4. All of the above

    52. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (ALL num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    53.What is the maximum level up to which Sub-queries can be nested?

    1. 255
    2. 100
    3. 2
    4. 16

    54. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (DISTINCT num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    55. Here are few statements about VARIANCE function in SQL.

    i. The function accepts multiple numeric inputs and returns variance of all the values

    ii. The function accepts a number column and returns variance of all column values including NULLs

    iii. The function accepts a number column and returns variance of all column values excluding NULLs

    Chose the correct combination from the below options.

    1. i and iii
    2. i and ii
    3. ii
    4. iii

    56. Which clause is used to filter the query output based on aggregated results using a group by function?

    1. WHERE
    2. LIMIT
    3. GROUP WHERE
    4. HAVING

    57. A user named “Kevin” wants to access a table which is owned by another user named “Jonathan”. Which of the following will work for Kevin?

    1. Select * from Kevin.employees;
    2. Select * from jonathan.employees;
    3. Either of A or B
    4. None of the above

    58.What is true about the ALL operator used for sub-queries? (Choose the most appropriate answer.)

    1. Returns rows that match all the values in a list/sub-query
    2. Returns rows that match only some values in a list/sub-query
    3. Returns rows only if all the values match in a list/sub-query
    4. All of the above

    59. Suppose you select DISTINCT departments and employee salaries in the view query used in above question. What will be the outcome if you try to remove rows from the view dept_sum_vu?

    1. The rows will get removed without any error
    2. Only the first 10 rows will get removed
    3. The rows cannot be deleted.
    4. None of the above

    60.What will happen if the SELECT list of the compound queries returns both a VARCHAR2 and a NUMBER data type result?

    1. Oracle will convert them implicitly and return a VARCHAR2 data type result
    2. Oracle will convert them implicitly and return a NUMBER data type result
    3. An ORA error is thrown
    4. None of the above

    61. What is true about a schema?

    1. A schema is owned by a database user and has the same name as that user
    2. Each user owns a single schema
    3. Schema objects include database links
    4. All of the above

    62. In which order the values will get inserted with respect to the above INSERT statement?

    1. Location_id , manager_id, department_name , department_id
    2. department_id , department_name , manager_id, location_id
    3. department_id , manager_id, department_name , location_id
    4. department_id , department_name , location_id , manager_id

    63. What among the following is true about tables?

    1. A default value is given to a table
    2. A default value can be given to a column of a table during an INSERT statement
    3. Either of A or B
    4. None of the above

    65. Which of the below SQL query will display employee names, department, and annual salary?

    1. SELECT ename, deptno, sal FROM emp;
    2. SELECT ename, deptno, sal + comm FROM emp;
    3. SELECT ename, deptno, (sal * 12) Annual_Sal FROM emp;
    4. Annual salary cannot be queried since the column doesn”t exists in the table

    66. What is true about the SUBSTR function in Oracle DB?

    1. It extracts a string of determined length
    2. It shows the length of a string as a numeric value
    3. It finds the numeric position of a named character
    4. It trims characters from one (or both) sides from a character string

    67. Which of the following SELECT statements lists the highest retail price of all books in the Family category?

    1. SELECT MAX(retail) FROM books WHERE category = ''FAMILY
    2. SELECT MAX(retail) FROM books HAVING category = ''FAMILY
    3. SELECT retail FROM books WHERE category = ''FAMILY'' HAVING MAX(retail);
    4. None of the above

    68. Which of the following functions can be used to include NULL values in calculations?

    1. SUM
    2. NVL
    3. MAX
    4. MIN

    69.Which statements best describes the inference drawn from the questions 34 and 35?

    1. There are duplicate values for job codes
    2. The query executes but results produced are unexpected
    3. There are no duplicate values for departments
    4. None of the above

    70. What will be the outcome of the following query?

    SELECT length(''hi'') FROM dual;
    1. 2
    2. 3
    3. 1
    4. hi

    Answer:

    Answer(1): A. The ROUND function will round off the value 144.23 according to the specified precision -1 and returns 140.

    Examine the structure of the EMPLOYEES table as given and answer the questions 2 and 3 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Answer(2): A. Using parenthesis will explicitly change the order of evaluation when INTERSECT is used with other operators.

    Answer(3): A, D. On strict grounds, SELECT is a DML command as it is one of the mandatory clauses for manipulation of data present in tables.

    Answer(4): A.Select the required from the tables each separated by a comma.

    Answer(5): C. Simple and Complex views are two types of views. Simple views are based on a subquery that references only one table and doesn”t include group functions, expressions, or GROUP BY clauses. Complex views are based on a subquery that retrieves or derives data from one or more tables and can contain functions or grouped data.

    Answer(6): C. All the combined should have the same no. of columns when using SET operators. The corresponding columns in the queries that make up a compound query must be of the same data type group.

    Answer:(7) D. Multiple-row subqueries return more than one row of results.Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.

    Answer(8): C. An index can be created to speed up the query process. DML operations are always slower when indexes exist. Oracle 11g creates an index for PRIMARY KEY and UNIQUE constraints automatically. An explicit index is created with the CREATE INDEX command. An index can be used by Oracle 11g automatically if a query criterion or sort operation is based on a column or an expression used to create the index.

    Answer(9): A. Using the SELECT clause is the most common technique for inserting rows into tables. It reduces the effort of manually keying in values for each column.

    Answer(10): A. View definition can make use of sub-queries.

    Answer(11): C. DESCRIBE is used to show the table structure along with table columns, their data type and nullity

    Answer(12): C. Any arithmetic operation with NULL results in a NULL.

    Answer()13: C, D.

    Answer(14): C. The ANSI SQL: 1999 syntax though not used as much as the traditional Oracle syntax, it still is one of the syntaxes that may be used in Oracle SQL

    Answer(15): B. Correlated subquery references a column in the outer query and executes the subquery once for every row in the outer query while Uncorrelated subquery executes the subquery first and passes the value to the outer query.

    Answer(16): D. The constraints on the column must be obeyed while updating its value. In the given UPDATE statement, error will be thrown because the EMPLOYEE_ID column is a primary key in the EMPLOYEES table which means it cannot be NULL.

    Answer(17): D. The WHERE clause can be omitted and the relevant conditions can be accommodated in the JOIN..ON clause itself as shown in the given query

    Answer(18): A. Table1 JOIN table2 JOIN table3 is not allowed without the ON clauses for between each JOIN

    Answer(19): C. The leading zeroes in the right operand of expression are ignored by Oracle.

    Answer(20): A, C. You cannot create a table with the name same as an Oracle Server reserved word.

    Answer(21): C. The BETWEEN operator can be used within a sub-query but not with a sub-query.

    Answer(22): D. Functions can perform calculations, perform case conversions and type conversions.

    Answer(23): A, C. A join can be an inner join,in which the only records returned have a matching record in all tables,or an outer join, in which records can be returned regardless of whether there”s a matching record in the join.An outer join is created when records need to be included in the results without having corresponding records in the join tables. These records are matched with NULL records so that they”re included in the output.

    Answer(24): B. Ff you include the FORCE keyword in the CREATE clause, Oracle 11g creates the view in spite of the absence of any referenced tables. NOFORCE is the default mode for the CREATE VIEW command, which means all tables and columns must be valid, or the view isn”t created.

    Answer(25): D.

    Answer(26): A, B. A user must possess the CREATE TABLE privilege and must have sufficient space to allocate the initial extent to the table segment.

    Answer(27): A.

    Answer(28): C. The FULL OUTER JOIN returns the non-matched rows from both the tables. A full outer join includes all records from both tables, even if no corresponding record in the other table is found.

    Answer(29): B.In SQL, concatenation operator is represented by two vertical bars (||).

    Answer(30): C. Parenthesis can be used to group the specific queries in order to change the precedence explicitly. Parentheses are preferred over other SET operators during execution.

    Answer(31): A. UNION Returns the combined rows from two queries, sorting them and removing duplicates.

    Answer(32): C. The WITH READ ONLY option prevents performing any DML operations on the view. This option is used often when it”s important that users can only query data, not make any changes to it.

    Answer(33): B, C. NOFORCE is the default mode for the CREATE VIEW command, which means all tables and columns must be valid, or the view isn”t created.

    Answer(34): B. The OR REPLACE option notifies Oracle 11g that a view with the same name might already exist; if it does, the view”s previous version should be replaced with the one defined in the new command.

    Answer(35): A. There are basically two types of functions – Single row and Multiple row functions.

    Answer(36): B. Character, Date, Conversion, General, Number are the types of Single row functions.

    Answer(37): B. Multiple Row functions always work on a group of rows and return one value per group of rows.

    Answer(38): C. Group functions are same as Multi row functions and aggregate functions.

    Answer(39): A. The COUNT(*) counts the number of rows including duplicates and NULLs. Use DISTINCT and ALL keyword to restrict duplicate and NULL values.

    Answer(40): D. A table must have atleasr one column, its data type specification, and precision (if required).

    Answer(41): C. Specifying alias name is good practice to improve the readability of the code and the view queries.

    Answer(42): C. COUNT (column) ignores the NULL values but counts the duplicates.

    Answer(43): C. The NATURAL JOIN clause implicitly matches all the identical named columns. To add additional conditions the WHERE clause can be used.

    Answer(44): A. GROUPING SETS operations can be used to perform multiple GROUP BY aggregations with a single query.

    Answer(45): B. The sequence of the column alias not matters much as they don”t carry any behavioral attribute.

    Answer(46): B. The WHERE clause predicate is optional in DELETE statement. If the WHERE clause is omitted, all the rows of the table will be deleted.

    Answer(47): B. Provided the last names in the employees table are in a proper case, the condition WHERE last_name = ”smith” will not be satistified and hence no results will be displayed.

    Answer(48): C. As a part of the active or a new transaction, the rows in the table will be deleted.

    Answer(49): D. A compound query is one query made up of several queries using different tables.

    Answer(50): D.

    Answer(51): B. A compound query will by default return rows sorted across all the columns,from left to right in ascending order.The only exception is UNION ALL, where the rows will not be sorted. The only place where an ORDER BY clause is permitted is at the end of the compound query.

    Answer(52): C. COUNT(ALL column) ignores the NULL values but counts the duplicates.

    Answer(53): A.

    Answer(54): B. COUNT (DISTINCT column) counts the distinct not null values.

    Answer(55): C. The VARIANCE function accepts single numeric argument as the column name and returns variance of all the column values considering NULLs.

    Answer(56): D. HAVING Clause is used for restricting group results. You use the HAVING clause to specify the groups that are to be displayed, thus further restricting the groups on the basis of aggregate information. The HAVING clause can precede the GROUP BY clause, but it is recommended that you place the GROUP BY clause first because it is more logical. Groups are formed and group functions are calculated before the HAVING clause is applied to the groups in the SELECT list.

    Answer(57): B.

    Answer(58): C. ”> ALL” More than the highest value returned by the subquery. ”< ALL” Less than the lowest value returned by the subquery. ”< ANY” Less than the highest value returned by the subquery. ”> ANY” More than the lowest value returned by the subquery. ”= ANY” Equal to any value returned by the subquery (same as IN). ”[NOT] EXISTS” Row must match a value in the subquery.

    Answer(59): C. The view DEPT_SUM_VU is still a complex view as it uses DISTINCT keyword. Hence, DML operations are not possible on it.

    Answer(60): C. Oracle does not convert data types implicitly.

    Answer(61): D. The user space in a database is known as schema. A schema contains the objects which are owned or accessed by the user. Each user can have single schema of its own.

    Answer(62): B. If the columns are mentioned in the INSERT clause, the VALUES keyword should contain values in the same order

    Answer(63): B. A default value can be specified for a column during the definition using the keyword DEFAULT.

    Answer(65): C. Use numeric expressions in SELECT statement to perform basic arithmetic calculations.

    Answer(66): A. The SUBSTR(string, x, y) function accepts three parameters and returns a string consisting of the number of characters extracted from the source string, beginning at the specified start position (x). When position is positive, then the function counts from the beginning of string to find the first character. When position is negative, then the function counts backward from the end of string.

    Answer(67): A. Since the category FAMILY has to be restricted before grouping, table rows must be filtered using WHERE clause and not HAVING clause.

    Answer(68): B. NVL is a general function to provide alternate values to the NULL values. It can really make a difference in arithmetic calculations using AVG, STDDEV and VARIANCE group functions.

    Answer(69): C. As the combination of the job codes and departments is unique, there are no duplicates obtained.

    Answer(70): A. the LENGTH function simply gives the length of the string.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL Certificate – Discussion nhận dự án làm có lương

    Discuss SQL Certificate



    Oracle”s Oracle Database 11g: SQL Fundamentals exam is part of the Oracle Certified Oracle Database 11g Administrator track, combining training, experience, and testing to endorse candidates with a strong foundation and expertise in the industry’s most advanced database management system.

    This certification is to put you on the short list for winning Oracle SQL-Based projects. An Oracle Technical Certification is a valuable, industry-recognized credential that signifies a proven level of knowledge and skill.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Get Data from Multiple Tables nhận dự án làm có lương

    SQL – Get Data from Multiple Tables Questions



    1.Which of the following is not related to a Relational Database?

    1. Selection
    2. Projection
    3. Joining
    4. None of the above

    Answer: D. The options A, B and C are the major capabilities of the Oracle Relational Database.

    2.Which of the following methods is used for writing a query with columns from multiple tables?

    1. SELECT
    2. GROUP BY
    3. ORDER BY
    4. JOINS

    Answer: D. Joins are used to connect multiple tables and project column data from multiple tables in Oracle.

    3.Which of the following is one of the most common methods to join multiple tables?

    1. Hash Join
    2. Equijoin
    3. Self Join
    4. Cross Join

    Answer: B. Equijoin is one of the types of joins which is the most common and simple technique for joining more than one tables. Equijoins are also called simple joins or inner joins.Equijoin involve primary key and foreign key.

    4.Which of following will be used to join rows with other tables if the column values fall in a range defined by inequality operators?

    1. Equijoin
    2. Simple join
    3. Non-equijoin
    4. None of the above

    Answer: C. Equijoins use equality operators to join rows, non-equijoins use inequality operators.

    5.Which of the following statements is true about Oracle joins?

    1. NULL values are included in the result set
    2. Only the rows which have matching conditions are fetched
    3. All the rows that are present in any of the one tables are fetched
    4. None of the above

    Answer: B. NULL values and differing entries in common join columns are excluded when joins are used.

    6.Which of the following can be used to join the rows of a table with other rows of the same table?

    1. Equijoin
    2. Non-equijoin
    3. Outer join
    4. Self-join

    Answer: D. The association is based on columns with logical and usually hierarchical relationships with each other.

    7.What is true about a cartesian join of two tables in Oracle DB?

    1. It must be avoided as it is costly and non optimized
    2. It is formed when every row from one table is joined with all rows in the second table
    3. Both A and B
    4. None of the above

    Answer: B. Cartesian join is often the result of missing or inadequate join conditions.It is simply the cross product of two tables.

    8.Which of the following is one of the basic types of joins in Oracle DB ?

    1. Outer join
    2. Self-join
    3. Equi-join
    4. All of the above

    Answer: C. Equi-join and non-equijoin are the two basic types of joins in Oracle DB.

    9.What is the main condition for using joins between a source table and a target table in Oracle DB for getting a non-cartesian product result?

    1. There is no condition
    2. At least one of the columns in both the tables should be common.
    3. The names of the columns in both the joining tables should be the same for using joins
    4. None of the above

    Answer: B. The tables must be connected through a common column relating two entities.The table joined on a common column produce non Cartesian product.

    10. Which of the following can be used to fetch rows from multiple tables in a single SQL query?

    1. SELECT
    2. WHERE
    3. FROM
    4. Equi-joins

    Answer: D. Equijoins are also called simple joins or inner joins. Equijoin involve primary key and foreign key.

    11.What is true about the source table and the target table in terms of Oracle Joins?

    1. They must have atleast one column of same name
    2. All the columns should be of the same name and same data type for joining the two tables
    3. The source and the target tables cannot be swapped and are position specific
    4. None of the above

    Answer: D. The source and the target tables can be swapped and are not fixed at their positions.Depending of the type of join used in the query, the result may differ or remain same.

    12.What is true about Natural joins in Oracle DB?

    1. The column names of the source and the target tables should be identical
    2. If the column names of the source and the target tables are not same, Oracle implicitly does the needful
    3. NATURAL JOINS, USING and ON are the keywords associated with Natural Joins
    4. All of the above

    Answer: C. The keyword NATURAL JOIN instruct Oracle to identify columns with identical names between source and target tables. Natural joins use all columns with matching names and data types to join the tables. The USING clause can be used to specify only those columns that should be used for an equijoin.

    13.Assume the tables EMPLOYEES and DEPARTMENT have to be joined using NATURAL JOIN. What is the difference between the following two queries which follow? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT department_id
    FROM employees NATURAL JOIN department
    WHERE first_name = ''John''
    AND last_name = ''Bacon
    
    SELECT department_id
    FROM department NATURAL JOIN employees
    WHERE first_name = ''John''
    AND last_name = ''Bacon
    
    1. There is no difference
    2. The result is different in both the cases
    3. Both the queries will give an ORA error on execution
    4. None of the above

    Answer: B. The source and target tables can be swapped while using NATURAL JOIN giving relationally different result sets.

    14.Which of the following options is true regarding the NATURAL JOIN in Oracle DB?

    1. While using NATURAL JOIN mentioning the names of all the columns from both the tables is mandatory
    2. NATURAL JOIN can be used only if the names of all the columns of both the tables are identical
    3. The join in NATURAL JOIN happens only when the user specifies the columns of the source and the target tables.
    4. There is no need to mention the columns when using NATURAL JOINS.

    Answer: D. There”s an implicit joining of the columns from the source and the target tables when a NATURAL JOIN is used. A NATURAL JOIN is a JOIN operation that creates an implicit join clause for you based on the common columns in the two tables being joined.Common columns are columns that have the same name in both tables.

    15. What is the difference between a NATURAL JOIN and a join with JOIN..ON?

    1. There is no difference between the both
    2. JOIN..ON joins the source and target tables on specific columns with the same name
    3. NATURAL JOIN implicitly joins all the matching columns from the source and target tables
    4. None of the above

    Answer: B, C. The join condition for the natural join is basically an equijoin of all columns with the same name.Use the ON clause to specify arbitrary conditions or specify columns to join.The join condition is separated from other search conditions. The ON clause makes code easy to understand.

    16.What is true about the JOIN..ON clause in Oracle DB?

    1. It does not depend on the columns in the source and target tables having identical names
    2. Only those columns from the source and the target tables which have identical names can be used with this clause
    3. It is a format of the NATURAL JOIN
    4. All of the above

    Answer: A, C. The join condition for the natural join is basically an equijoin of all columns with the same name. Use the ON clause to specify arbitrary conditions or specify columns to join. The join condition is separated from other search conditions. The ON clause makes code easy to understand.

    17. The database designer has named the key (unique) columns from two tables differently.While joining these tables, which among the following will be the best practice?

    1. JOIN..ON
    2. Either NATURAL JOIN or JOIN…ON clauses
    3. Both A and B
    4. None of the above

    Answer: A. Using NATURAL JOINS in this case can yield unexpected results as there is an implicit searching of columns with identical names which in this case is not present.

    18.What of the following can be used to fetch non-matching rows along with the matching rows between a source and a target table in Oracle DB?

    1. EQUI-JOIN
    2. SELF-JOIN
    3. NATURAL JOIN
    4. OUTER-JOIN

    Answer: D. An outer join is created when records need to be included in the results without having corresponding records in the join tables. These records are matched with NULL records so that they”re included in the output.

    19. What are Cartesian Joins also known as in Oracle DB?

    1. Equi-join
    2. Anti-join
    3. Cross-Join
    4. None of the above

    Answer: C. A Cartesian join between two tables returns every possible combination of rows from the tables. A Cartesian join can be produced by not including a join operation in the query or by using a CROSS JOIN.

    20.What will be the result of a NATURAL JOIN between two tables EMPLOYEES and DEPARTMENT as given in the query below? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT * FROM employees NATURAL JOIN department;
    1. The common column DEPARTMENT_ID with identical name in both the tables will appear twice in the result set
    2. All the columns having identical names joined with the NATURAL JOIN, will appear twice in the result set
    3. The result set will have only one column for each pair of identically named columns from both tables
    4. None of the above

    Answer: C. The NATURAL JOIN keywords don”t require a condition to establish the relationship between two tables. However, a common column must exist. Column qualifiers can”t be used with the NATURAL JOIN keywords.

    21.What is the difference between a NATURAL JOIN and an EQUI-JOIN in Oracle DB?

    1. There is no difference
    2. They are the same with respect to the result set that is obtained from both
    3. Both A and B
    4. None of the above

    Answer: D. NATURAL JOIN joins all the columns with identical names whereas EQUI-JOIN requires the columns to be explicitly mentioned in the SQL query.

    22.What is an INNER JOIN in Oracle DB?

    1. The join giving the matching records between two tables is called an INNER JOIN
    2. An inner join can use operators like <,>, <>
    3. Both A and B
    4. None of the above

    Answer: C. A join can be an inner join, in which the only records returned have a matching record in all tables, or an outer join, in which records can be returned regardless of whether there”s a matching record in the join.

    23.What is the difference between a INNER JOIN and an EQUI-JOIN in Oracle DB?

    1. They are the same in terms of syntax and result sets obtained.
    2. An INNER JOIN is a subset of an EQUI-JOIN
    3. An INNER JOIN can use operators like <,>, <> along with “=” while EQUI-JOIN only uses the “=” operator
    4. All of the above

    Answer: C. EQUI-JOIN is a type of INNER JOIN containing “=” operator in a join condition, whereas the INNER JOIN can contain both equality as well non-equality operators

    24.What is true about NATURAL JOINS in terms of ANSI SQL: 1999 syntaxes in Oracle DB?

    1. An Equality operator (=) is used
    2. They fetch different results when compared to the traditional syntax
    3. The ANSI SQL syntax uses words like NATURAL JOIN in the SQL queries
    4. None of the above.

    Answer: C. ANSI SQL syntax is different from the traditional way of using (=) in the traditional ways. There are keywords like NATURAL JOIN etc. in the ANSI SQL syntax to distinguish the joins used.

    25.What of the following is true with respect to the query given below? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT first_name, salary
    FROM employees e, departments d
    WHERE e.department_id  (+) = d.department_id ;
    
    1. There is an outer join between the department_id from both tables which is equivalent to a Right Outer join in ANSI SQL
    2. There is an outer join between the department_id from both tables which is equivalent to a Left Outer join in ANSI SQL
    3. It fetches all the records of the department_id from the employees table whether they match or not
    4. It fetches all the records of the department_id from the department table whether they match or not

    Answer: A, D. The condition e.department_id (+) = d.department_id means it will perform a Right Outer Join and all the department_id s from the department table will be displayed whether they match or not

    26.Which of the following syntax models is used in extensively in the software systems worldwide?

    1. ANSI SQL: 1999
    2. Both traditional Oracle syntax and the ANSI SQL: 1999 syntax
    3. Traditional Oracle syntax
    4. All of the options

    Answer: C. The ANSI SQL: 1999 syntax though not used as much as the traditional Oracle syntax, it still is one of the syntaxes that may be used in Oracle SQL

    27.What of the following is true regarding the Cartesian product in Oracle DB?

    1. If ”N” is the no of tables joined, then if no. of joins is N-1, Cartesian product is not performed
    2. If ”N” is the no of tables joined, then if no. of joins is N, Cartesian product is performed
    3. If ”N” is the no of tables joined, then if no. of joins is N+1, Cartesian product is performed
    4. If ”N” is the no of tables joined, then if no. of joins is N-1 or less, Cartesian product is performed.

    Answer: A. A Cartesian join between two tables returns every possible combination of rows from the tables. A Cartesian join can be produced by not including a join operation in the query or by using a CROSS JOIN. A query must have at least (N-1) join conditions to prevent a cartesian product, where N is the number of tables in the query.

    28.What is the reason of error in the following SQL query? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT first_name, last_name
    FROM employees, departments
    WHERE department_id (+) = department_id ;
    
    1. There are no aliases used for the tables.
    2. The word RIGHT OUTER JOIN is not used here hence it throws the error
    3. The (+) should be on the Right side of the equality condition and not on the left side
    4. Table Aliases should be used with the department_id in the condition to remove ambiguous naming

    Answer: D. Without the table aliases, Oracle is unable to derive the origin of the columns being joined and hence throws an Ambiguity error on execution.

    29.Which of the following is used to avoid the ambiguous column problem in Oracle DB?

    1. ;
    2. ,
    3. .
    4. /

    Answer: C. The syntax for removing the Ambiguous column issue is: table_alias.column_name

    30.Which of the following is the most appropriate about the following query? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT employee_id , first_name, last_name
    FROM employees e right outer join department d
    On e.department_id  = d.department_id ;
    
    1. It gives the details of those employees who are not in any department
    2. It gives the details of those departments which do not have any employee
    3. It gives the details of all departments irrespective of whether they”ve any employee or not
    4. It gives the details of the employees which were hired in the company ”ABC” irrespective of the departments.

    Answer: C. With the JOIN method for outer joins, you can add the LEFT, RIGHT, or FULL keywords. A left outer join includes all records from the table listed on the left side of the join, even if no match is found with the other table in the join operation. A full outer join includes all records from both tables, even if no corresponding record in the other table is found.

    31.What will be the outcome of the following query? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT *
    FROM employees e, department d
    WHERE a.department_id  = b.department_id ;
    
    1. It will give all the matching values from both the tables which have the same department_id
    2. It will give all the columns from the table employees and only the top 100 rows from the departments table
    3. It will give an ORA error: “b.department_id ” invalid identifier
    4. None of the above options

    Answer: C. The same aliases should in the WHERE clause as declared in the FROM clause

    32.Which of the following is true regarding the USING and ON clauses in table joins? (Choose more than one options if applicable)

    1. The ON clause can be used to join tables on columns with the same data type but not necessarily the same name
    2. The USING and ON clauses are used on only equijoins and non-equijoins
    3. Not more than one condition can be used with the ON clause
    4. The WHERE clause can be written after the USING..ON clause to apply additional conditions

    Answer: A, D. The JOIN … USING approach is similar to the NATURAL JOIN approach, except the common column is specified in the USING clause. A condition can”t be included in the USING clause to indicate how the tables are related. In addition, column qualifiers can”t be used for the common column specified in the USING clause. The JOIN… ON approach joins tables based on a specified condition. The JOIN keyword in the FROM clause indicates the tables to be joined, and the ON clause indicates how the two tables are related. This approach must be used if the tables being joined don”t have a common column with the same name in each table.

    33.How many tables can be joined by using the JOINS in Oracle DB?

    1. 1
    2. 2
    3. 255
    4. No limit

    Answer: D. There is currently no limit on the number of tables participating in a join.

    34. What is true when multiple joins are used in an SQL statement?

    1. The joins are evaluated from left to right
    2. The joins are evaluated from right to left
    3. There is no precedence in the process of the evaluation of joins
    4. None of the above

    Answer: A. When multiple-joins exist in a statement, they are evaluated from left to right.

    35.What is true with respect to the following query? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
    SELECT bonus, first_name, department_id
    FROM bonus b NATURAL JOIN employees e NATURAL JOIN department d;
    
    1. The use of NATURAL JOIN to join multiple tables is a better option and yields accurate results
    2. The error probability is very less when NATURAL JOINs are used to join multiple tables
    3. The clauses USING..JOIN..ON give more accurate results than NATURAL JOINs when joining multiple tables
    4. Oracle implicitly joins multiple tables when a NATURAL JOIN is used and hence it is a good practice to use NATURAL JOINS

    Answer: C. The use of NATURAL JOINS can create Cartesian products of rows and also are error prone with non-dependable result sets.

    36.What is true about the clauses JOIN..ON in Oracle DB?

    1. They are not very dependable as compared to NATURAL JOINS when joining multiple tables
    2. The JOIN..ON clause is similar to the WHERE clause which limits rows with conditions
    3. An additional WHERE clause is mandatory when the JOIN..ON clause is used
    4. None of the above

    Answer: B. The JOIN …. ON approach joins tables based on a specified condition. The JOIN keyword in the FROM clause indicates the tables to be joined, and the ON clause indicates how the two tables are related. This approach must be used if the tables being joined don”t have a common column with the same name in each table.

    Examine the table structures as given. Answer the questions 37 and 38 that follow the query given below:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT e.salary, d.department_id
    FROM employees e JOIN department d
    On (e.department_id  = d.department_id  and e.last_name = ''Brandon'');
    

    37.What is true with respect to the query given above?

    1. It gives an ORA error as the mandatory WHERE clause is not present
    2. The JOIN..ON clause can”t contain more than one condition
    3. The query ignores the last condition and executes without an ORA error
    4. The JOIN..ON clause can be written in the form given above for putting more conditions.

    Answer: D. The WHERE clause can be omitted and the relevant conditions can be accommodated in the JOIN..ON clause itself as shown in the given query

    38.With respect to the given query, if the JOIN used is replaced with NATURAL JOIN, it throws an error. What is the reason for this error?

    1. When the NATURAL JOIN is used, a WHERE clause is mandatory, omitting which gives an error
    2. The ON clause should be replaced with the USING clause
    3. The words NATURAL, JOIN and USING are mutually exclusively in the context of the same join clause
    4. A query can”t combine the NATURAL JOIN and ON (or USING) clauses while joining.

    Answer: C, D.

    39.What is true about Non-equijoins in Oracle DB?

    1. They join based on the keyword NON-EQUI JOIN
    2. They are used using the JOIN..ON clause with “=” sign
    3. The results are obtained when the result of the inequality mentioned evaluates to true.
    4. None of the above

    Answer: C. The non-equi joins are used with the JOIN..ON clause but with inequality operators.

    Examine the structures of the tables EMPLOYEES and DEPARTMENTS as given and answer the questions 40 and 41 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    40.What will be the outcome of the following query in Oracle DB?

    SELECT e.first_name, e.last_name, e.employee_id
    FROM employees e JOIN department d
    ON (e.salary BETWEEN 1000 AND 10000);
    
    1. It will throw an ORA error as the condition in the ON clause is incorrect.
    2. It will throw an ORA error due to a syntax error as there is no Equality sign “=” in the ON clause
    3. It will execute successfully and give the first name, last name and employee ID of employees with the condition mentioned.
    4. Non-equi joins can only be used for showing in-equalities and not ranges.

    Answer: C.

    41.You need to find a report which lists the first names and last names of the employees whose salary is greater than 20000 and who are located in any of the departments in the location Geneva. Which of the following queries will give the required results?

    1. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      AND d.loc = upper (''Geneva'');
    2. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000);
    3. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000)
      AND d.loc = ''Geneva 
    4. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      WHERE d.loc = upper(''Geneva'');

    Answer: A, C.

    42.On which of the following conditions is a row returned when an EQUI-JOIN is used to join tables?

    1. The result of the inequality match operation is true
    2. The result of the inequality match operation is 0
    3. The result of the inequality match operation is 1
    4. The result of the inequality match operation is false

    Answer: A. An equality join is created when data joining records from two different tables is an exact match (that is, an equality condition creates the relationship).The traditional approach uses an equal sign as the comparison operator in the WHERE clause. The JOIN approach can use the NATURAL JOIN, JOIN … USING, or JOIN … ON keywords.

    41.You need to find a report which lists the first names and last names of the employees whose salary is greater than 20000 and who are located in any of the departments in the location Geneva. Which of the following queries will give the required results?

    1. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      AND d.loc = upper (''Geneva'');
    2. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000);
    3. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000)
      AND d.loc = ''Geneva 
    4. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      WHERE d.loc = upper(''Geneva'');

    Answer: A, C.

    42.On which of the following conditions is a row returned when an EQUI-JOIN is used to join tables?

    1. The result of the inequality match operation is true
    2. The result of the inequality match operation is 0
    3. The result of the inequality match operation is 1
    4. The result of the inequality match operation is false

    Answer: A. An equality join is created when data joining records from two different tables is an exact match (that is, an equality condition creates the relationship).The traditional approach uses an equal sign as the comparison operator in the WHERE clause. The JOIN approach can use the NATURAL JOIN, JOIN … USING, or JOIN … ON keywords.

    41.You need to find a report which lists the first names and last names of the employees whose salary is greater than 20000 and who are located in any of the departments in the location Geneva. Which of the following queries will give the required results?

    1. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      AND d.loc = upper (''Geneva'');
    2. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000);
    3. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000)
      AND d.loc = ''Geneva 
    4. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      WHERE d.loc = upper(''Geneva'');

    Answer: A, C.

    42.On which of the following conditions is a row returned when an EQUI-JOIN is used to join tables?

    1. The result of the inequality match operation is true
    2. The result of the inequality match operation is 0
    3. The result of the inequality match operation is 1
    4. The result of the inequality match operation is false

    Answer: A. An equality join is created when data joining records from two different tables is an exact match (that is, an equality condition creates the relationship).The traditional approach uses an equal sign as the comparison operator in the WHERE clause. The JOIN approach can use the NATURAL JOIN, JOIN … USING, or JOIN … ON keywords.

    41.You need to find a report which lists the first names and last names of the employees whose salary is greater than 20000 and who are located in any of the departments in the location Geneva. Which of the following queries will give the required results?

    1. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      AND d.loc = upper (''Geneva'');
    2. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000);
    3. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >=20000)
      AND d.loc = ''Geneva 
    4. SELECT e.first_name, e.last_name
      FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id  and e.salary >20000)
      WHERE d.loc = upper(''Geneva'');

    Answer: A, C.

    42.On which of the following conditions is a row returned when an EQUI-JOIN is used to join tables?

    1. The result of the inequality match operation is true
    2. The result of the inequality match operation is 0
    3. The result of the inequality match operation is 1
    4. The result of the inequality match operation is false

    Answer: A. An equality join is created when data joining records from two different tables is an exact match (that is, an equality condition creates the relationship).The traditional approach uses an equal sign as the comparison operator in the WHERE clause. The JOIN approach can use the NATURAL JOIN, JOIN … USING, or JOIN … ON keywords.

    43.What is true regarding a Self-Join in Oracle DB?

    1. Only two tables are required for the join to work
    2. The columns in the result set are obtained from two tables but are displayed in one table
    3. Conceptually, the source table duplicates itself to create the target table. (Oracle doesn”t duplicate tables)
    4. All of the above

    Answer: C. Self-joins are used when a table must be joined to itself to retrieve the data you need. Table aliases are required in the FROM clause to perform a self-join.

    44. With respect to the query and the table structure given below,answer the question.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT *
    FROM employees a join employees b
    WHERE a.employee_id  = b.employee_id ;
    

    Which of the following tables does Oracle treat as source table and target table?

    1. a is source and b is target
    2. b is source and a is target
    3. Oracle doesn”t treat any of the tables as source or target
    4. None of the above

    Answer: A. The first occurrence of employees table is taken as source and the subsequent occurrences as b, c and so on.

    45.In what scenarios can we use Self-Joins ideally in Oracle DB?

    1. When we need to find the duplicate records in a table
    2. When we need to obtain NULL values from a table
    3. When we need to display a column of a table twice
    4. When we need to display hierarchy of relevant entities

    Answer: D.

    46. What is true about NATURAL JOINS in Oracle DB?

    1. The joined columns have the same name but can have different data types
    2. The joined columns can have the same data type but different names
    3. The joined columns should have identical names and the same data type
    4. None of the above

    Answer: C. The NATURAL JOIN keywords don”t require a condition to establish the relationship between two tables. However, a common column must exist.Column qualifiers can”t be used with the NATURAL JOIN keywords.

    47.A report has to be extracted which gives the department name, department ID, department city and location ID only for departments 100 and 101. Using NATURAL JOINS, which of the following options will give the required results?

    Table DEPARTMENTS Table LOCATIONS
    1. SELECT department_id , department_name  ,location, city
      FROM departments
      NATURAL JOIN locations
      WHERE department_id in (100,101);
      
    2. SELECT department_id , department_name  ,location, city
      FROM locations
      NATURAL JOIN departments
      WHERE department_id BETWEEN 100 AND 101;
      
    3. SELECT department_id , department_name  ,location, city
      FROM departments
      NATURAL JOIN locations
      WHERE department_id >100
      AND department_id >101;
      
    4. SELECT department_id , department_name  ,location, city
      FROM departments
      NATURAL JOIN locations ; 

    Answer: A. The WHERE can be used for additional conditions after the NATURAL JOIN clause.

    48.In which of the following scenarios shall a USING clause or a NATURAL JOIN clause be used?

    1. When the names of the columns from the tables are identical then use USING clause
    2. When the data types of the columns from the tables are identical then use NATURAL JOINS
    3. If several columns have the same names but the data types do not match, USING can be used
    4. NATURAL JOINS should be used only when the column names and their data types are the same

    Answer: C, D. NATURAL JOINS and USING are mutually exclusive, the USING clause should be used to match only one column when more than one columns match.

    49.Examine the table structures given. What will be the outcome of the following query? (Choose the most appropriate answer)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
    SELECT e.name, b.bonus
    FROM employees e
    JOIN bonus b
    USING (job_id)
    WHERE e.job_id  like ''SA%'');
    
    1. It gives the names and bonus obtained by all the employees in some company
    2. It gives the names and bonus obtained by all the employees in a particular job title in a company
    3. It executes successfully giving all the names and the bonus obtained by all the employees in all jobs
    4. It throws an ORA error.

    Answer: D. The column(s) used in the USING clause should not have a qualifier (table name or alias) anywhere in the SQL statement.

    50.What is true with respect to INNER JOINS and OUTER JOINS in Oracle DB?

    1. INNER JOIN returns only the rows that are matched
    2. OUTER JOIN returns only the rows that are not matched
    3. OUTER JOIN returns the rows that are matched as well as those which do not match
    4. None of the above

    Answer: A, C. A join can be an inner join,in which the only records returned have a matching record in all tables,or an outer join, in which records can be returned regardless of whether there”s a matching record in the join.An outer join is created when records need to be included in the results without having corresponding records in the join tables. These records are matched with NULL records so that they”re included in the output.

    51. What is true regarding FULL OUTER JOIN in Oracle DB?

    1. When both LEFT OUTER JOIN and RIGHT OUTER JOIN appear in the same query,it is called a FULL OUTER JOIN
    2. A FULL OUTER JOIN is the same as an OUTER JOIN
    3. Both A and B
    4. A join between two tables that returns the results of an INNER join and a LEFT and RIGHT OUTER JOIN is called a FULL OUTER JOIN

    Answer: D. A full outer join includes all records from both tables, even if no corresponding record in the other table is found.

    Examine the given table structures and answer the questions 52 and 53 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)

    52.Consider the following query.

    SELECT e.job_id , e.first_name, d.department_id
    FROM departments D JOIN employees e JOIN BONUS b
    USING (job_id );
    

    This query results in an error. What is the reason of the error?

    1. A JOIN..USING can happen only between two tables at a time
    2. USING clause in the query doesn”t have any column from the department
    3. There is no WHERE clause in the query
    4. None of the above

    Answer: A. Table1 JOIN table2 JOIN table3 is not allowed without the ON clauses for between each JOIN

    53.You need to display all the non-matching rows from the EMPLOYEES table and the non-matching rows from the DEPARTMENT table without giving a Cartesian product of rows between them. Which of the following queries will give the desired output?

    1. SELECT *
      FROM employees e, department d
      WHERE e.department_id  = d.department_id ;
      
    2. SELECT *
      FROM employees e NATURAL JOIN department d;
      
    3. SELECT *
      FROM employees e FULL OUTER JOIN department d
      ON  e.department_id  = d.department_id ;
      
    4. SELECT *
      FROM employees e JOIN  department d
      ON ( e.department_id  > d.department_id ) ; 

    Answer: C. The FULL OUTER JOIN returns the non-matched rows from both the tables. A full outer join includes all records from both tables, even if no corresponding record in the other table is found.

    54.Which of the following ANSI SQL: 1999 join syntax joins are supported by Oracle?

    1. Cartesian products
    2. Natural joins
    3. Full OUTER join
    4. Equijoins

    Answer: D.

    55.Which of the following is not a format for Outer Joins in Oracle DB?

    1. Right
    2. Left
    3. Centre
    4. Full

    Answer: C. Except ”Centre”, rest 3 types are the types of formats of the Outer Joins in Oracle DB. With the JOIN method for outer joins, you can add the LEFT, RIGHT, or FULL keywords.

    Examine the given table structures. Answer the questions 56, 57 and 58 that follow by referring to the following query:

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SELECT *
    FROM employees e NATURAL JOIN department d;
    

    56.You need to find the results obtained by the above query only for the departments 100 and 101. Which of the following clauses should be added / modified to the above query?

    1. ON (e.department_id = d.department_id ) should be added
    2. USING (e.department_id ) should be added
    3. WHERE e.department_id in (100,101) should be added
    4. None of the above

    Answer: C. The NATURAL JOIN clause implicitly matches all the identical named columns. To add additional conditions the WHERE clause can be used.

    57.You need to find the results obtained by the above query for all those employees who have salaries greater than 20000. Which of the following clauses should be added / modified to the above query?

    1. ON (e.department_id = d.department_id ) WHERE salary > 20000;
    2. USING (e.department_id ) WHERE salary > 20000;
    3. USING (department_id ) WHERE salary>20000;
    4. WHERE salary >20000;

    Answer: D.

    58.If the NATURAL JOIN in the above query is replaced by only JOIN which of the following should be added / modified to the above query to give the results pertaining to Department 100?

    1. ON (department_id = 100);
    2. USING (e.department_id =100);
    3. WHERE d.department_id = 100;
    4. ON (e.department_id = d.department_id and d.department_id = 100);

    Answer: D. The equi-joins can be added for more conditions after the ON clause.

    59.A report has to be extracted to get the Managers for all the employees in the departments 10 and 20 of a company ”ABC”. Which of the following queries will give the required results? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT a.first_name || '' ''||a.last_name "Manager", b.first_name||'' ''||b.last_name "Employees"
      FROM employees a join employees b
      On (employee_id );
    2. SELECT a.first_name || '' ''||a.last_name "Manager", b.first_name||'' ''||b.last_name "Employees"
      FROM employees a join employees b
      On (b.employee_id  = a.employee_id );
    3. SELECT a.first_name || '' ''||a.last_name "Manager", b.first_name||'' ''||b.last_name "Employees"
      FROM employees a join employees b
      On (a.manager_id  = b.employee_id )
      WHERE department_id  in (10,20);
      
    4. SELECT a.first_name || '' ''||a.last_name "Manager", b.first_name||'' ''||b.last_name "Employees"
      FROM employees a join employees b
      On (a.manager_id  = b.employee_id )
      WHERE a.department_id  in (10,20);

    Answer: D. The option C is incorrect because the non-aliased department_id in the WHERE clause will throw an error.

    60.Which of the following queries will give results without duplicate values between the two tables EMPLOYEES and DEPARTMENT? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    1. SELECT *
      FROM employees e NATURAL JOIN department d;
      
    2. SELECT *
      FROM employees e JOIN department d;
      
    3. SELECT *
      FROM employees e NATURAL JOIN department d
      USING (e.department_id );
      
    4. SELECT *
      FROM employees e FULL OUTER JOIN department d
      USING (department_id );

    Answer: D. The FULL OUTER JOIN will give all the matching as well non-matching rows from both the tables excluding duplicate values.

    Examine the structures for the tables as given here and answer the questions 61 to 64.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
    SQL> desc locations
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     LOCATION_ID		 NOT NULL NUMBER(4)
     STREET_ADDRESS 		  VARCHAR2(40)
     POSTAL_CODE			  VARCHAR2(12)
     CITY			 NOT NULL VARCHAR2(30)
     STATE_PROVINCE 		  VARCHAR2(25)
     COUNTRY_ID			  CHAR(2)
    SQL> desc locations
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     LOCATION_ID		 NOT NULL NUMBER(4)
     STREET_ADDRESS 		  VARCHAR2(40)
     POSTAL_CODE			  VARCHAR2(12)
     CITY			 NOT NULL VARCHAR2(30)
     STATE_PROVINCE 		  VARCHAR2(25)
     COUNTRY_ID			  CHAR(2)

    61.What is true about the following query? (Choose the most appropriate answer)

    SELECT *
    FROM bonus b, employees e
    WHERE b.job_id  (+) = e.job_id ;
    
    1. It will display all the bonuses obtained by all the employees.
    2. It will display NULL for the bonus column if a particular employee has not received any bonus
    3. Both A and B
    4. None of the above

    Answer: B. The (+) is on the LHS of the equation means it is a RIGHT OUTER JOIN and vice versa.

    62.You have to list all the departments who have no employees yet in a company named ”XYZ”. Which of the following queries will give you the required results?

    1. SELECT department_id , department_name FROM departments d NATURAL JOIN employees e;
      
    2. SELECT department_id , department_name FROM employees e JOIN departments d
      ON (e.department_id  = d.department_id );
      
    3. SELECT department_id , department_name FROM employees e LEFT OUTER JOIN departments d
      USING (department_id );
      
    4. SELECT department_id , department_name FROM employees e RIGHT OUTER JOIN departments d
      ON (e.department_id  = d.department_id );

    Answer: D.

    63.You need to extract a report which displays ”No department yet” for all those employees who are yet to be allocated to a department. Which of the following will fulfill the purpose?

    1. SELECT nvl(department_id ,''No department yet'')
      FROM employees e RIGHT OUTER JOIN departments d
      ON (e.department_id  = d.department_id );
      
    2. SELECT nvl(department_id ,''No department yet'')
      FROM departments d LEFT OUTER JOIN employees e
      ON (e.department_id  = d.department_id );
      
    3. SELECT nvl(department_id ,''No department yet'')
      FROM employees e LEFT OUTER JOIN departments d
      ON (e.department_id  = d.department_id );
      
    4. SELECT nvl(department_id ,''No department yet'')
      FROM employees e FULL OUTER JOIN departments d
      ON (e.department_id  = d.department_id );

    Answer: C.

    64.You need to extract a report which displays all the departments which have not been assigned to a city yet. Which of the following queries will give you the required output?

    1. SELECT department_id , department_name FROM departments d NATURAL JOIN locations l;
      
    2. SELECT department_id , department_name FROM departments d FULL OUTTER JOIN locations l
      ON (d.location_id = l.location_id);
      
    3. SELECT  d.department_id , d.department_name FROM departments d JOIN locations l
      USING (location_id);
      
    4. SELECT department_id , department_name FROM departments d LEFT OUTER JOIN locations l
      ON (d.location_id = l.location_id); 

    Answer: D.

    65.In which two cases an OUTER JOIN should be used?

    1. If the joined tables” columns have NULL values
    2. If the joined tables have NOT NULL columns
    3. If the joined tables have only un-matched data
    4. If the joined tables have both matching as well as non-matching data

    Answer: A, D. An outer join is created when records need to be included in the results without having corresponding records in the join tables. These records are matched with NULL records so that they”re included in the output.

    66.You need to find the salary grade obtained by each employee. Which of the following query will you use? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc grade
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     GRADE 				  NUMBER
     LOSAL 				  NUMBER
     HISAL				  NUMBER
    1. SELECT employee_id , salary, grade
      FROM employees e JOIN grade g
      ON g.grade BETWEEN g.losal AND g.hisal
      
    2. SELECT employee_id , salary, grade
      FROM employees e FULL OUTER JOIN grade g
      WHERE g.grade > g.losal AND < g.hisal;
      
    3. SELECT employee_id , salary, grade
      FROM employees e JOIN grade g
      ON (MIN(g.grade) = g.losal
      AND MAX(g.grade) = g.hisal);
      
    4. None of the above

    Answer: A.

    67.Examine the table structures given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)

    Evaluate this SQL statement:

    SELECT e.employee_id , (.25* e.salary) + (.5 * e.commission_pct) + (.75 * b.bonus) as calc_val
    FROM employees e, bonus b
    WHERE e.employee_id  = b.employee_id ;
    

    What will happen if you remove all the parentheses from the calculation?

    1. The value displayed in the calc_val column will be lesser.
    2. The value displayed in the calc_val column will be higher.
    3. There will be no difference in the calc_val column.
    4. An error will be reported.

    Answer: C.

    68.Consider the exhibit and examine the structures of the EMPLOYEES, DEPARTMENTS, and GRADE tables. For which situation would you use a non-equijoin query?

    Table EMPLOYEES Table DEPARTMENTS Table GRADE
    1. To find the grade for each of the employees
    2. To list the name, job_id, and manager name for all the employees
    3. To find the department name of employees.
    4. To find the number of employees working for the Administrative department and earning less than 30000

    Answer: A. A non-equality join establishes a relationship based on anything other than an equal condition. Range values used with non-equality joins must be mutually exclusive.

    69.In which three cases would you use the USING clause? (Choose three.)

    1. You want to create a non-equijoin.
    2. The tables to be joined have multiple NULL columns.
    3. The tables to be joined have columns of the same name and different data types.
    4. You want to use a NATURAL join, but you want to restrict the number of columns in the join condition.

    Answer: C, D. The JOIN …. USING approach is similar to the NATURAL JOIN approach, except the common column is specified in the USING clause. A condition can”t be included in the USING clause to indicate how the tables are related. In addition, column qualifiers can”t be used for the common column specified in the USING clause.

    70.If the tables EMPLOYEES and BONUS have two columns with identical names viz: – SALARY and JOB_ID, which of the following queries are equivalent to each other? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
    1. SELECT * FROM employees E JOIN bonus B on (salary, job_id )
    2. SELECT * FROM employees E NATURAL JOIN bonus B on (salary, job_id )
    3. SELECT * FROM employees E JOIN bonus B USING (salary, job_id )
    4. SELECT * FROM employees E JOIN bonus B on (salary, job_id )

    Answer: B, C.

    71.Examine the table structures as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    Examine the following two SQL statements:

    Query 1
    SELECT first_name,department_id
    FROM employees E JOIN departments D
    USING (department_id );
    
    Query 2
    SELECT first_name,department_id
    FROM employees E NATURAL JOIN departments D
    USING (department_id );
    

    Which statement is true regarding the outcome?

    1. Only query 1 executes successfully and gives the required result.
    2. Only query 2 executes successfully and gives the required result.
    3. Both queries 1 and 2 execute successfully and give different results.
    4. Both queries 1 and 2 execute successfully and give the same required result.

    Answer: D.

    72.You need to generate a report showing the department location along with the employee name for all hires made before 20th January, 2013.

    Table DEPARTMENTS Table EMPLOYEES Table LOCATIONS

    You issue the following query:

    SELECT department_name  , first_name||'' ''||last_name
    FROM employees E JOIN department d
    ON ( hire_date < ''20-JAN-2013'')
    JOIN locations L
    ON  (l.location_id = d.location_id) ;
    

    Which statement is true regarding the above query?

    1. It executes successfully and gives the required result.
    2. It executes successfully but does not give the required result.
    3. It produces an error because the join order of the tables is incorrect.
    4. It produces an error because equijoin and non-equijoin conditions cannot be used in the same SELECT statement.

    Answer: B.

    73.Examine the structure of the EMPLOYEES table:

    Table EMPLOYEES

    You want to find out if any employee” details have been entered more than once using different EMPLOYEE_ID , by listing all the duplicate names. Which method can you use to get the required result?

    1. self-join
    2. full outer-join with self-join
    3. left outer-join with self-join
    4. right outer-join with self-join

    Answer: A. Self-joins are used when a table must be joined to itself to retrieve the data you need. Table aliases are required in the FROM clause to perform a self-join.

    Examine the structure of the tables DEPARTMENTS and LOCATIONS and answer the questions 74 and 75 that follow.

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    SQL> desc locations
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     LOCATION_ID		 NOT NULL NUMBER(4)
     STREET_ADDRESS 		  VARCHAR2(40)
     POSTAL_CODE			  VARCHAR2(12)
     CITY			 NOT NULL VARCHAR2(30)
     STATE_PROVINCE 		  VARCHAR2(25)
     COUNTRY_ID			  CHAR(2)

    74.You need to find out the departments that have not been allocated any location. Which query would give the required result?

    1. SELECT d.department_id , d.department_name FROM departments d JOIN locations l
      ON (d.location_id = l.location_id);
      
    2. SELECT d.department_id , d.department_name FROM departments d RIGHT OUTER JOIN locations l
      ON (d.location_id = l.location_id);
      
    3. SELECT d.department_id , d.department_name FROM departments d FULL JOIN locations l
      ON (d.location_id = l.location_id);
      
    4. SELECT d.department_id , d.department_name FROM departments d LEFT OUTER JOIN locations l
      ON (d.location_id = l.location_id);

    Answer: B.

    75.You want to list all departments that are not located in any location along with the department name. Evaluate the following query:

    SELECT d.department_id , d.department_name  ,l.location_id, l.city
    FROM departments D __________________   location L
    ON (d.location_id = l.location_id);
    

    Which two JOIN options can be used in the blank in the above query to give the correct output?

    1. JOIN
    2. NATURAL JOIN
    3. LEFT OUTER JOIN
    4. RIGHT OUTER JOIN

    Answer: A, C.

    76. You need to generate a report that shows all department IDs, with corresponding employees (if any) and bonus details (if any), for all employees. Which FROM clause gives the required result? (Consider the table structures as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> desc bonus
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER
     JOB_ID 			  VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
    1. FROM departments LEFT OUTER JOIN employees USING (department_id ) FULL OUTER JOIN bonus
    2. FULL OUTER JOIN department USING (department_id );
    3. FROM bonus JOIN employees USING (job_id )
    4. FROM employees FULL OUTER JOIN departments FULL OUTER JOIN bonus

    Answer: A.

    77. Examine the following exhibits:

    Table BONUS Table DEPARTMENTS Table EMPLOYEES

    You want to generate a report listing the employees” IDs and their corresponding commissions and departments (if any), if the commissions exist or not. Evaluate the following query:

    SELECT e.employee_id , bonus, department_name FROM bonus b_____________ employees
    USING (job_id ) ____________ departments
    USING (department_id )
    WHERE commission_pct  IS NOT NULL;
    

    Which combination of joins used in the blanks in the above query gives the correct output?

    1. JOIN; LEFT OUTER JOIN
    2. FULL OUTER JOIN; FULL OUTER JOIN
    3. RIGHT OUTER JOIN; LEFT OUTER JOIN
    4. LEFT OUTER JOIN; RIGHT OUTER JOIN

    Answer: A.

    78.Predict the outcome of the following query.

    SELECT e.salary, bonus
    FROM employees E JOIN bonus b
    USING (salary,job_id );
    
    1. It executes successfully.
    2. It throws an error because bonus in SELECT is not aliased
    3. It throws an error because the USING clause cannot have more than 1 column.
    4. It executes successfully but the results are not correct.

    Answer: D.

    View the Exhibit and examine the structure of the EMPLOYEES, DEPARTMENTS, LOCATIONS and BONUS. Answer the questions from 79 and 80 that follow:

    Table BONUS Table DEPARTMENTS Table EMPLOYEES Table GRADE Table LOCATIONS

    79.You need to list all the departments in the city of Zurich. You execute the following query:

    SELECT D.DEPARTMENT_ID , D.DEPARTMENT_NAME  , L.CITY
    FROM departments D JOIN LOCATIONS L
    USING (LOC_ID,CITY)
    WHERE L.CITY = UPPER(''ZURICH'');
    

    Predict the outcome of the above query.

    1. It executes successfully.
    2. It gives an error because a qualifier is used for CITY in the SELECT statement.
    3. It gives an error because the column names in the SELECT do not match
    4. It gives an error because the USING clause has CITY which is not a matching column.

    Answer: D. Only the matching column names should be used in the USING clause.

    80.Answer the question that follows the query given below:

    SELECT e.first_name, d.department_id , e.salary, b.bonus
    FROM bonus b join employees e
    USING (job_id )
    JOIN department d
    USING (department_id )
    WHERE d.loc = ''Zurich
    

    You need to extract a report which gives the first name, department number, salary and bonuses of the employees of a company named ”ABC”. Which of the following queries will solve the purpose?

    1. SELECT e.first_name, d.department_id , e.salary, b.bonus
      FROM bonus b join employees e join departments d
      on (b.job_id  = e.job_id )
      on (e.department_id =d.department_id )
      WHERE d.loc = ''Zurich
      
    2. SELECT e.first_name, d.department_id , e.salary, b.bonus
      FROM bonus b join employees e
      on (b.job_id  = e.job_id )
      JOIN department d
      on (e.department_id =d.department_id )
      WHERE d.loc = ''Zurich
      
    3. SELECT e.first_name, d.department_id , e.salary, b.bonus
      FROM employees e join bonus b
      USING (job_id )
      JOIN department d
      USING (department_id )
      WHERE d.loc = ''Zurich
      
    4. None of the above

    Answer: C. The query A will throw a syntactical error, query B will throw an invalid identifier error between bonus and department.

    Examine the Exhibits given below and answer the questions 81 to 85 that follow.

    Table BONUS Table DEPARTMENTS Table EMPLOYEES

    81. You need to find the managers” name for those employees who earn more than 20000. Which of the following queries will work for getting the required results?

    1. SELECT e.employee_id  "Employee", salary, employee_id ,
      FROM employees E JOIN employees M
      USING (e.manager_id  = m.employee_id )
      WHERE e.salary >20000;
      
    2. SELECT e.employee_id  "Employee", salary, employee_id ,
      FROM employees E JOIN employees M
      USING (e.manager_id)
      WHERE e.salary >20000;
      
    3. SELECT e.employee_id  "Employee", salary, employee_id ,
      FROM employees E  NATURAL JOIN employees M
      USING (e.manager_id = m.employee_id )
      WHERE e.salary >20000;
      
    4. SELECT e.employee_id  "Employee", salary, employee_id ,
      FROM employees E JOIN employees M
      ON (e.manager_id = m.employee_id )
      WHERE e.salary >20000; 

    Answer: D.

    82.You issue the following query:

    SELECT e.employee_id ,d.department_id
    FROM employees e NATURAL JOIN department d NATURAL JOIN bonus b
    WHERE department_id  =100;
    

    Which statement is true regarding the outcome of this query?

    1. It executes successfully.
    2. It produces an error because the NATURAL join can be used only with two tables.
    3. It produces an error because a column used in the NATURAL join cannot have a qualifier.
    4. It produces an error because all columns used in the NATURAL join should have a qualifier.

    Answer: C.

    83.You want to display all the employee names and their corresponding manager names. Evaluate the following query:

    SELECT e.first_name "EMP NAME", m.employee_name "MGR NAME"
    FROM employees e ______________ employees m
    ON e.manager_id = m.employee_id ;
    

    Which JOIN option can be used in the blank in the above query to get the required output?

    1. Simple inner JOIN
    2. FULL OUTER JOIN
    3. LEFT OUTER JOIN
    4. RIGHT OUTER JOIN

    Answer: C. A left outer join includes all records from the table listed on the left side of the join, even if no match is found with the other table in the join operation.

    Consider the below exhibit and following query to answer questions 84 and 85. (Assume the table department has manager_id and department_name as its columns)

    Table DEPARTMENTS
    Select *
    FROM employees e JOIN department d
    ON (e.employee_id  = d.manager_id);
    

    84. You need to display a sentence “(first_name) (last_name) is manager of the (department_name) department”. Which of the following SELECT statements will successfully replace ”*” in the above query to fulfill this requirement?

    1. SELECT e.first_name||'' ''||e.last_name||'' is manager of the ''||d.department_name||'' department.'' "Managers"
    2. SELECT e.first_name, e.last_name||'' is manager of the ''||d.department_name||'' department.'' "Managers"
    3. SELECT e.last_name||'' is manager of the ''||d.department_name||'' department.'' "Managers"
    4. None of the above

    Answer: A.

    85.What will happen if we omit writing the braces “( )” after the ON clause in the above query?

    1. It will give only the names of the employees and the managers” names will be excluded from the result set
    2. It will give the same result as with braces “( )”
    3. It will give an ORA error as it is mandatory to write the braces “()” when using the JOIN..ON clause
    4. None of the above

    Answer: B. The braces are not mandatory, but using them provides a clear readability of the conditions within it.

    86. Which of the following queries creates a Cartesian join?

    1. SELECT title, authorid FROM books, bookauthor;
    2. SELECT title, name FROM books CROSS JOIN publisher;
    3. SELECT title, gift FROM books NATURAL JOIN promotion;
    4. all of the above

    Answer: A, B. A Cartesian join between two tables returns every possible combination of rows from the tables. A Cartesian join can be produced by not including a join operation in the query or by using a CROSS JOIN.

    87. Which of the following operators is not allowed in an outer join?

    1. AND
    2. =
    3. OR
    4. >

    Answer: C. Oracle raises the exception “ORA-01719: outer join operator (+) not allowed in operand of OR or IN”

    88. Which of the following queries contains an equality join?

    1. SELECT title, authorid FROM books, bookauthor WHERE books.isbn = bookauthor.isbn AND retail > 20;
    2. SELECT title, name FROM books CROSS JOIN publisher; 
    3. SELECT title, gift FROM books, promotion WHERE retail >= minretail AND retail <= maxretail;
    4. None of the above

    Answer: A. An equality join is created when data joining records from two different tables is an exact match (that is, an equality condition creates the relationship).

    89. Which of the following queries contains a non-equality join?

    1. SELECT title, authorid FROM books, bookauthor WHERE books.isbn = bookauthor.isbn AND retail > 20;
    2. SELECT title, name FROM books JOIN publisher USING (pubid);
    3. SELECT title, gift FROM books, promotion WHERE retail >= minretail AND retail <= maxretail;
    4. None of the above

    Answer: D. Nonequijoins match column values from different tables based on an inequality expression. The value of the join column in each row in the source table is compared to the corresponding values in the target table. A match is found if the expression used in the join, based on an inequality operator, evaluates to true. When such a join is constructed, a nonequijoin is performed.A nonequijoin is specified using the JOIN..ON syntax, but the join condition contains an inequality operator instead of an equal sign.

    90. The following SQL statement contains which type of join?

    SELECT title, order#, quantity
    FROM books FULL OUTER JOIN orderitems
    ON books.isbn = orderitems.isbn;
    
    1. equality
    2. self-join
    3. non-equality
    4. outer join

    Answer: D. A full outer join includes all records from both tables, even if no corresponding record in the other table is found.

    91. Which of the following queries is valid?

    1. SELECT b.title, b.retail, o.quantity FROM books b NATURAL JOIN orders od NATURAL JOIN orderitems o WHERE od.order# = 1005;
    2. SELECT b.title, b.retail, o.quantity FROM books b, orders od, orderitems o WHERE orders.order# = orderitems.order# AND orderitems.isbn=books.isbn AND od.order#=1005;
    3. SELECT b.title, b.retail, o.quantity FROM books b, orderitems o WHERE o.isbn = b.isbn AND o.order#=1005;
    4. None of the above

    Answer: C. If tables in the joins have alias, the selected columns must be referred with the alias and not with the actual table names.

    92. Given the following query.

    SELECT zip, order#
    FROM customers NATURAL JOIN orders;

    Which of the following queries is equivalent?

    1. SELECT zip, order# FROM customers JOIN orders WHERE customers.customer# = orders.customer#;
    2. SELECT zip, order# FROM customers, orders WHERE customers.customer# = orders.customer#;
    3. SELECT zip, order# FROM customers, orders WHERE customers.customer# = orders.customer# (+);
    4. none of the above

    Answer: B. Natural join instructs Oracle to identify columns with identical names between the source and target tables.

    93. Examine the table structures as given. Which line in the following SQL statement raises an error?

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)
    1. SELECT e.first_name, d.department_name
    2. FROM employees  e, department d
    3. WHERE e.department_id=d.department_id
    
    1. line 1
    2. line 2
    3. line 3
    4. No errors

    Answer: A. If a query uses alias names in the join condition, their column should use the alias for reference.

    94. Given the following query:

    SELECT lastname, firstname, order#
    FROM customers LEFT OUTER JOIN orders
    USING (customer#)
    ORDER BY customer#;
    

    Which of the following queries returns the same results?

    1. SELECT lastname, firstname, order# FROM customers c OUTER JOIN orders o ON c.customer# = o.customer# ORDER BY c.customer#;
    2. SELECT lastname, firstname, order# FROM orders o RIGHT OUTER JOIN customers c ON c.customer# = o.customer# ORDER BY c.customer#;
    3. SELECT lastname, firstname, order# FROM customers c, orders o WHERE c.customer# = o.customer# (+) ORDER BY c.customer#;
    4. None of the above

    Answer: B, C.

    95. Which of the below statements are true?

    1. Group functions cannot be used against the data from multiple data sources.
    2. If multiple tables joined in a query, contain identical columns, Oracle selects only one of them.
    3. Natural join is used to join rows from two tables based on identical columns.
    4. A and B

    Answer: C. Group functions can be used on a query using Oracle joins. Ambiguous columns must be referenced using a qualifier.

    96. Which line in the following SQL statement raises an error?

    1. SELECT name, title
    2. FROM books JOIN publisher
    3. WHERE books.pubid = publisher.pubid
    4. AND
    5. cost < 45.95
    
    1. line 1
    2. line 2
    3. line 3
    4. line 4

    Answer: C. Since the tables are joined using JOIN keyword, the equality condition should be written with the USING clause and not WHERE clause.

    97. Given the following query:

    SELECT title, gift
    FROM books CROSS JOIN promotion;

    Which of the following queries is equivalent?

    1. SELECT title, gift
      FROM books NATURAL JOIN promotion;
      
    2. SELECT title
      FROM books INTERSECT
      SELECT gift
      FROM promotion;
      
    3. SELECT title
      FROM books UNION ALL
      SELECT gift
      FROM promotion;
      
    4. SELECT title, gift
      FROM books, promotion;
      

    Answer: D. Cartesian joins are same as Cross joins.

    98. If the CUSTOMERS table contains seven records and the ORDERS table has eight records, how many records does the following query produce?

    SELECT *
    FROM customers CROSS JOIN orders;
    
    1. 0
    2. 56
    3. 7
    4. 15

    Answer: B. Cross join is the cross product of rows contained in the two tables.

    99. Which of the following SQL statements is not valid?

    1. SELECT b.isbn, p.name
      FROM books b NATURAL JOIN publisher p;
      
    2. SELECT isbn, name
      FROM books b, publisher p
      WHERE b.pubid = p.pubid;
      
    3. SELECT isbn, name
      FROM books b JOIN publisher p
      ON b.pubid = p.pubid;
      
    4. SELECT isbn, name
      FROM books JOIN publisher
      USING (pubid);
      

    Answer: A. Ambiguous columns must be referred with the table qualifiers.

    100. Which of the following lists all books published by the publisher named ”Printing Is Us”?

    1. SELECT title
      FROM books NATURAL JOIN publisher
      WHERE name = ''PRINTING IS US
      
    2. SELECT title
      FROM books, publisher
      WHERE pubname = 1;
      
    3. SELECT *
      FROM books b, publisher p
      JOIN tables ON b.pubid = p.pubid
      WHERE name = ''PRINTING IS US
      
    4. none of the above

    Answer: A. Assuming that the column NAME is not contained in BOOKS table, query A is valid.

    101. Which of the following SQL statements is not valid?

    1. SELECT isbn
      FROM books
      MINUS
      SELECT isbn
      FROM orderitems;
      
    2. SELECT isbn, name
      FROM books, publisher
      WHERE books.pubid (+) = publisher.pubid (+);
      
    3. SELECT title, name
      FROM books NATURAL JOIN publisher
      
    4. All the above SQL statements are valid.

    Answer: B. The query B raises an exception “ORA-01468: a predicate may reference only one outer-joined table”.

    102. Which of the following statements about an outer join between two tables is true?

    1. If the relationship between the tables is established with a WHERE clause, both tables can include the outer join operator.
    2. To include unmatched records in the results, the record is paired with a NULL record in the deficient table.
    3. The RIGHT, LEFT, and FULL keywords are equivalent.
    4. all of the above

    Answer: B.

    103. Which line in the following SQL statement raises an error?

    1. SELECT name, title
    2. FROM books b, publisher p
    3. WHERE books.pubid = publisher.pubid
    4. AND
    5. (retail > 25 OR retail-cost > 18.95);
    
    1. line 1
    2. line 3
    3. line 4
    4. line 5

    Answer: B. Since the tables used in the query have a qualifier, the columns must be referred using the same.

    104. What is the maximum number of characters allowed in a table alias?

    1. 10
    2. 155
    3. 255
    4. 30

    Answer: D. The table alias can be maximum of 30 characters.

    105. Which of the following SQL statements is valid?

    1. SELECT books.title, orderitems.quantity
      FROM books b, orderitems o
      WHERE b.isbn= o.ibsn;
    2. SELECT title, quantity
      FROM books b JOIN orderitems o;
    3. SELECT books.title, orderitems.quantity
      FROM books JOIN orderitems
      ON books.isbn = orderitems.isbn;
      
    4. none of the above

    Answer: C.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Using the Group Functions nhận dự án làm có lương

    SQL – Using the Group Functions Questions



    1. Which of the following is NOT a GROUP BY function?

    1. MAX
    2. MIN
    3. NVL
    4. AVG

    Answer: C. NVL is a general function used to provide alternate value to the NULL values. The functions MAX, MIN and AVG can be used as GROUP BY functions.

    2. Which of the following functions can be used without GROUP BY clause in SELECT query?

    1. COUNT
    2. MAX
    3. MIN
    4. AVG

    Answer: A, B, C, D. All the listed group functions can be used in a query provided no other columns are selected in the SELECT query.

    3. Which of the following SELECT query returns the department number with maximum salary compensated to an employee? (Consider the table structure as given)

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT department_id , max(salary ) FROM employees ;
    2. SELECT department_id , max(salary ) FROM employees  GROUP BY department_id ;
    3. SELECT max(salary ) FROM employees  GROUP BY department_id ;
    4. SELECT max(salary ) FROM employees ;

    Answer: B. The MAX function can be used to return the maximum salary in a department where each group is formed by a department.

    4. Which of the following statements are true about the COUNT function?

    1. The COUNT function counts the number of rows
    2. The COUNT(*) function counts the number of rows with duplicates and NULL values
    3. The COUNT(DISTINCT) function counts the number of distinct rows
    4. COUNT(*) is equivalent to COUNT(ALL)

    Answer: B. The COUNT(*) counts the number of rows including duplicates and NULLs. Use DISTINCT and ALL keyword to restrict duplicate and NULL values.

    5. What are the appropriate data types accepted by GROUP BY functions?

    1. Nested Tables
    2. NUMBER
    3. CLOB
    4. DATE

    Answer: B. The data types for the functions with an argument may be CHAR, VARCHAR2, NUMBER or DATE.

    6. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (*) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    Answer: A. The COUNT(*) counts the number of rows including duplicates and NULLs. Use DISTINCT and ALL keyword to restrict duplicate and NULL values.

    7. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    Answer: C. COUNT (column) ignores the NULL values but counts the duplicates.

    8. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (ALL num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    Answer: C. COUNT(ALL column) ignores the NULL values but counts the duplicates.

    9. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

    SELECT COUNT (DISTINCT num) FROM t_count;
    1. 12
    2. 6
    3. 9
    4. Throws exception because COUNT function doesn”t works with NULL values

    Answer: B. COUNT (DISTINCT column) counts the distinct not null values.

    10. What happens when the below query is executed in SQL* Plus?

    SELECT COUNT() FROM dual;
    1. Executes successfully and returns no output
    2. Executes successfully and returns output as ”1”
    3. Throws exception “ORA-00909: invalid number of arguments”
    4. Throws exception “ORA-00904: “COUNT”: invalid identifier” because COUNT function doesn”t works with DUAL table

    Answer: C. COUNT function requires minimum one argument which can be either the column with [ALL | DISTINCT] modifier or ”*”.

    11. Here are few statements about VARIANCE function in SQL.

    i. The function accepts multiple numeric inputs and returns variance of all the values

    ii. The function accepts a number column and returns variance of all column values including NULLs

    iii. The function accepts a number column and returns variance of all column values excluding NULLs

    Chose the correct combination from the below options.
    1. i and iii
    2. i and ii
    3. ii
    4. iii

    Answer: C. The VARIANCE function accepts single numeric argument as the column name and returns variance of all the column values considering NULLs.

    12. Which of the following is NOT a GROUP BY extensions in SQL?

    1. GROUP BY
    2. GROUPING SETS
    3. CUBE
    4. ROLLUP

    Answer: A. GROUPING SETS operations can be used to perform multiple GROUP BY aggregations with a single query.

    13. Select the correct statements about the below query. Consider the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT department_id , SUM(salary )
    FROM employees
    GROUP BY department_id ;
    1. SUM is a group by function because it processes group of employees working in a department
    2. SUM is an aggregate function because it produces one result per group of data
    3. SUM is a single row function because it returns single value for a group i.e. department
    4. SUM is a group by extension function because it uses GROUP BY clause to logically group the departments

    Answer: A. SUM is a group function which calculates the sum of salaries of a group of employees working in a department.

    14. Which clause is used to filter the query output based on aggregated results using a group by function?

    1. WHERE
    2. LIMIT
    3. GROUP WHERE
    4. HAVING

    Answer: D. HAVING Clause is used for restricting group results. You use the HAVING clause to specify the groups that are to be displayed, thus further restricting the groups on the basis of aggregate information. The HAVING clause can precede the GROUP BY clause, but it is recommended that you place the GROUP BY clause first because it is more logical. Groups are formed and group functions are calculated before the HAVING clause is applied to the groups in the SELECT list.

    15. Examine the given table structure and predict the outcome of the following query.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT count(*)
    FROM employees
    WHERE comm = NULL;
    1. The query returns the number of employees who have no commission
    2. The query throws error because equal sign cannot be used when searching for NULL value
    3. The query returns the number of employees in a department whose commission is NULL value
    4. The query throws error because GROUP BY clause is missing in the query

    Answer: B. Excluding out NULLs using WHERE condition is a way to direct the query to ignore NULLs. But here the usage of IS NULL operator is wrong. The condition should be ”WHERE comm IS NULL”.

    16. Which of the following statements is true about the group functions?

    1. The MIN function can be used only with numeric data.
    2. The MAX function can be used only with date values.
    3. The AVG function can be used only with numeric data.
    4. The SUM function canít be part of a nested function.

    Answer: C. The AVG function can be only used with numeric values. Other functions which have such restriction are SUM, STDDEV and VARIANCE.

    17. Which of the following is a valid SELECT statement?

    1. SELECT AVG(retail-cost) FROM books GROUP BY category;
    2. SELECT category, AVG(retail-cost) FROM books;
    3. SELECT category, AVG(retail-cost) FROM books WHERE AVG(retail-cost) > 8.56 GROUP BY category;
    4. SELECT category, AVG(retail-cost) Profit FROM books GROUP BY category HAVING profit > 8.56;

    Answer: A. Column aliases cannot be used in GROUP BY or HAVING clause.

    18. Which of the following statements is correct?

    1. The WHERE clause can contain a group function only if the function isnít also listed in the SELECT clause.
    2. Group functions canít be used in the SELECT, FROM, or WHERE clauses.
    3. The HAVING clause is always processed before the WHERE clause.
    4. The GROUP BY clause is always processed before the HAVING clause.

    Answer: D. Though Oracle doesn”t raise error if HAVING clause precedes the GROUP BY clause but it is processed only after the GROUP BY clause is processed and group are ready to be filtered.

    19. Which of the following is not a valid SQL statement?

    1. SELECT MIN(pubdate) FROM books GROUP BY category HAVING pubid = 4;
    2. SELECT MIN(pubdate) FROM books WHERE category = ''COOKING
    3. SELECT COUNT(*) FROM orders WHERE customer# = 1005;
    4. SELECT MAX(COUNT(customer#)) FROM orders GROUP BY customer#;

    Answer: A.

    20. Which of the following statements is correct?

    1. The COUNT function can be used to determine how many rows contain a NULL value.
    2. Only distinct values are included in group functions, unless the ALL keyword is included in the SELECT clause.
    3. The WHERE clause restricts which rows are processed.
    4. The HAVING clause determines which groups are displayed in the query results.

    Answer: C, D. The WHERE clause restricts the rows before they are grouped and processed while HAVING clause restricts the groups.

    21. Which of the following is a valid SQL statement?

    1. SELECT customer#, order#, MAX(shipdate-orderdate) FROM orders GROUP BY customer# WHERE customer# = 1001;
    2. SELECT customer#, COUNT(order#) FROM orders GROUP BY customer#;
    3. SELECT customer#, COUNT(order#) FROM orders GROUP BY COUNT(order#);
    4. SELECT customer#, COUNT(order#) FROM orders GROUP BY order#;

    Answer: B. The GROUP BY clause must contain all the columns except the one which is used inside the group function.

    22. Which of the following SELECT statements lists only the book with the largest profit?

    1. SELECT title, MAX(retail-cost) FROM books GROUP BY title;
    2. SELECT title, MAX(retail-cost) FROM books GROUP BY title HAVING MAX(retail-cost);
    3. SELECT title, MAX(retail-cost) FROM books;
    4. None of the above

    Answer: A.

    23. Which of the following statement(s) is/are correct?

    1. A group function can be nested inside a group function.

    2. A group function can be nested inside a single-row function.

    3. A single-row function can be nested inside a group function.

    1. 1
    2. 2
    3. 3
    4. 1 and 3

    Answer: A, B, C. Group functions can be nested only to a depth of two. Group functions can be nested inside single-row functions (AVG embedded in a TO_CHAR function). In addition, single-row functions can be nested inside group functions.

    24. Which of the following functions is used to calculate the total value stored in a specified column?

    1. COUNT
    2. ADD
    3. TOTAL
    4. SUM

    Answer: D. SUM function is used to get the addition of numeric values.

    25. Which of the following SELECT statements lists the highest retail price of all books in the Family category?

    1. SELECT MAX(retail) FROM books WHERE category = ''FAMILY
    2. SELECT MAX(retail) FROM books HAVING category = ''FAMILY
    3. SELECT retail FROM books WHERE category = ''FAMILY'' HAVING MAX(retail);
    4. None of the above

    Answer: A. Since the category FAMILY has to be restricted before grouping, table rows must be filtered using WHERE clause and not HAVING clause.

    26. Which of the following functions can be used to include NULL values in calculations?

    1. SUM
    2. NVL
    3. MAX
    4. MIN

    Answer: B.NVL is a general function to provide alternate values to the NULL values. It can really make a difference in arithmetic calculations using AVG, STDDEV and VARIANCE group functions.

    27. Which of the following is not a valid statement?

    1. You must enter the ALL keyword in a group function to include all duplicate values.
    2. The AVG function can be used to find the average calculated difference between two dates.
    3. The MIN and MAX functions can be used on VARCHAR2 columns.
    4. All of the above

    Answer: A. The ALL keyword counts duplicates but ignores NULLs. Duplicates are also included with ”*” and column name specification.

    28. Which of the following SQL statements determines how many total customers were referred by other customers?

    1. SELECT customer#, SUM(referred) FROM customers GROUP BY customer#;
    2. SELECT COUNT(referred) FROM customers;
    3. SELECT COUNT(*) FROM customers;
    4. SELECT COUNT(*) FROM customers WHERE referred IS NULL;

    Answer: B. Considering all customers as one group, COUNT(referred) will count only those who are referred by someone. COUNT(referred) will ignore NULL values of the column.

    29. Determine the correct order of execution of following clauses in a SELECT statement.

    1.SELECT

    2.FROM

    3.WHERE

    4.GROUP BY

    5.HAVING

    6.ORDER BY

    1. 2-3-4-5-1-6
    2. 1-2-3-4-5-6
    3. 6-5-4-3-2-1
    4. 5-4-2-3-1-6

    Answer: A. Processing order starts from FROM clause to get the table names, then restricting rows using WHERE clause, grouping them using GROUP BY clause, restricting groups using HAVING clause. ORDER BY clause is the last one to be processed to sort the final data set.

    30. Which of the below clauses is used to group a set of rows based on a column or set of columns?

    1. HAVING
    2. WHERE
    3. GROUP BY
    4. GROUPING

    Answer: C. GROUP BY clause forms the groups of the data based on the column list specified.

    31. Which of the following group functions can be used for population variance and population standard deviation problems?

    1. VAR_POP
    2. STDDEV_POP
    3. VARIANCE
    4. STDDEV_SASMP

    Answer: A, B.

    32. Select the positions in a SELECT query where a group function can appear.

    1. SELECT statement
    2. WHERE clause
    3. ORDER BY clause
    4. GROUP BY clause

    Answer: A, C, D. Group functions can appear in SELECT, ORDER BY and HAVING clause. Oracle raises exception if group functions are used in WHERE or GROUP BY clauses.

    33. Examine the structure of the EMPLOYEES table as given. Which query will return the minimum salary in each department?

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    1. SELECT department_id , MIN (salary ) from EMPLOYEES ;
    2. SELECT department_id , MIN (salary ) from EMPLOYEES  GROUP BY department_id ;
    3. SELECT department_id , MIN (salary ) from EMPLOYEES  GROUP BY salary ;
    4. SELECT department_id , MIN (salary ) from EMPLOYEES  GROUP BY employee_id ;

    Answer: B. MIN function returns the minimum salary in a group formed by department.

    34. Examine the structure for the table EMPLOYEES and Interpret the output of the below query

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    SELECT COUNT(*), COUNT(all comm) FROM employees ;
    1. It throws error because only one aggregate function can be used in a query.
    2. It throws error because GROUP BY clause is missing.
    3. It executes successfully and returns same values for both.
    4. It executes successfully where COUNT(*) including NULLs and COUNT(all comm) excluding NULLs.

    Answer: D.

    35. Which of the following are true about group functions?

    1. You can use group functions in any clause of a SELECT statement.
    2. You can use group functions only in the column list of the select clause and in the WHERE clause of a SELECT statement.
    3. You can mix single row columns with group functions in the column list of a SELECT statement by grouping on the single row columns.
    4. You can pass column names, expressions, constants, or functions as parameter to an group function.

    Answer: C. Group functions can be nested only to a depth of two. Group functions can be nested inside single-row functions (AVG embedded in a TO_CHAR function). In addition, single-row functions can be nested inside group functions.

    36. Examine the structure of the table EMPLOYEES as given. You want to create a “emp_dept_sales” view by executing the following SQL statements.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)
    CREATE VIEW emp_dept_sales
    AS
    SELECT d.department_name , sum(e.salary )
    FROM employees  e, departments  d
    where e.department_id =d.department_id
    GROUP by d.department_name ;

    Which statement is true regarding the execution of the above statement?

    1. The view will be created and you can perform DLM operations on the view
    2. The view will not be created because the join statements are not allowed for creating a view
    3. The view will not be created because the GROUP BY clause is not allowed for creating a view
    4. The view will be created but no DML operations will be allowed on the view

    Answer: D. Rules for Performing DML Operations on a View. You cannot add data through a view if the view includes group functions or a GROUP BY clause or DISTINCT keyword. The pseudo column ROWNUM keyword Columns defined by expressions NOT NULL columns in the base tables that are not selected by the view.

    37. Which of the following statements are true regarding views?

    1. A sub query that defines a view cannot include the GROUP BY clause
    2. A view is created with the sub query having the DISTINCT keyword can be updated
    3. A Data Manipulation Language (DML) operation can be performed on a view that is created with the sub query having all the NOT NULL columns of a table
    4. A view that is created with the sub query having the pseudo column ROWNUM keyword cannot be updated

    Answer: C, D. Rules for Performing DML Operations on a View. You cannot add data through a view if the view includes group functions or a GROUP BY clause or DISTINCT keyword. The pseudo column ROWNUM keyword Columns defined by expressions NOT NULL columns in the base tables that are not selected by the view.

    38. Examine the table structure as given.

    SQL> DESC departments
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     DEPARTMENT_ID		 NOT NULL NUMBER(4)
     DEPARTMENT_NAME	 NOT NULL VARCHAR2(30)
     MANAGER_ID			  NUMBER(6)
     LOCATION_ID			  NUMBER(4)

    Which clause in the below SQL query generates error?

    SELECT department_id , avg(salary )
    FROM departments
    WHERE upper(job) in (''SALES'',''CLERK'')
    GROUP BY job
    ORDER BY department_id ;
    1. WHERE
    2. SELECT
    3. ORDER BY
    4. GROUP BY

    Answer: D. GROUP BY clause must contain all the columns appearing in the SELECT statement. It raises error because JOB is not a selected column. It should have used DEPARTMENT_ID in placed of JOB.

    39. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Which of the below SELECT query will display the maximum and minimum salary earned by each job category?

    1. SELECT job, MAX(salary ), MIN (salary ) FROM employees  GROUP BY department_id ;
    2. SELECT job, MAX(salary ), MIN (salary ) FROM employees  GROUP BY job;
    3. SELECT job, MAX(salary ), MIN (salary ) FROM employees ;
    4. Two aggregate functions cannot be used together in SELECT statement.

    Answer: B. More than one group function can appear in the SELECT statement.

    40. Consider the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Examine the error in the below query.

    SELECT department_id
    FROM employees
    WHERE hiredate > ''01-JAN-1985''
    AND COUNT(*) > 2
    GROUP by department_id
    HAVING SUM (salary ) > 1000;
    1. It executes successfully and generates the required result.
    2. It produces an error because COUNT(*) should be specified in the SELECT clause also.
    3. It executes successfully but produces no result because COUNT(prod_id) should be used instead of COUNT(*).
    4. It produces an error because COUNT(*) should be only in the HAVING clause and not in the WHERE clause.

    Answer: D. Group functions cannot be used in WHERE clause. The can appear in SELECT, HAVING and ORDER BY clause.

    41. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Predict the outcome of the below query

    SELECT job, COUNT(employee_id ),sum(salary )
    FROM employees
    GROUP BY job
    HAVING SUM (salary ) > 5000;
    1. It executes successfully and lists the count of employees under each job category but ignores the HAVING clause since “salary ” is not in GROUP BY clause.
    2. It throws error because HAVING clause is invalid.
    3. It throws error because “salary ” is not included in the GROUP BY clause.
    4. It executes successfully and lists the count of employees under each category having sum of salary greater than 5000.

    Answer: D. The HAVING clause restricts the group results. COUNT function is used for counting while SUM is used for adding the numeric values.

    42. What is true of using group functions on columns that contain NULL values?

    1. Group functions on columns ignore NULL values.
    2. Group functions on columns returning dates include NULL values.
    3. Group functions on columns returning numbers include NULL values.
    4. Group functions on columns cannot be accurately used on columns that contain NULL values.

    Answer: A. Except COUNT function, all the group functions ignore NULL values.

    43. Which of the following statetments are true about the usage of GROUP BY columns in a subquery?

    1. Subqueries can contain GROUP BY and ORDER BY clauses.
    2. Subqueries cannot contain GROUP BY and ORDER BY clauses.
    3. Subqueries can contain ORDER BY but not the GROUP BY clause.
    4. Subqueries cannot contain ORDER BY but can have GROUP BY clause.

    Answer: A. Like the primary query, a subquery can contain a GROUP BY as well as ORDER BY clause.

    Examine the table structure as given and answer the questions 44 to 49 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    44. Predict the outcome of the below query

    SELECT avg(max(salary ))
    FROM employees
    GROUP BY department_id
    HAVING avg(max(salary ))>100;
    1. It executes successfully.
    2. It gives an error because the HAVING clause is not valid.
    3. It gives an error because the GROUP BY expression is not valid.
    4. It gives an error because aggregate functions cannot be nested in SELECT statement.

    Answer: B. The HAVING clause doesn”t allows nesting of aggregate functions.

    45. Predict the output of the below query

    SELECT avg(salary ), department_id
    FROM employees
    GROUP BY department_id ;
    1. It gives error because an aggregate function cannot appear just after SELECT clause.
    2. It gives error because GROUP BY clause is invalid.
    3. It executes without errors but produces no output.
    4. It executes successfully and gives average salary in each department.

    Answer: D. Group functions can be used in any sequence (before or after the group by columns) in a SELECT query.

    46. Predict the output of the below query

    SELECT lower(job),avg(salary )
    FROM employees
    GROUP BY upper(job);
    1. It executes successfully and displays “job” in lower case.
    2. It executes successfully but display “job” in original case.
    3. It throws error because singe row and aggregate functions cannot be used together.
    4. It throws error because case conversion in the SELECT list mismatches with the case conversion GROUP BY clause.

    Answer: D. The function LOWER, being a single row function must be specified in the GROUP BY clause to base the grouping of EMPLOYEES data.

    47. Which of the below query executes successfully?

    1. SELECT employee_id , COUNT(hiredate-sysdate) FROM employees ;
    2. SELECT AVG(salary ), MAX(salary ) FROM employees ;
    3. SELECT AVG(salary ), MAX(salary ) FROM employees  GROUP BY department_id ;
    4. SELECT AVG(hiredate) FROM employees ;

    Answer: B, C. The first query operates of the whole EMPLOYEES data while the second one processes the data in groups of department.

    48. Identify the error in the below SELECT statement.

    SELECT department_id , AVG (salary )
    FROM employees
    GROUP BY department_id
    HAVING department_id  > 10;
    1. It executes successfully and displays average salary of departments higher than 10.
    2. It throws error because non aggregated column cannot be used in HAVING clause.
    3. It executes successfully but displays wrong result for the departments.
    4. It throws error because HAVING clause must be placed before GROUP BY clause.

    Answer: A. GROUP BY expressions can be used in HAVING clause to filter out the groups from the final data set.

    49. Predict the output of the below query

    SELECT department_id , AVG (salary )
    FROM employees
    GROUP BY department_id
    HAVING (department_id >10 and AVG(salary )>2000);
    1. It throws error because multiple conditions cannot be given in HAVING clause.
    2. It throws error because a non aggregate column cannot be used in HAVING clause.
    3. It executes successfully and displays average salary of department higher than 10 and greater than 2000.
    4. It executes successfully but no result is displayed.

    Answer: C. The HAVING clause can impose multiple conditions joined using AND or OR operator filter the groups.

    50. Which of the following group functions can be used with DATE values?

    1. AVG
    2. MIN
    3. SUM
    4. COUNT

    Answer: B, D. The group function AVG and SUM can be used with numeric data only.

    51. Which of the following statements are true?

    1. AVG and SUM can be used only with numeric data types.
    2. STDDEV and VARIANCE can be used only with numeric data types.
    3. MAX can be used with LONG data type.
    4. MAX and MIN cannot be used with LOB or LONG data types.

    Answer: A, B, D. The group functions AVG,SUM, VARIANCE and STDDEV can be used with numeric data only. None of the group functions can be used with LONG data type.

    52. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Identify the error in the below query.

    SELECT department_id , avg(salary ), count(hiredate)
    FROM employees
    GROUP BY department_id ;
    1. Multiple aggregate functions cannot be used in a single SELECT query
    2. GROUP BY clause is invalid
    3. COUNT function cannot be used with DATE values
    4. No errors and it executes successfully

    Answer: D.

    53. Which of the following group function can be used with LOB data types?

    1. MAX
    2. MIN
    3. COUNT
    4. None of these

    Answer: D. No aggregate function can be used with LOB data types.

    54. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Predict the output of the below two queries

    Query – 1

    SELECT avg(comm)
    FROM employees ;

    Query – 2

    SELECT avg(nvl(comm,0))
    FROM employees ;
    1. Both the queries produce same result
    2. Query – 1 and Query – 2 produce different results because Query-1 considers NULL values of COMM and Query-2 substitutes NULL values of COMM with zero
    3. Query – 1 produces error because COMM has NULL values
    4. Query – 2 produces error because NVL cannot be nested with aggregate function.

    Answer: B. The AVG function ignores NULL values while calculating the average of numeric data. AVG(column) will calculate average for only non null values. However, if NVL is used to substitute NULLs with a zero, all the values will be considered.

    55. Choose the correct statements about the GROUP BY clause.

    1. Column alias can be used in the GROUP BY clause.
    2. GROUP BY column must be in the SELECT clause.
    3. GROUP BY clause must appear together with HAVING clause a SELECT query.
    4. GROUP BY clause must appear after WHERE clause in a SELECT query.

    Answer: D. As per the processing sequence, the GROUP BY clause must appear after the WHERE clause in a SELECT query.

    56. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Predict the outcome of the below query

    SELECT department_id ,avg(salary )
    FROM employees
    GROUP BY department_id , job
    ORDER BY department_id ;
    1. It throws error because GROUP BY column list doesn”t matches with SELECT column list.
    2. It executes successfully and produces average salary of a job category in each department.
    3. It executes successfully and produces average salary for a department in each job category.
    4. It throws error because GROUP BY and ORDER BY clause have different list of columns.

    Answer: B. Though GROUP BY clause implicitly sorts the groups, the GROUP BY and ORDER BY clauses can be used together in a query.

    57. Which clause should you use to exclude group results in a query using group functions?

    1. WHERE
    2. HAVING
    3. GROUP BY
    4. ORDER BY

    Answer: B. HAVING clause is used to restrict the groups.

    Examine the table structure as given and answer the questions 58 and 59 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    58. Predict the outcome of the below query

    SELECT department_id ,avg(salary )
    FROM employees
    HAVING avg(salary )>2000
    GROUP BY department_id
    ORDER BY department_id 
    1. It executes successfully.
    2. It throws error because HAVING clause precedes the GROUP BY clause.
    3. It throws error because HAVING clause uses the aggregate function.
    4. It executes but no results are displayed because HAVING clause precedes the GROUP BY clause.

    Answer: A. HAVING clause can precede the GROUP BY clause but it is processed only after the group results are calculated.

    59. Predict the outcome of the below query

    SELECT department_id , COUNT(first_name )
    FROM employees
    WHERE job IN (''SALESMAN'',''CLERK'',''MANAGER'',''ANALYST'')
    GROUP BY department_id
    HAVING AVG(salary ) BETWEEN 2000 AND 3000;
    1. It returns an error because the BETWEEN operator cannot be used in the HAVING clause.
    2. It returns an error because WHERE and HAVING clauses cannot be used in the same SELECT statement.
    3. It returns an error because WHERE and HAVING clauses cannot be used to apply conditions on the same column.
    4. It executes successfully.

    Answer: D. The WHERE clause restricts the number of rows participating in group clause processing.

    60. Which statements are true regarding the WHERE and HAVING clauses in a SELECT statement?

    1. The HAVING clause can be used with group functions in subqueries.
    2. The WHERE clause can be used to exclude rows after dividing them into groups.
    3. The WHERE clause can be used to exclude rows before dividing them into groups.
    4. The WHERE and HAVING clauses can be used in the same statement only if they are applied to different columns in the table.

    Answer: A, C. WHERE and HAVING clause can be used together in a query. WHERE excludes the rows before group processing while HAVING restricts the groups.

    Examine the table structure as given and answer the questions 61 and 62 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    61. Predict the outcome of the below query.

    SELECT department_id , avg(salary )
    FROM employees
    HAVING avg(salary ) > min(salary )
    GROUP BY department_id ;
    1. It throws an error because the aggregate functions used in HAVING clause must be in SELECT list.
    2. It throws an error because the HAVING clause appears before GROUP BY clause.
    3. It displays the departments whose average salary is greater than the minimum salary of the department.
    4. It displays the departments whose average salary is greater than the minimum salary of the organization.

    Answer: C. Group functions can be used by HAVING clause to filter the groups.

    62. Interpret the output of the below query.

    SELECT SUM(AVG(LENGTH(first_name )))
    FROM employees
    GROUP BY department_id ;
    1. It calculates the sum of averages of length of employee”s name in each department.
    2. It calculates the average length of employee”s name in each department.
    3. It throws error because single row function cannot be used with group functions.
    4. It throws error because group column DEPARTMENT_ID is not used in the SELECT list.

    Answer: A. Group functions can be used with single row or general functions in the SELECT query.

    63. Up to how many levels, the group functions can be nested?

    1. 1
    2. 2
    3. 3
    4. No limits

    Answer: B. Group functions can be nested maximum up to 2 levels. However, single row functions can be nested up to any number of levels.

    64. What is the limit of number of groups within the groups created by GROUP BY clause?

    1. 1
    2. 2
    3. 3
    4. No Limit

    Answer: D. There is no limit to the number of groups and subgroups that can be formed.

    65. Choose the correct statements about the HAVING clause.

    1. The HAVING clause is an optional clause in SELECT statement.
    2. The HAVING clause is a mandatory clause if SELECT statement uses a GROUP BY clause.
    3. The HAVING clause can appear in a SELECT statement only if it uses a GROUP BY clause.
    4. The HAVING clause is a mandatory clause if SELECT statement uses a GROUP BY clause.

    Answer: A, C. HAVING clause can only appear in a query if GROUP BY clause is present, but vice versa is not true.

    66. What is the output of the below query.

    SELECT count(*) FROM dual GROUP BY dummy;
    1. 1
    2. 0
    3. NULL
    4. Throws error because group functions cannot be applied on DUAL table.

    Answer: A. The DUAL table contains single column DUMMY of type CHAR(1) whose value is ”X”.

    Based on the below scenario, answer the question from 67 to 74.

    An organization has 14 employees who work on fixed salary of 1000. The company recruits 5 new employees whose salary is not yet fixed by the payroll department. However, during the month end processing, the HR payroll department generates several reports to reconcile the financial data of the organization. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    67. What is the output of the below query?

    SELECT SUM (salary ) FROM employees ;
    1. NULL
    2. 14000
    3. 19000
    4. 0

    Answer: B. The SUM function adds the salaries of the employees.

    68. What is the output of the below query?

    SELECT AVG (salary ) FROM employees ;
    1. 1000
    2. 736.84
    3. NULL
    4. 0

    Answer: A. The AVG (salary ) function calculates the average of salaries and ignoring the NULL values. In this case, AVG(salary)=(14*1000)/14=1000.

    69. What is the output of the below query?

    SELECT AVG (nvl(salary ,0)) FROM employees ;
    1. 1000
    2. NULL
    3. 736.84
    4. 0

    Answer: C. The AVG(NVL(salary ,0)) gives an alternate value to the NULLs and enables them to participate in average calculation. In this case, (14*1000)/19 = 736.84.

    70. What is the output of the below query?

    SELECT VARIANCE (salary ) FROM employees ;
    1. 1000
    2. 0
    3. NULL
    4. 204678.36

    Answer: B. The VARIANCE (salary ) calculates the variance of salary column values ignoring NULLs.

    71. What is the output of the below query?

    SELECT VARIANCE (nvl(salary ,0)) FROM employees ;
    1. 1000
    2. 0
    3. NULL
    4. 204678.36

    Answer: D. The VARIANCE (NL(salary ,0)) calculates the variance of salary column values including NULLs.

    72. What is the output of the below query?

    SELECT STDDEV (salary ) FROM employees ;
    1. 1
    2. 1000
    3. 0
    4. NULL

    Answer: C. The STDDEV (salary ) calculates the standard deviation of salary column values ignoring NULLs.

    73. What is the output of the below query?

    SELECT STDDEV (nvl(salary ,0)) FROM employees ;
    1. 0
    2. 452.41
    3. 1000
    4. NULL

    Answer: B. The STDDEV (nvl(salary ,0)) calculates the standard deviation of salary column values including NULLs.

    74. What is the output of the below query?

    select count(*),count(salary ) from employees ;
    1. 19,19
    2. 14,19
    3. 19,14
    4. 14,14

    Answer: C. COUNT(*) includes NULLs while COUNT(salary ) ignores NULL values.

    75. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Which of the below query will give the department who have more than 5 employees working in it?

    1. SELECT department_id  FROM employees  WHERE COUNT(*) > 5 GROUP BY department_id ;
    2. SELECT department_id  FROM employees  HAVING COUNT(*) > 5;
    3. SELECT department_id  FROM employees  GROUP BY employee_id  HAVING COUNT(*) > 5;
    4. SELECT department_id  FROM employees  GROUP BY department_id  HAVING COUNT(*) > 5;

    Answer: D.

    76. Which of the following are true about the CUBE extension of GROUP BY?

    1. Enables performing multiple GROUP BY clauses with a single query.
    2. Performs aggregations for all possible combinations of columns included.
    3. Performs increasing levels of cumulative subtotals, based on the provided column list.
    4. None of the above

    Answer: B. CUBE, ROLLUP are the GROUP BY extensions used for OLAP processing. CUBE aggregates the results whenever a new permutation of column is formed.

    Use the following SELECT statement to answer below questions 77 to 82:

    1 SELECT customer#, COUNT(*)
    2 FROM customers JOIN orders USING (customer#)
    3 WHERE orderdate > ''02-APR-09''
    4 GROUP BY customer#
    5 HAVING COUNT(*) > 2;

    77. Which line of the SELECT statement is used to restrict the number of records the query processes?

    1. 1
    2. 3
    3. 4
    4. 5

    Answer: B. WHERE clause is used to restrict the rows before the groups are formed.

    78. Which line of the SELECT statement is used to restrict groups displayed in the query results?

    1. 1
    2. 3
    3. 4
    4. 5

    Answer: D. HAVING is used to restrict the group results after the group processing is over.

    79. Which line of the SELECT statement is used to group data stored in the database?

    1. 1
    2. 3
    3. 4
    4. 5

    Answer: C. GROUP BY clause uses the group by columns to group the data in the table.

    80. Which clause must be included for the query to execute successfully?

    1. 1
    2. 3
    3. 4
    4. 5

    Answer: C. Because the SELECT clause contains the CUSTOMER# column, it is mandatory to have GROUP BY clause with the CUSTOMER# column.

    81. What is the purpose of using COUNT(*) in the SELECT query?

    1. The number of records in the specified tables
    2. The number of orders placed by each customer
    3. The number of NULL values in the specified tables
    4. The number of customers who have placed an order

    Answer: B. It counts the number of rows processing under a group. In this case, group is formed by the customer and COUNT(*) counts the orders placed by each customer.

    82. Which of the following functions can be used to determine the earliest ship date for all orders recently processed by JustLee Books?

    1. COUNT function
    2. MAX function
    3. MIN function
    4. STDDEV function

    Answer: C. MIN function is used to retrieve the least value of the column. When used with date columns, it fetches the minimum date from the column.

    83. Which of the following is not a valid SELECT statement?

    1. SELECT STDDEV(retail) FROM books;
    2. SELECT AVG(SUM(retail)) FROM orders NATURAL JOIN orderitems NATURAL JOIN books GROUP BY customer#;
    3. SELECT order#, TO_CHAR(SUM(retail),''999.99'') FROM orderitems JOIN books USING (isbn) GROUP BY order#;
    4. SELECT title, VARIANCE(retail-cost) FROM books GROUP BY pubid;

    Answer: D. The GROUP BY clause must specify a column or set of columns contained in the SELECT clause. Here PUBID is not contained in the SELECT clause, hence the query is not valid.

    84. Which of the below statements are true about the nesting of group functions?

    1. The inner most function is resolved first.
    2. Oracle allows nesting of group function up to 3 levels.
    3. Single row functions can be nested with group functions.
    4. Oracle allows nesting of group function up to 2 levels.

    Answer: A, C, D. In an expression containing nested functions, the innermost function is executed first whose result is fed into the next function moving in outwards direction. Single row functions can be well used with group functions which can be maximum nested up to 2 levels.

    85. What are the statistical group functions in Oracle?

    1. AVG
    2. STDDEV
    3. VARIANCE
    4. STATS

    Answer: B, C. VARIANCE and STATS are the statistical group functions available in Oracle SQL.

    86. If the SELECT list contains a column and a group functions, which of the following clause must be mandatorily included?

    1. ORDER BY
    2. HAVING
    3. GROUP BY
    4. None of these

    Answer: C. GROUP BY clause should necessarily contain the column or set of columns contained in the SELECT clause.

    87. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    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;
    1. Salaries cannot be averaged as not all the numbers will divide evenly.
    2. You cannot use a column alias in the GROUP BY clause.
    3. The GROUP BY clause must have something to GROUP.
    4. The department id is not listed in the departments table.

    Answer: B. Neither GROUP BY clause nor HAVING clause works with column alias.

    88. Which of the following data types are compatible with AVG, SUM, VARIANCE, and STDDEV functions?

    1. Only numeric data types
    2. Integers only
    3. Any data type
    4. All except numeric

    Answer: A. The functions AVG, SUM, VARIANCE and STDDEV mandatorily work with numeric data type only.

    Examine the table structure as given below and answer the questions 89 and 90 that follow.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    89. Which of the below query will display the number of distinct job categories working in each department?

    1. SELECT department_id , COUNT(DISTINCT job) FROM employees  GROUP BY job;
    2. SELECT department_id , COUNT(job) FROM employees  GROUP BY employee_id ;
    3. SELECT department_id , COUNT(job) FROM employees  GROUP BY department_id ;
    4. SELECT department_id , COUNT(DISTINCT job) FROM employees  GROUP BY department_id ;

    Answer: D. Use DISTINCT modifier to filter out the duplicates.

    90. Evaluate this SQL statement:

    SELECT employee_id , first_name , department_id , SUM(salary )
    FROM employees
    WHERE salary  > 1000
    GROUP BY department_id , employee_id , first_name
    ORDER BY hiredate;

    Why will this statement cause an error?

    1. The HAVING clause is missing.
    2. The WHERE clause contains a syntax error.
    3. The SALARY column is NOT included in the GROUP BY clause.
    4. The HIRE_DATE column is NOT included in the GROUP BY clause.

    Answer: D. All the columns appearing in SELECT and ORDER BY clause must be included in the GROUP BY clause.

    91. Which of the following statements is true about the GROUP BY clause?

    1. To exclude rows before dividing them into groups using the GROUP BY clause, you use should a WHERE clause.
    2. You must use the HAVING clause with the GROUP BY clause.
    3. Column alias can be used in a GROUP BY clause.
    4. By default, rows are not sorted when a GROUP BY clause is used.

    Answer: A. Using a WHERE clause, you can exclude rows before dividing them into groups.

    92. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Interpret the outcome of the below query.

    SELECT department_id , MIN (hiredate)
    FROM employees
    GROUP by department_id ;
    1. The earliest hire date in the organization.
    2. The latest hire date in the organization.
    3. The earliest hire date in a department.
    4. The latest hire date in a department.

    Answer: C. The query returns the earliest hired employee in each department.

    93. Which statement about group functions is true?

    1. Group functions except COUNT(*), ignore null values.
    2. A query that includes a group function in the SELECT list must include a GROUP BY clause.
    3. Group functions can be used in a WHERE clause.
    4. Group functions can only be used in a SELECT list.

    Answer: A. All the group functions except COUNT(*), ignore NULL values. It is because they process the values directly contained in a specific column.

    94. Which of the following clauses represent valid uses of group functions?

    1. GROUP BY MAX(salary)
    2. ORDER BY AVG(salary)
    3. HAVING MAX(salary) > 10000
    4. SELECT AVG(NVL(salary, 0))

    Answer: B, C, D. Group functions can appear in SELECT, HAVING and ORDER BY clauses only.

    95. Which of the following statements are true about the GROUP BY clause?

    1. The last column listed in the GROUP BY clause is the most major grouping.
    2. The first column listed in the GROUP BY clause is the most major grouping.
    3. A GROUP BY clause cannot be used without an ORDER BY clause.
    4. The GROUP BY clause do not ensure the sorting of output.

    Answer: B. The grouping of data is based on the sequence of columns appearing in the GROUP BY clause.

    96. What is difference between WHERE clause and HAVING clause?

    1. WHERE clause restrict rows before grouping while HAVING clause restricts groups.
    2. WHERE clause cannot contain a group function but HAVING clause can have.
    3. WHERE clause can join multiple conditions using AND or OR operators but HAVING clause cannot.
    4. WHERE clause can appear in SELECT query without GROUP BY clause but HAVING clause cannot.

    Answer: A, B, D. WHERE clause restricts the rows before grouping but HAVING restricts the groups.

    97. Examine the table structure as given.

    SQL> DESC employees
     Name			 Null?	  Type
     ----------------------- -------- ----------------
     EMPLOYEE_ID		 NOT NULL NUMBER(6)
     FIRST_NAME			  VARCHAR2(20)
     LAST_NAME		 NOT NULL VARCHAR2(25)
     EMAIL			 NOT NULL VARCHAR2(25)
     PHONE_NUMBER			  VARCHAR2(20)
     HIRE_DATE		 NOT NULL DATE
     JOB_ID 		 NOT NULL VARCHAR2(10)
     SALARY 			  NUMBER(8,2)
     COMMISSION_PCT 		  NUMBER(2,2)
     MANAGER_ID			  NUMBER(6)
     DEPARTMENT_ID			  NUMBER(4)

    Predict the outcome of the below query.

    SELECT department_id ,job,count(*)
    FROM employees
    GROUP BY department_id ,job
    ORDER BY department_id ,count(*);
    1. It executes successfully.
    2. It throws error because ORDER BY clause is invalid.
    3. It throws error because GROUP BY clause is invalid.
    4. It throws error because GROUP BY and ORDER BY clause cannot be used together.

    Answer: A. ORDER BY clause can use the group functions for sorting.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc