Creating Other Schema Objects

Advertisements


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

  • Rows

  • Views

  • 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?
  • Synonyms

  • Views

  • Tables

  • 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?
  • They are equal to tables

  • They store data from one or many tables

  • We can execute SELECT and other DMLs on Simple views

  • 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)
  • Because they have shorter names than tables

  • To prevent users from accessing the columns of tables

  • To simplify user SQL

  • 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?
  • View contains GROUP BY clause

  • Base tables contain NOT NULL columns but not selected in the view query

  • View query uses ROWNUM pseudocolumn

  • 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?
  • Tables from the same schema

  • Tables from different schema

  • Both A and B

  • 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;
  • 0

  • 1

  • 2

  • 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?
  • SELECT E.*, dept_name
    FROM departments D join emp_details E
    ON (E.department_id= D.dept_id);
  • SELECT hire_date, job, salary, dept_name FROM emp_details
  • This is not possible a view cannot be joined to other tables

  • 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?
  • Select dept_name, e.salary
    FROM departments D join emp_details E
    On (E.department_id= D.dept_id);
  • Select dept_name, max(salary)
    FROM departments D join emp_details E
    On (E.department_id= D.dept_id)
    Group by dept_name;
  • View cannot appear in queries using group functions

  • 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?
  • PUBLIC and PRIVATE synonyms can have the same name for the same table

  • DROP SYNONYM will remove a synonym

  • DROP PUBLIC SYNONYM can be executed only by a SYSDBA

  • 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 answer0
  • A view can only be created from a table

  • A view can only be created from one table

  • A view can be created from one or many tables or views

  • 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?
  • CREATE TABLE system privilege

  • CREATE VIEW system privilege

  • ALTER VIEW system privilege

  • 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?
  • CREATE ANY VIEW

  • CREATE VIEW

  • Both A and B

  • 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?
  • LOBs

  • Object types

  • REF data types

  • All of the above

Answer: D.
15. What among the following are different types of Views?
  • Simple views

  • Complex views

  • Both A and B

  • 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?
  • DML statements can be issued most of the times against simple views

  • There is only one source base table

  • No group functions are used

  • 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?
  • DML statements cannot be issued against complex views

  • Contain multiple base tables

  • Aggregations cannot be performed

  • 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?
  • CREATE VIEW

  • REPLACE VIEW

  • CREATE OR REPLACE VIEW

  • 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?
  • As a WHERE clause

  • As a CREATE statement

  • As an UPDATE statement

  • As a SELECT statement

Answer: D.
20. Which of the following can contain single-row functions?
  • Inline Views

  • Simple Views

  • Complex Views

  • 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?
  • Composite View

  • Simple View

  • Complex View

  • 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?
  • Sub-queries can be embedded in a CREATE VIEW statement

  • A sub-query used in the CREATE VIEW statement has to have a simple SELECT syntax

  • You cannot use a WHERE clause in a sub-query when it is used in the CREATE VIEW statement

  • 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?
  • NOFORCE

  • FORCE

  • OR REPLACE

  • 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?
  • NOFORCE

  • FORCE

  • WITH READ ONLY

  • 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?
  • It creates a view even if the base table(s) does not exist.

  • It creates a view only if the base table(s) exists.

  • It is the default while creating a view.

  • 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?
  • Object privileges are lost when a view is created using this keyword

  • There is no need of re granting the object privileges previously granted on it

  • Neither of A nor B

  • 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; 
  • The view has to be accessed by the original column names defined in the base table

  • The view has to be accessed by the aliases given in the view query

  • View is a simple view

  • 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; 
  • It is not mandatory that the number of aliases match the no. of expressions in the sub-query

  • It is mandatory that the no. of aliases listed must match the no. of expressions selected in the sub-query

  • It is mandatory to give aliases while creating a view

  • 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?
  • Column aliases are listed in a random order as the columns in the sub-query

  • Column aliases are listed in the same order as the columns in the sub-query

  • Column aliases are mandatory while using the CREATE OR REPLACE keyword

  • 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?
  • Alternative names have been given for the view

  • Giving alternative names is mandatory if any column is derived from a function or an expression

  • Both A and B

  • 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; 
  • It will be no different than the original statement

  • It will execute successfully giving the same results but change in alias names.

  • It will throw an ORA error

  • 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; 
  • It will delete the view

  • It will remove all the rows from the view but the structure of the view will remain the same

  • It will throw an ORA error

  • 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?
  • The view can be updated to update the values in EMPLOYEES and DEPARTMENTS tables

  • Data in EMPLOYEES and DEPARTMENTS tables cannot be deleted through view

  • Data in EMPLOYEES and DEPARTMENTS tables can be inserted through view

  • 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?
  • The rows will get removed without any error

  • Only the first 10 rows will get removed

  • The rows cannot be deleted.

  • 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?
  • Deletion of rows through a view is not possible

  • It should be a simple view

  • It should be a complex view

  • 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?
  • When there are group expressions

  • When there is a GROUP BY clause

  • When ROWNUM is used in the view query

  • 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; 
  • Andy issues -
    CREATE SYNONYM EMP_JOBS for JOB_HISTORY
  • HR issues -
    CREATE SYNONYM EMP_JOBS for andy.JOB_HISTORY
  • HR issues -
    CREATE PUBLIC SYNONYM EMP_JOBS FOR andy.JOB_HISTORY
  • 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?
  • OR REPLACE

  • CREATE

  • WITH CHECK OPTION

  • 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?
  • It will allow the users to perform INSERT or UPDATE on all departments

  • It will allow the user to perform INSERT or UPDATE any row which has department 100

  • The user can UPDATE any row in the employees table

  • 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?
  • No rows are updated

  • An ORA error is thrown

  • Both A and B

  • 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?
  • INSERTs or UPDATEs performed through the view cannot create rows that the view cannot select

  • Only INSERTs performed through the view cannot create rows that the view cannot select

  • Only UPDATEs performed through the view cannot create rows that the view cannot select

  • None of the above

Answer: A.
42. How can you prevent DML operations on a View?
  • By defining a WITH CHECK OPTION constraint

  • By defining a WITH READ ONLY option

  • Neither of A nor B

  • 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?
  • The view will not be created

  • INSERT operation on this view an will throw an ORA error

  • On UPDATING the rows for all the employees in department 100, an ORA error will be thrown

  • 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?
  • All rows of the view

  • All the rows of only the department 100

  • No rows

  • 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?
  • DROP READ ONLY VIEW empvu100;
  • DROP NOFORCE empvu100;
  • DROP VIEW empvu100;
  • 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?
  • The columns in the view from the base tables are also dropped

  • The definition of the view is removed from the database

  • Dropping of a view has no effect on the underlying base table

  • None of the above

Answer: B, C.
47. Which of the following privileges should a user have to drop a view?
  • CREATE ANY VIEW

  • CREATE VIEW

  • DROP ANY VIEW

  • DROP VIEW

Answer: C.
48. What is true about sequences?
  • It generates integers

  • It is a shareable object

  • Can be used to create a PRIMARY KEY value

  • 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?
  • It is created when the Oracle Database is installed

  • It is created by a user who has CREATE SEQUENCE system privilege

  • It cannot be shared by more than two users

  • 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?
  • The integers generated through a sequence for one table cannot be used by other tables

  • A sequence can only be incremented

  • A sequence becomes invalid if another sequence generates the same integers

  • 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

  • 100

  • 101

  • 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?
  • 0

  • 100

  • 101

  • 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?
  • 102

  • 100

  • 99

  • 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?
  • 101

  • No value

  • It will throw an ORA error

  • 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?
  • 20

  • 0

  • 100

  • 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?
  • 200

  • 101

  • 9999

  • 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?
  • 200

  • 101

  • 9999

  • 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?
  • ALTER dept_deptid_seq
    INCREMENT BY 100
    START WITH 1000
    MAXVALUE 9999
    NOCACHE
    NOCYCLE; 
  • The sequence has to be dropped and re-created to start the sequence from 1000.

  • ALTER SEQUENCE dept_deptid_seq
    START WITH 101
  • 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?
  • ORA error

  • The maximum value for the altered sequence will now be 99

  • Neither of A nor B

  • 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?
  • If we want to purge the old rows faster

  • If we do not want to use the sequence to generate PRIMARY KEY values

  • Both A and B

  • 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?
  • It re-generates the CURRVAL of a sequence

  • It returns the next available sequence value

  • It can return duplicate values

  • 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?
  • CURRVAL can be used before NEXTVAL with respect to a sequence

  • CURRVAL gives the current value of a sequence

  • CURRVAL can give duplicate values

  • None of the above

Answer: B.
63. When can NEXTVAL and CURRVAL be used?
  • SET clause of an INSERT statement

  • VALUES clause of an UPDATE statement

  • The SELECT list of a SELECT statement that is not part of a sub-query

  • 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?
  • The SELECT list of a view

  • The SELECT statement with the DISTINCT keyword

  • A sub-query in SELECT, DELETE or UPDATE statement

  • 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)
  • Table will be created

  • The department_id column will have the values from the sequence generated for the employee ID

  • The department_id column will have a DEFAULT value

  • 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)
  • Table will be created

  • The department_id column will have the values from the sequence generated for the employee ID

  • The department_id column will have a DEFAULT value

  • 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?
  • INSERT INTO departments (dept_id, dept_name, location_id)
    VALUES (dept_deptid_seq.NEXTVAL, 'HR', 1000); 
  • INSERT INTO departments (dept_id, dept_name, location_id)
    VALUES (dept_deptid_seq.NEXTVAL, "HR", 1000); 
  • INSERT INTO departments (dept_id, dept_name, location_id)
    VALUES (dept_deptid_seq.CURRVAL, 'HR', 1000); 
  • 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; 
  • ORA error

  • It will give the current value of the sequence

  • Neither of A nor B

  • 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?
  • When a rollback occurs

  • The system crashes

  • A sequence is used in another table

  • All of the above

Answer: D.
70. What is true about caching sequence values?
  • Caching sequence values is not possible in Oracle

  • The cache is populated when the maximum limit of the sequence is reached

  • Caching starts the first time when the sequence is referred

  • 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?
  • The sequence value at the starting of employee transaction

  • NULL

  • The sequence value at the end of employee transaction

  • 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?
  • CREATE OR REPLACE privilege

  • ALTER privilege for the sequence

  • ALTER TABLE privilege

  • 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?
  • The existing integers already generated by the sequence are altered as well

  • Only the future integers are affected

  • The sequence stops caching the future integers

  • 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?
  • ALTER SEQUENCE sequence_name START WITH NULL;
  • DROP sequence_name;
  • DROP SEQUENCE sequence_name;
  • 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)
  • ALTER SEQUENCE

  • ALTER TABLE

  • DROP SEQUENCE

  • 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?
  • Indexes are only manually created

  • Indexes are only automatically created

  • Both A and B

  • 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?
  • ROWNUM

  • ROWID

  • Sequence

  • 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?
  • The data is located quickly

  • There is a full table scan

  • The table cannot be created

  • The table cannot be altered

Answer: B.
79. What among the following is true about an Index?
  • Index reduces the disk I/O

  • Index locates data quickly

  • Indexes are logically and physically independent of the table that they index

  • All of the above

Answer: D.
80. What will happen if an index is dropped?
  • The column on which the index is created, is dropped too

  • The table on which the index is created, is dropped too

  • Indexes once created cannot be dropped

  • 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?
  • The indexes still remain as they are logically and independent objects

  • The indexes in the table are also dropped

  • Neither of A nor B

  • None of the above

Answer: B.
82. How are indexes created automatically?
  • When we create a table

  • When a table is altered

  • When a PRIMARY KEY is defined on a column (or group of columns) of a table

  • 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?
  • Tables and views only

  • Table, view and sequence

  • Stored procedure, function, or package

  • 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?
  • INDEX

  • TABLE

  • SYNONYMS

  • 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?
  • PRIMARY KEY

  • UNIQUE KEY

  • FOREIGN KEY

  • None of the above

Answer: C.
86. Which of the following is the main and basic type of an Index?
  • Bitmap

  • B-tree

  • Unique

  • 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)
  • CREATE INDEX emp_first_name_idx 
    ON employees (first_name); 
  • CREATE INDEX emp_first_name_idx 
    ON employees first_name; 
  • ALTER INDEX emp_first_name_idx 
    ON employees (first_name); 
  • None of the above

Answer: A.
88. What does the UNIQUE keyword do while creating indexes?
  • It specifies that the value of the column(s) upon which the index is created must be unique

  • You cannot use the UNIQUE keyword when creating indexes

  • It specifies that the index that is created can be used only by one table

  • 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?
  • It creates the index with a bitmap for each distinct key.

  • It does not create the index on each row separately

  • Both A and B

  • 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)
  • Indexes

  • UNION set operator

  • MINUS set operator

  • 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?
  • If the table(s) is very large

  • If a column has less values

  • If a column contains a large number of NULL values

  • 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)
  • Indexes should not be created if a table is updated frequently

  • Indexes should be created at the time when the table is created

  • Neither of A nor B

  • 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?
  • Yes

  • No

  • It might help

  • 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?
  • DELETE FROM index_name; 
  • DROP INDEX index_name; 
  • DROP INDEX;
  • None of the above

Answer: B. You must have the DROP ANY INDEX privilege to drop an index.


Advertisements
Advertisements