Beruflich Dokumente
Kultur Dokumente
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
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.
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.
INSERT
DELET E
GROUP BY
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
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.
MINUS
UPDAT E
T RUNCAT E
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
9. What is true about the INSERT statement? (Choose the most appropriate answer)
Answer: C. T he INSERT statement is capable of inserting a row or set of rows in a sing le table at a time.
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 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
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)
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?
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);
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?
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
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.
SELECT
INSERT
Sub-queries
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)
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.
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
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)
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)
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;
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;
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?
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.
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)
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?
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
Answer: C.
27. Whic h of the following c olumns in a table are not usually updated?
A primary key c olumn whic h also serves as foreig n key referenc e in another table
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)
UPDATE employees
SET job_id = NULL;
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)
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?
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
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)
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;
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
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 c an perform all three operations on a table 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
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
38.Whic h of the following situations indic ate that a DML operation has taken plac e?
Answer: A. When existing rows in a table are inserted, modified or removed from a table, it
is done throug h a DML statement.
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 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
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.
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)
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?
Answer: B. If the c olumns are mentioned in the INSERT c lause, the VALUES keyword
should c ontain values in the same order
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
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.
It will insert only the employee_id and the hire date of the employee, leaving all other
c olumns as blanks
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.
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)
Answer: C.
It will insert only the employee_id and the first name of Bryan, leaving all other
c olumns as NULL
It will exec ute suc c essfully but with wrong values mig ht g et inserted in the c olumns
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)
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)
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.
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
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 an insert values
It throws an O RA error
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
5 9. Whic h of the following is the syntax for inserting rows throug h a sub-query?
Both A and B
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);
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?
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.
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?
What will happen when a RO LLBACK T O SAVEPO INT c ommand is issued for the user
session?
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
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?
Answer: D. T ransac tion c ompletes if a T CL, DCL or a DDL c ommand is exec uted in the
session.
T he c olumns in the EMPLO YEES table and the departments table do not matc h
T he VALUES keyword c annot be used with the INSERT c lause when sub-queries are
used
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.
It would not exec ute as we c annot use two tables in a sing le update statement
It would exec ute with the restric tions on the c olumn spec ified
Answer: C.
T he c hang es made during the transac tion are saved for a partic ular user session
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
A new table with the same name would g et c reated automatic ally and the values would
g et inserted
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
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?
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)
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
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.
If the c olumns are not mentioned in the INSERT statement, the values are inserted
positionally in the c olumns
Both A and B
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
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'));
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?
80. You need to c opy the data from one table to another table. Whic h of the following
methods c an be used?
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)
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
Answer: B, C. INSERT ALL c an make c onditional inserts into the targ et tables.
Sales Representatives
Ac c ountants
Both A or B
Answer: B. As per the INSERT ALL statement, the details of employees whose job_id is not
'Sales Representative'.
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
UPDATE employees
SET employee_id = id_seq.NEXTVAL
WHERE first_name = 'Steyn'
AND job_id ='Trainee';
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?
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);
Salary of all the employees will be updated with the same salary as the employee 7382
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
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');
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
No c hang e required
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'
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.
What will be the outc ome of the main query g iven 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
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
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.
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 multiple predic ates c annot work in DELET E
statements
Answer: B. Multiple predic ates c an be applied to the DML statements UPDAT E and
DELET E.
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
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 onc e a transac tion c ompletes, it must be impossible for the DB to lose it.
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
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
102. What among the following best desc ribes a T ransac tion?
INSERT to CO MMIT /RO LLBACK
Answer: D.
Answer: C.
A DDL statement
Exiting a c lient
System c rashes
Answer: D. DDL is auto c ommit and will end the ong oing ac tive transac tion.