Vous êtes sur la page 1sur 30

MANIPULATING DATA

http://www.tuto rialspo int.co m/sql_ce rtificate /manipulating _data_que stio ns.htm Co pyrig ht © tuto rials po int.co m

1. What does ACID mean with respect to relational database?

Accuracy, Consistency, Isolation, Database

Accuracy, Concurrency, Isolation, Durability

Atomicity, Consistency, Isolation, Durability

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. T here 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 chang es made by committed transactions are permanent. After a transaction
completes, the database ensures throug h its recovery mechanisms that chang es from the transaction are not
lost.

2. What does the word DML stands for in Oracle SQL?

Durability Manag ement Lang uag e

Database Manag ement Lang uag e

Database Manipulation Lang uag e

None of the above

Answer: C. DML stands for Data Manipulation Lang uag e.

3. Which of the following are DML commands in Oracle Database?

SELECT

GROUP BY

INT ERSECT

INSERT

Answer: A, D. On strict g rounds, 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 UPDAT E in a sing le
statement?

INT ERSECT

INSERT

SELECT

MERGE

Answer: D. MERGE can perform INSERT and UPDAT E actions in a sing le statement in Oracle.

5. What all operations can MERGE statement perform in SQL?

INSERT

DELET E
GROUP BY

None of the above

Answer: A, B. In some conditions MERGE can perform the DELET E operation too, along with INSERT and
UPDAT E.

6.Which of following commands is a DDL (Data Definition Lang uag e) command but is often considered along
with DML commands?

DELET E

INSERT

T RUNCAT E

None of the above

Answer: C. T RUNCAT E is a DDL command. It removes the records from the table without any condition. It is
not the part of any ong oing transaction and an uncommitted transaction in the session is committed after
T RUNCAT E is executed.

7.Which of the following commands manipulate data basically?

MINUS

UPDAT E

T RUNCAT E

All of the above

Answer: B, C. UPDAT E is a DML statement to modify a column value in a table. T RUNCAT E manipulates the
data by removing them unconditionally from a table.

8. Which of the following commands is used to populate table rows with data?

DELET E

INSERT

SELECT

UPDAT E

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)

It can insert data in one row of one table at a time

It can insert data in many rows of one table at a time

It can insert data in many rows of many tables at a time

All of the above

Answer: C. T he INSERT statement is capable of inserting a row or set of rows in a sing le table at a time.

10.What is true about the insertion of rows in tables?

T he rows can be inserted randomly

Any number of rows can be inserted in a table without any restrictions

Generally the rows are inserted in a table based on certain rules known as constraints
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. T hese 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)

An INSERT statement can override any constraint put on the table

An INSERT statement cannot be used on a table if a constraint is already placed on the table

An INSERT statement can be used on a table only if a constraint is already placed on the table

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 EMPLO YEES table along with its struc ture 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

INSERT INTO EMPLOYEES (employee_id , first_name , job_id) VALUES (5100, 'BRUCE', 'CLERK');

Assuming that there is a duplic ate value c hec k c onstraint on the EMPLO YEE_ID c olumn,
what will be the outc ome of the above statement?

It will insert another row with 5 100 BRUCE CLERK values

It will insert another row with 5 1002 BRUCE CLERK values

It will throw a 'Constraint violated' O RA error

None of the above

INSERT INTO EMPLOYEES (employee_id , first_name , job_id) VALUES (51003,'BRUCE','CLERK');

What will be the output of this statement?

It will insert a new row with 5 1003 BRUCE CLERK values

It will throw an O RA error as there c annot be another BRUCE who is a CLERK

It will throw an 'Constraint violated' O RA error

None of the above

Answer: A. As there is no c onstraint on the c olumns FIRST _NAME and job_id, the INSERT
will work without any error
INSERT INTO EMPLOYEES (employee_id , first_name , job_id ) VALUES (51003,'BRUCE', NULL);

What will be the output of this statement?

It will insert a new row with 5 1003 BRUCE CLERK values

It will throw an O RA error as there c annot be another BRUCE who is a CLERK

It will throw an 'Constraint violated' O RA error

It will insert a new row with 5 1003 BRUCE NULL values

Answer: D. As there is no NO T NULL c onstraint on the c olumns FIRST _NAME and J O B_ID
, the NULL value will g et inserted.

15 . What among the following c an be said reg arding inserting of rows in tables?

T he user c annot interac tively insert rows

A query c an be written with substitution variables for an interac tive insertion of rows
by the users

When a user is prompted for inserting rows, the insert doesn't work and it throws an
O RA error

None of the above

Answer: B. An INSERT statement c an make use of substitution variable to prompt the user
to key in values during the runtime. It provides an interac tive way of inserting data into
tables.

16.Whic h of the following c an be used to insert rows in tables?

SELECT

INSERT

Sub-queries

All of the above

Answer: D. INSERT statement c an make use of explic it INSERT , INSERT -SELECT or a


sub-query method to insert data into tables.

17. Whic h among the following is a c ommon tec hnique for inserting rows into a table?
(Choose the most sensible and appropriate answer)

Using SELECT c lause

Manually typing eac h value into the INSERT c lause

Using SET operators

None of the above

Answer: A. Using the SELECT c lause is the most c ommon tec hnique for inserting rows into
tables. It reduc es the effort of manually keying in values for eac h c olumn.

18.Whic h of the following c ommands is used to c hang e the rows that already exist in a table?

INSERT

UNIO N

UPDAT E

SELECT
Answer: C. UPDAT E is a DML statement whic h is used to modify the c olumn values in a
table.

19.What is true about the UPDAT E c ommand?

It c an update only one row at a time

It c an update only 100 rows at a time

It c an update unlimited rows at a time in bulk

None of the above

Answer: C. An UPDAT E c an update multiple rows in one or more rows at a time based on
the WHERE c lause c onditions.

20.Whic h of the following c lauses dec ides how many rows are to be updated?

SELECT

WHERE

FRO M

All of the above

Answer: B. UPDAT E statement makes use of WHERE c lause to c apture the set of rows
whic h needs to be updated.

21.What among the following is true about the UPDAT E statement? (Choose the most
appropriate answer)

An UPDAT E c an update rows from only one table

An UPDAT E c an update rows from multiple tables

A sing le UPDAT E c ommand c annot affec t rows in multiple tables

None of the above

Answer: A, C. An UPDAT E statement affec ts rows of only one table and not multiple tables.
Consider the following data set from the EMPLO YEES table and its struc ture. 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 c hang e the J O B_ID for Bruc e (Employee Id 7389) to 'ACCO UNT ANT '.
Whic h of the following statements will you fire?
UPDATE employees
SET job_id = 'ACCOUNTANT'
WHERE employee_id = 7389;

INSERT INTO EMPLOYEES (employee_id , first_name , job_id ) VALUES (5100,'BRUCE',


'ACCOUNTANT');

UPDATE employees
SET job_id = 'ACCOUNTANT'
WHERE job_id = 'CLERK';

UPDATE employees
SET job_id = 'ACCOUNTANT';

Answer: A. O ption B fails bec ause it modifies the job c ode of all c lerks to ACCO UNT ANT .
O ption C is wrong bec ause it update job c ode to ACCO UNT ANT for all the employees in the
table.
Answer the following questions 23 and 24 based on the below ac tions -
You issue the following query to the EMPLO YEES table with the data set as shown above.
UPDATE employees
Set job_id = NULL
Where employee_id = 51000;

EMPLOYEE_ID FIRST_NAME JOB_ID


------------------- ------------------ --------
5100 BRUCE
5101 JESSICA SALESMAN
5102 DEBBY SALESMAN

23. Suppose you fire an UPDAT E statement to update Bruc e's J O B_ID to 'SALESMAN'
(with respec t to the data set shown above). What will be the outc ome of the query?

Bruc e's job c ode will still be NULL

Bruc e's job c ode will be modified to 'SALESMAN'

O RA error

No ac tion

Answer: B. T he UPDAT E will add the new value to the NULL value c hang ing the NULL to the
new value

24. You issue an UPDAT E statement to update the employee id 7389 to 7900. You query the
employee by its id '7389' before c ommitting the transac tion. What will be the outc ome?

Update will work suc c essfully while selec t will show 7389.

Update will work suc c essfully while selec t will show no rec ords.

Constraint on EMPLO YEE_ID will not allow it to be updated

It will update suc c essfully but all the values for the EMPLO YEE_ID 7389 will bec ome
NULL.

Answer: B. A query in a session is c onsistent with the ong oing transac tions. If the same
query would have been exec uted in a different session, it would have shown the employee
rec ord with id 7389 bec ause the ac tive transac tion in the first session is not yet c ommitted.

25 . What among the following is a typic al use of an UPDAT E statement? (Selec t the most
appropriate answer)

T o retrieve a row and update one of more c olumns of that row


T o modify all the rows for some c olumns

T o modify all the rows for all the c olumns of a table

None of the above

Answer: A. Althoug h, the UPDAT E statement c an modify all c olumn values in all rows, but
typic ally it is used to selec t a row and update one or more c olumns.

26. Whic h of the following prac tic es appropriately desc ribe for selec ting whic h row set to
update using the UPDAT E statement?

If some rows are to be updated, PRIMARY KEY c onstraint c an be used

If all rows are to be updated, WHERE c lause c an be c onsidered

T o update a set of rows use WHERE, to update all rows of a table, put a PRIMARY
KEY c onstraint on the table

None of the above

Answer: C.

27. Whic h of the following c olumns in a table are not usually updated?

LO NG type c olumns in the table

LO B c olumns in the table

A primary key c olumn whic h also serves as foreig n key referenc e in another table

All of the above

Answer: C. As a c ommon prac tic e, the primary key c olumns whic h serve as foreig n key
referenc e in other tables, should not be updated. T houg h they c an be updated by deferring
the c onstraints whic h is usually not rec ommended.
Consider the following data set and struc ture of the EMPLO YEES 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

UPDATE employees
SET job_id = NULL;

What will be the outc ome of the above statement?

T he first row of the data set will g et updated to NULL

T he 3rd c olumn of the first row will g et updated to NULL


T he 3rd c olumn of all the rows will g et updated to NULL

And O RA error will be thrown

Answer: C. An UPDAT E statement without a WHERE c lause will update all the rows of the
table.

UPDATE employees
SET employee_id = NULL;
WHERE job_id = 'CLERK';

What will be the outc ome of the above statement? (Here the c olumn EMPLO YEE_ID is
marked as mandatory by putting a c onstraint)

T he first c olumn of the data set will g et updated to NULL

T he 3rd c olumn of the first row will g et updated to NULL

T he 3rd c olumn of all the rows will g et updated to NULL

And O RA error will be thrown

Answer: D. T he c onstraints on the c olumn must be obeyed while updating its value. In the
g iven UPDAT E statement, error will be thrown bec ause the EMPLO YEE_ID c olumn is a
primary key in the EMPLO YEES table whic h means it c annot be NULL.

30. Whic h of the following c ommands c an be used to remove existing rec ords from a table?

UPDAT E

INSERT

MINUS

DELET E

Answer: D. DELET E is used to remove the rec ords from the table whic h c an be optionally
based upon a c ondition. Being a DML statement, it is the part of a transac tion.

31. What among the following is true about the DELET E statement?

T he DELET E statement has to be ac c ompanied by the WHERE c lause

It is not mandatory to write a WHERE c lause with the DELET E statement

DELET E c an remove data from multiple tables at a time

None of the above

Answer: B. T he WHERE c lause predic ate is optional in DELET E statement. If the WHERE
c lause is omitted, all the rows of the table will be deleted.

32.What among the following happens when we issue a DELET E statement on a table?
(Choose the most appropriate answer)

A prompt pops up asking the user whether he/she is sure of deleting the rows
requested

T he rows obeying the c ondition g iven in the DELET E statement are removed
immediately

T he requested rows are removed immediately without any prompt.

None of the above

Answer: C. As a part of the ac tive or a new transac tion, the rows in the table will be deleted.
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 J O B_ID c olumn in the row with employee_id 5 1001.
Whic h of the following queries will be c orrec t?

UPDATE employees
SET job_id = NULL
WHERE employee_id = 51001;

DELETE job_id FROM employees


WHERE employee_id = 51001;

DELETE FROM employees;

None of the above

Answer: D. You c annot delete a partic ular c olumn value for a partic ular row with the
DELET E statement. T he entire row g ets deleted based on the c onditions g iven. Unwanted
values in a c olumn c an be updated to NULL. O ption 'A' is near but not c orrec t in the c ontext
of the question.

34. What is the differenc e between the UPSERT and MERGE statements?

T here is no differenc e

UPSERT is the latest term adopted for MERGE statement, whic h has turned obsolete

UPSERT c an perform delete operation whic h MERGE c annot

MERGE does INSERT , UPDAT E and DELET E, UPSERT does only UPDAT E and
INSERT

Answer: D. UPSERT is an obsolete statement and MERGE took over with new c apabilities.

35 . What is the differenc e between the MERGE c ommand and the c ommands INSERT ,
UPDAT E and DELET E?

MERGE statement c onsumes more time than eac h operation (INSERT , UPDAT E,
DELET E) done separately

MERGE is obsolete after O rac le 10g

MERGE c an perform all three operations on a table while INSERT , UPDAT E and
DELET E perform one operation at a time.

None of the above.


Answer: C. T he MERGE statement c an embed all three operations on a table in a sing le
statement while INSERT , UPDAT E and DELET E perform one operation at a time.

36. Whic h of the following objec ts c an be the data sourc e in a MERGE statement?

A table only

A sub-query only

A table or a sub-query

Both A or B

Answer: C. MERGE works well with a table or a subquery.

37. What among the following is a T RUNCAT E statement equivalent to? (Choose the most
suitable answer)

T o a DELET E statement

T o an UPDAT E statement

A DELET E statement without a WHERE c lause

None of the above

Answer: C. T RUNCAT E deletes all the rows in one c ommand.

38.Whic h of the following situations indic ate that a DML operation has taken plac e?

When new rows are added to a table

When two queries are c ombined

When a table is trunc ated

None of the above

Answer: A. When existing rows in a table are inserted, modified or removed from a table, it
is done throug h a DML statement.

39.Whic h of the following best defines a transac tion?

A transac tion c onsists of DDL statements on the database sc hema

A transac tion c onsists of CO MMIT or RO LLBACK in a database session

A transac tion c onsists of either a c ollec tion of DML statements or a DDL or DCL or
T CL statement to form a log ic al unit of work in a database session

A transac tion c onsists of c ollec tion of DML and DDL statements in different sessions
of the database

Answer: C. A database transac tion c onsists of one or more DML statements to c onstitute
one c onsistent c hang e in data, or a DDL statement or a DCL c ommand (GRANT or
REVO KE). It starts with the first DML statement and ends with a DCL or DDL or T CL
(CO MMIT or RO LLBACK) c ommand. Note that DDL and DCL c ommands hold auto c ommit
feature.

40. What does a c ollec tion of DML statements that form a log ic al unit work known as?

ACID property

UNIO N

UNIO N ALL
T ransac tion

Answer: D.

41.What happens when a DML statement in an ac tive transac tion enc ounters an error on
exec ution?

T he c omplete transac tions is rolled bac k

T he DMLs in the transac tion are mutually exc lusive and henc e c an c ontinue their
exec ution

T he other DMLs in the transac tions are interrupted and wait until the error is resolved

None of the above

Answer: A. If any of the DML statement in an ac tive transac tion enc ounters error, the whole
transac tion ends up in a rollbac k.

42.What is true about the keyword VALUES in INSERT statements?

VALUES c an add multiple rows at a time during the INSERT

VALUES c an add only 100 rows at a time during the INSERT

VALUES is mandatory to be used if we use the keyword INSERT

VALUES add only one row at a time

Answer: D. T he VALUES keyword is used only when the c olumn values are explic itly
spec ified in the INSERT statement.
Consider the following statement and the table struc ture. 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?

Answer: D. When the keyword VALUES is used, it inserts only one row at a time.

44. In whic h order the values will g et inserted with respec t to the above INSERT statement?

Loc ation_id , manag er_id, department_name , department_id

department_id , department_name , manag er_id, loc ation_id

department_id , manag er_id, department_name , loc ation_id

department_id , department_name , loc ation_id , manag er_id

Answer: B. If the c olumns are mentioned in the INSERT c lause, the VALUES keyword
should c ontain values in the same order

INSERT INTO departments VALUES (100, 'Human Resources', 121, 1000);

What will be the outc ome of this modific ation? Assume that the DEPART MENT S table has
four c olumns namely, department_id ,DEPART MENT _NAME ,MANAGER_ID and
LO CAT IO N_ID .

It will insert values into all the c olumns of the departments table assuming that c olumn
values are provided in the same sequenc e as the c olumn in the table

It will throw an O RA error bec ause c olumn names are not explic itly mentioned

It will throw an O RA error bec ause VALUES c lause is wrong ly used in the INSERT

None of the above

Answer: A. Inc luding the c olumn names in the INSERT statement is optional provided the
values must c omply with the c ount and sequenc e of the c olumns in the table.

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");

It will insert only the employee_id and the hire date of the employee, leaving all other
c olumns as blanks

It will insert only the employee_id

It will throw an O RA error

None of the above

Answer: C. T he date literal formatting c ontains error. It should be enc losed within sing le
quotation marks and not double quotation marks.

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");


It will insert only the employee_id and the first name of Bryan, leaving all other
c olumns as blanks

It will insert only the first name

It will throw an O RA error

None of the above

Answer: C. T he string literal formatting c ontains error. It should be enc losed within sing le
quotation marks and not double quotation marks.

48. Suppose you need to insert the name O 'Callag han as the last name of the employees
table. Whic h of the following queries will g ive you the required results? (Consider the g iven
table struc ture)
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 , last_name) VALUES (210,'O'callahan');

INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,'O"callahan');

INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,'O' 'Callahan');

INSERT INTO EMPLOYEES (employee_id , last_name) VALUES (210,"O'callahan");

Answer: C.

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');

It will throw a numeric value error

It will insert only the employee_id and the first name of Bryan, leaving all other
c olumns as NULL

It will insert only the employee_id

None of the above


Answer: A. Number values should not be enc losed within quotes.

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);

It will throw an O RA error

It will exec ute suc c essfully but with wrong values mig ht g et inserted in the c olumns

It will exec ute suc c essfully

None of the above

Answer: C. NULLs c an be used in the VALUES c lause to fill up the c olumn values
alternatively.

5 1. What will be the outc ome of the below INSERT statement? (Assume there is a NO T
NULL c onstraint on the department_id c olumn and c onsider the table struc ture
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);

It will throw an O RA error

It will exec ute suc c essfully but with wrong results

It will exec ute suc c essfully but with c orrec t results

None of the above

Answer: A. NULL values c annot be inserted into non null c olumns.

5 2. What will be the outc ome of the below INSERT statement? (Assume there is a NO T
NULL c onstraint on the department_id c olumn and c onsider the g iven table
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);

It will exec ute suc c essfully but with wrong results


It will throw an O RA error

It will exec ute suc c essfully but with c orrec t results

None of the above

Answer: B. Data type of the value mismatc hes with the data type of the c olumn in the table.

5 3. Whic h of the following c ommands is used to save the c hang ed data in a table
permanently?

RO LLBACK

CO MMIT

INSERT

UPDAT E

Answer: B. T he T CL c ommand CO MMIT is used to end the c urrent ac tive transac tion in a
session by making all the pending data c hang es permanent in the tables.

5 4. Whic h of the following c ommands allows undoing the c hang ed data?

RO LLBACK

CO MMIT

INSERT

UPDAT E

Answer: A. T he T CL c ommand RO LLBACK is used to end the c urrent ac tive transac tion in a
session by disc arding all the pending data c hang es.

5 5 . Whic h of the following c ommands allows enabling markers in an ac tive transac tion?

RO LLBACK

CO MMIT

SAVEPO INT

None of the above

Answer: C. SAVEPO INT marks a point in a transac tion whic h divides the transac tion into
smaller sec tions.

5 6. Whic h of the following c ommands prevents other users from making c hang es to a table?

RO LLBACK

CO MMIT

LO CK T ABLE

SAVEPO INT

Answer: C.

5 7. What is true about an INSERT statement whic h tries to insert values into a virtual
c olumn? (Choose the most appropriate answer)

It c annot insert values in the Virtual c olumn

It c an insert values
It throws an O RA error

All of the above

Answer: A. A Virtual c olumn is a c olumn whic h is always auto g enerated based on the
derivation expression defined in the c olumn spec ific ation. Its value c annot be explic itly
inserted by the user.

5 8.Whic h of the following c ommands allows the user to insert multiple rows with a sing le
statement?

INSERT

INSERT ALL

UNIO N ALL

None of the above

Answer: B. Bulk insert operations c an be c arried out using INSERT ALL.

5 9. Whic h of the following is the syntax for inserting rows throug h a sub-query?

INSERT INTO tablename [{column_name,..}]


subquery;

INSERT INTO tablename VALUES [{column_name,..}]


subquery;

Both A and B

None of the above

Answer: A.
Consider the following exhibit of the EMPLO YEES 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. Whic h of the following queries will exec ute suc c essfully?

UPDATE employees
SET salary = salary + 1000
WHERE to_char (hire_date, 'YYYY') > '2006';

UPDATE employees
SET salary = salary + 1000
WHERE to_date (hire_date, 'YYYY') > '2006';

UPDATE employees
SET salary = salary + 1000
WHERE hire_date > to_date (substr ('01-jan-200',8));
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 struc tural reorg anization in the org anization, you are asked to update department
IDs for all the employees to NULL before the final dec ision is made public . O nly those
rec ords should be updated whic h have the J O B_ID as NULL. Whic h of the following
queries will work?

UPDATE employees
SET department_id = NULL
Where job_id = NULL;

UPDATE employees
SET department_id = NULL
Where job_id = TO_NUMBER(NULL);

UPDATE employees
SET department_id = NULL
Where job_id IS NULL;

UPDATE employees
SET department_id = TO_NUMBER (' ', 9999)
Where job_id = TO_NUMBER(NULL);

Answer: C. Use IS NULL operator to c hec k c olumn value for nullity.

62.You need to add a basic employee data into EMPLO YEES table. T he basic data c ontains
the last name as 'Bond' and department ID as 300. Whic h of the following statements will
g ive the c orrec t results?

INSERT INTO employees (employee_id , last_name, department_id )


(100,'Bond',
(select department_id from departments where department_id = 300));

INSERT INTO employees (employee_id , last_name, department_id )


VALUES (100,'Bond',
(select department_id from departments where department_id = 300));

INSERT INTO employees (employee_id , last_name, department_id )


VALUES ('100','Bond',300);

None of the above

Answer: B, C. Sub queries do work in INSERT statements provided they return a sc alar
value of data type matc hing or c ompatible to the c olumn for whic h they are used.

DELETE FROM EMPLOYEES;

Assuming that there are no ac tive transac tions on the EMPLO YEES table in any sessions,
whic h of the following statements is true?

It removes all the rows and struc ture of the table

It removes all the rows whic h c an be rolled bac k

It removes all the rows permanently

None of the above


Answer: B. Being a DML statement, the data c hang es due to DELET E operation are made
permanent only after CO MMIT is issued in the session.

SQL> desc countries


Name Null? Type
----------------------- -------- ----------------
COUNTRY_ID NOT NULL CHAR(2)
COUNTRY_NAME VARCHAR2(40)
REGION_ID NUMBER

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 RO LLBACK T O SAVEPO INT c ommand is issued for the user
session?

T he rollbac k g enerates an error

O nly DELET E statements are rolled bac k

No SQ L statement is rolled bac k

None of the above

Answer: A, C. Sinc e there are two savepoints - A and B, and the RO LLBACK c ommand does
spec ifies the ac tual savepoint mark, O rac le throws error.

65 .If a user issues a DML c ommand and exits the SQ L Developer abruptly without a
CO MMIT or RO LLBACK, what will be the outc ome? (Assume the session is not auto
c ommit)

Automatic CO MMIT

Automatic RO LLBACK

Mig ht be a CO MMIT or a RO LLBACK to end the transac tion

None of the above

Answer: B. When transac tion is interrupted by a system failure, the entire transac tion is
automatic ally rolled bac k.

66. Whic h of the following c ommands / statements would end a transac tion?

CO MMIT

SELECT

SAVEPO INT

CREAT E

Answer: A, D. Apart from T CL c ommands i.e. CO MMIT or RO LLBACK, the DDL c ommands
and DCL c ommands possess auto c ommit feature. T he ac tive transac tion will be c ommitted
if the DDL statement is exec uted in the same session.
67.When does a transac tion c omplete?

When a RO LLBACK is exec uted

When a CO MMIT is exec uted

When T RUNCAT E is exec uted

All of the above

Answer: D. T ransac tion c ompletes if a T CL, DCL or a DDL c ommand is exec uted in the
session.

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 outc ome of the above query?

T he c olumns in the EMPLO YEES table and the departments table do not matc h

T he WHERE c lause is mandatory to be used in a sub-query

T he VALUES keyword c annot be used with the INSERT c lause when sub-queries are
used

None of the above

Answer: C. Wrong usag e of VALUES keyword. It must be used only when you have c olumn
data in hand, whic h has to be inserted in the table.

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);

Whic h of the following is true reg arding the g iven query?

It would not exec ute as we c annot use two tables in a sing le update statement

It would not exec ute as UPDAT E c annot use a sub-query

It would exec ute with the restric tions on the c olumn spec ified

It would not exec ute as sub-query is used in the WHERE c lause

Answer: C.

70.What happens when a transac tion is c ommitted?

T he c hang es made during the transac tion are saved for a partic ular user session

T he c hang es made during the transac tion are disc arded

If the transac tion is a DDL, the c ommit doesn't work

None of the above

Answer: D. Committing a transac tion saves the pending data c hang es permanently into the
database.

71. Whic h of the following reasons will the best one on the usag e of string ?

Using sub-queries

Syntax errors

Ac c ess permissions

Constraint violations

Answer: C, B, D. Referenc es to non-existing objec ts / c olumns, Spac e issues mig ht be


other reasons.

All the c olumns will g et NULL values

A new table with the same name would g et c reated automatic ally and the values would
g et inserted

INSERT c annot work and it throws an O RA error

None of the above

Answer: C.

73. A user named 'J onathan Adams' is able to SELECT c olumns from the EMPLO YEES table
but he is unable to insert rec ords into EMPLO YEES. What c an be the reason?

J onathan is c onnec ted to a database whic h does not support INSERT statements
T he INSERT statement c annot be applied on the table EMPLO YEES

J onathan has ac c ess to SELECT but no ac c ess to INSERT INT O the table
EMPLO YEES

None of the above

Answer: C. Users c an enjoy table ac c ess based on their responsibilities. O ne c an have only
read ac c ess on a table while other c an enjoy read and write ac c ess.

74. Suppose 1 million rows are to be inserted into the AUDIT table. An INSERT transac tion
runs suc c essfully for the first 1000 rows and an O RA error is thrown 'Constraint violated'.
What will happen to the values inserted in the first 1000 rows?

T hey will remain as it is

T hey all will g et deleted

T hey all will g et rolled bac k

None of the above

Answer: C. If any of the DML statement during the transac tion enc ounters error(s), the
c omplete transac tion will be rolled bac k.
Examine the table struc ture and c onsider 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 outc ome of this statement?

It will insert a row with department_id = 15 and all the other values as NULL

It will exec ute suc c essfully but insert 0 rows in the table

It will throw an O RA error as the no. of c olumns and values do not matc h

None of the above

Answer: C. T he DEPART MENT S table c ontains four c olumns but the INSERT statement
supplies value for two c olumns only without mentioning the c olumns too. Henc e, the O RA
error is thrown.

76. What is true about the above INSERT statement?

If the c olumns are not mentioned in the INSERT statement, the values are inserted
positionally in the c olumns

It is mandatory to mention c olumns after the INSERT statement

Both A and B

None of the above

Answer: A. If the c olumns are not spec ified in the INSERT statement, O rac le sequentially
and positionally maps eac h value to the c olumn in the table.

77. With respec t to the statement g iven above, what will happen if the table is altered to add a
new c olumn?
T he statement will still work

T he statement exec ution will throw an error as there will be a mismatc h in the no. of
c olumns and values

T here will be no c hang e and the statement will exec ute as before

None of the above

Answer: B. Sinc e the c olumns were not spec ified earlier, the problem will still exist.
Mismatc h in the c olumn-value mapping would throw an O RA error.
Examine the table struc ture g iven below and c onsider 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)

Q uery 1:
INSERT INTO employees (employee_id , last_name, hire_date)
VALUES (100, 'ADAMS','21-DEC-12');

Q uery 2:
INSERT INTO employees (employee_id , last_name, hire_date)
VALUES (100, upper('ADAMS'),to_date('21-DEC-12','DD-MON-YY'));

78. Whic h of the above two queries is better?

Both are better

O nly Q uery 1 is better

O nly Q uery 2 is better

None of the queries is c orrec t

Answer: C. Q uery-2 is better bec ause it inserts date value as a date and not as a string .
T houg h O rac le will perform implic it c onversion of string literal spec ified as a date, but not
rec ommended.

79. Whic h of the following queries is equivalent of the query 2 g iven above?

INSERT INTO employees (employee_id , last_name, hire_date)


VALUES (101-1, upper('ADAMS'),to_date('21-DEC-12','DD-MON-YY'));

INSERT INTO employees (employee_id , last_name, hire_date)


VALUES (99+1, upper('ADAMS'),to_date('22-DEC-12','DD-MON-YY') +1 );

INSERT INTO employees (employee_id , last_name, hire_date)


VALUES (100, upper('ADAMS'),to_date('21-DEC-12','DD-MON-YY') - 1);

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 /func tions c an be used to insert values as shown
above.

80. You need to c opy the data from one table to another table. Whic h of the following
methods c an be used?

You c an use the CO PY c ommand

You c an use the INSERT c ommand

You c an use the UPDAT E c ommand

None of the above

Answer: B. T he direc t path operations INSERT -AS-SELECT (IAS) is the most c ommonly
used method to c opy data from one table to another.

81.Whic h of the following statements will c opy data from the J O B_HIST O RY table to the
J O B_HIST O RY_ARCHIVE table? (Consider the table struc ture as g iven)
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)

INSERT INTO job_history values (select * from job_history);

INSERT INTO JOB_HISTORY_ARCHIVE values (select * from job_history_archive);

INSERT INTO JOB_HISTORY_ARCHIVE select * from job_history;

None of the above

Answer: C. T he option 'C' c orrec tly shows the usag e of IAS (INSERT -AS-SELECT )
method.
Examine the g iven table struc ture. 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.

T hrown an error

It will insert the rec ords for all the employees who were hired a month before the
sysdate.

It will insert the rec ords for all the employees who are Sales Representatives in
department 10

None of the above

Answer: B, C. INSERT ALL c an make c onditional inserts into the targ et tables.

83. Whic h employees' data will be inserted in the department 20?

Sales Representatives

Ac c ountants

Both A or B

None of the above

Answer: B. As per the INSERT ALL statement, the details of employees whose job_id is not
'Sales Representative'.

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;

Syntax error as substitution variables c annot be used in DML statements

T he user will be prompted for entering the employee ID and the salary but substitution
variables c annot insert data in the table

T he user will be prompted for entering the employee ID and the salary and rec ord will
be suc c essfully c reated in the EMPLO YEES table

None of the above

Answer: C. Substitution variables work well with the DML statements.

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 outc ome of the above statements?

T he CREAT E SEQ UENCE c ommand would throw error bec ause the minimum and
maximum value for the sequenc e have not been spec ified

All the statements would exec ute suc c essfully and the employee_id c olumn would
c ontain the value 2 for the employee ST EYN.

T he CREAT E SEQ UENCE c ommand would not exec ute bec ause the starting value of
the sequenc e and the inc rement value have not been spec ified.

All the statements would exec ute suc c essfully and the employee_id c olumn would have
the value 20 for the employee ST EYN bec ause the default CACHE value is 20.

Answer: B.

86. What is the restric tion on the sub-query used in the UPDAT E statement?

T he sub-query should be a multi row sub-query

T he sub-query should be a sing le row sub-query

T here's no restric tion

T he sub-query c an be either a sing le row or a multi row sub-query

Answer: B. T he sub-query should not return multiple rows when being used in an UPDAT E
statement
Examine the g iven table struc ture and c onsider the query g iven 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 outc ome of the above query?

It throws an O RA error on exec ution

Salary of all the employees will be updated with the same salary as the employee 7382

Salary of all the employees will be updated to NULL

None of the above

Answer: B. Q uery results c an be used to update the c olumn values in a table.

88. Suppose if the employee 7382 doesn't exist in the EMPLO YEES table. What will be the
outc ome of the query?

It throws an O RA error on exec ution bec ause query results c annot be updated to the
c olumns
Salary of all the employees will be updated to NULL

O RA exc eption 'NO _DAT A_FO UND' will be raised bec ause employee 7382 doesn't
exists

None of the above

Answer: B. UPDAT E statements do not raise any exc eption exc ept for syntac tic al errors.
Examine the g iven table struc ture and c onsider the query g iven 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 outc ome of the query?

It exec utes suc c essfully

All the rows of the table have the same salary

It mig ht throw an O RA error 'T O O _MANY_RO WS' upon exec ution

None of the above

Answer: C. T he sub-query mig ht return more than one row c ausing an error.

90. What c hang es in the above query will make sure there are no errors c aused?

Use a sing le row func tion like MAX, MIN or AVG to reduc e multi row results into a
sc alar result

Adding a Primary key c onstraint on SALARY c olumn

No c hang e required

None of the above

Answer: A.
Examine the g iven table struc ture and c onsider 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 outc ome of the query g iven above?

It will update the salaries of all the employees equal to the salary of the employee
named Adam

It will update the salaries of all the employees equal to the averag e salary of all with last
name as 'Adam'

It will update 0 rows

It will update only one row

Answer: B. Arithmetic func tions MAX or a MIN c an be used with sub-queries to g et sc alar
values and avoid errors.

SELECT distinct salary from employees where last_name = 'Adam';

What will be the outc ome of the main query g iven above?

It will exec ute suc c essfully g iving inc orrec t results

It will exec ute suc c essfully g iving c orrec t results

It will throw an O RA error

None of the above

Answer: C. it g ives an error bec ause as there are many with the last name as 'Adam' there
will many distinc t salaries.
Examine the g iven table struc ture and c onsider 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)

It will update all the salaries for all the employees as 5 0000

It will update all the salaries for all the employees who are in department 10

It will update the salaries for all the employees who have one of the job IDs similar to
those in department 10

None of the above


Answer: C.

WHERE job_id = (select job_id from job_history where department_id = 10);

It will exec ute suc c essfully with inc orrec t results

It will exec ute suc c essfully with c orrec t results

It will throw an O RA error

None of the above

Answer: C. T he equal sig n will raise the 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)

DELETE FROM employees where last_name = 'A%';


COMMIT;

95 . What will be the outc ome of the query g iven above?

Exec utes suc c essfully but no rows are deleted

All the employees whose last_name starts with "A" will be deleted

O RA error bec ause DELET E statement c annot have WHERE predic ate

All the rows from the employees table will g et deleted

Answer: A. DELET E statement c an have WHERE c lause predic ate. Based on c onditions, the
rec ords will be removed from the table.

DELETE FROM employees where employee_id IS NULL and job_id = NULL;


COMMIT;

Assuming there is a NO T NULL c onstraint on the c olumn employee_id , what will be the
outc ome of the above query?

It will raise O RA error bec ause of invalid WHERE predic ates

It will exec ute suc c essfully and no rows will be deleted

It will raise O RA error bec ause multiple predic ates c annot work in DELET E
statements

None of the above

Answer: B. Multiple predic ates c an be applied to the DML statements UPDAT E and
DELET E.

DELETE FROM employees where department_id = &deptID;


COMMIT;

What will happen when the above statement is exec uted?


It will raise error bec ause DML statements c annot use substitution variables

It will prompt for the department ID to be deleted from the user and delete the rec ord
with the g iven department ID

It will prompt for the department ID but transac tion c annot be c ommitted

None of the above

Answer: B. Substitution variables c an be used with DML statements.

98. All parts of a transac tion should c omplete or none of them. Whic h property of ACID
rule c omplies with the g iven statement?

Atomic ity

Consistenc y

Isolation

Durability

Answer: A. ACID refers to the basic properties of a database transac tion: Atomic ity,
Consistenc y, Isolation, and Durability. Atomic ity implies that entire sequenc e of ac tions
must be either c ompleted or aborted. Consistenc y implies that the transac tion takes the
resourc es from one c onsistent state to another. Isolation implies that a transac tion's effec t
is not visible to other transac tions until the transac tion is c ommitted. Durability implies that
the c hang es made by the c ommitted transac tion are permanent and must survive system
failure.

99. What does the princ iple of Durability in the ACID property state?

It states that a database c an lose c ompleted transac tions

It states that a transac tion c annot g et c ompleted

It states that onc e a transac tion c ompletes, it must be impossible for the DB to lose it.

None of the above

Answer: C.

100. An inc omplete transac tion should be invisible to all the other users. Whic h of the
properties of the ACID state this?

Isolation

Consistenc y

Atomic ity

Durability

101. What does the princ iple of c onsistenc y states?

It states that the results of a query must be c onsistent with the state of the DB at the
time the query started

It states that an inc omplete transac tion should be invisible to all the other users

It states that onc e a transac tion c ompletes, it must be impossible for the DB to lose it

None of the above

102. What among the following best desc ribes a T ransac tion?
INSERT to CO MMIT /RO LLBACK

UPDAT E to CO MMIT /RO LLBACK

DELET E to CO MMIT /RO LLBACK

INSERT /UPDAT E/DELET E to CO MMIT /RO LLBACK

Answer: D.

When J onathan provides ac c ess permission to the users

When J onathan exec utes a RO LLBACK statement in the session

When J onathan exec utes a CO MMIT statement in the same session

When J onathan opens a new session and issues a CO MMIT

Answer: C. T he ac tive transac tion must be c ommitted in the same session.

104. What c an be said about the nesting of transac tions?

Maximum 2 levels of nesting are possible

Maximum 25 5 levels of nesting are possible

Nesting of a transac tion is impossible

O nly 1 level of nesting is possible

Answer: C.

105 . Whic h of the following reasons will terminate a transac tion?

A DDL statement

Exiting a c lient

System c rashes

All of the above

Answer: D. DDL is auto c ommit and will end the ong oing ac tive transac tion.