Quiz s9
Quiz s9
Quiz s9
LESSON 1
1. What will happen when the following subprogram is compiled? PROCEDURE at_proc
IS PRAGMA AUTONOMOUS_TRANSACTION; dept_id NUMBER := 90; BEGIN UPDATE ... INSERT
... END at_proc; Mark for Review (1) Points The subprogram will fail because it
is missing AUTHID CURRENT_USER before IS. The autonomous transaction subprogram
will fail because it must include COMMIT or ROLLBACK. (*) The compilation will
fail because a semicolon after AUTONOMOUS_TRANSACTION is not needed. The program
will compile successfully. Incorrect. Refer to Section 9 Lesson 6. 2. To create
a function successfully, the following steps should be performed: A B C D E F R
e-execute the code until it compiles correctly Write the code containing the CRE
ATE or REPLACE FUNCTION followed by the function code Test the function from a S
QL statement or an anonymous block If the function fails to compile, correct the
errors Load the code into Application Express Execute the code in Application E
xpress
What is the correct order to perform these steps? Mark for Review (1) Points B,E
,F,D,A,C (*) D,B,E,F,A,C B,C,E,F,D,A A,B,E,F,D,C Correct 3. An autonomous transa
ction subprogram may be in the same package as the calling subprogram or may be
in a separate subprogram. True or False? (1) Points True False (*) Incorrect. Re
fer to Section 9 Lesson 6. Mark for Review
4. Which of the following is found in a function and not a procedure? (1) Points
An exception section. IN parameters. Local variables in the IS/AS section. Retu
rn statement in the header. (*) Correct 5. The following function has been creat
ed: CREATE OR REPLACE FUNCTION find_sal (p_emp_id IN employees.employee_id%TYPE)
RETURN NUMBER IS ... We want to invoke this function from the following anonymo
us block: DECLARE v_mynum NUMBER(6,2); v_mydate DATE; BEGIN ... Line A END; Whic
h of the following would you include at Line A? Mark for Review (1) Points find_
sal(100,v_mynum); v_mynum := find_sal(100); (*) v_mydate := find_sal(100); find_
sal(v_mynum,100);
Mark for Review
Correct 6. You have created a function called GET_COUNTRY_NAME which accepts a c
ountry_id as an IN parameter and returns the name of the country. Which one of t
he following calls to the function will NOT work? Mark for Review (1) Points v_n
ame := get_country_name(100); DBMS_OUTPUT.PUT_LINE(get_country_name(100)); SELEC
T get_country_name(100) FROM dual; BEGIN get_country_name(100, v_name); END; (*)
Correct 7. What is wrong with the following code? CREATE FUNCTION annual_comp (
sal employees.salary %TYPE, comm_pct IN employees.commission%TYPE) RETURN NUMBER
(5,2) IS RETURN (sal*12) + NVL(comm_pct,0)*12*sal; END annual_comp; (1) Points M
ark for Review
The sal parameter should specify the IN keyword. The RETURN NUMBER has a scale a
nd precision. (*) There should be parentheses (brackets) around NVL(comm_pct,0)*
12*sal The END; statement should not include the function name. Correct 8. Funct
ion MYFUNC1 has been created, but has failed to compile because it contains synt
ax errors. We now try to create procedure MYPROC1 which invokes this function. W
hich of the following statements is true? Mark for Review (1) Points MYPROC1 wil
l compile correctly, but will fail when it is executed. MYPROC1 will compile and
execute succesfully. MYPROC1 will fail to compile because the function is inval
id. (*) MYPROC1 will compile and execute successfully, except that the call to M
YFUNC1 will be treated as a comment and ignored. Correct 9. Based on the followi
ng function definition: Create function annual_comp (sal employees.salary %type,
comm_pct In employees.commission%type) ... Which one of the following is an inc
orrect call for annual_comp? Mark for Review (1) Points Execute dbms_output.put_
line(annual_comp (1000,.2)) Select employee_id, annual_comp(salary, commission_p
ct) from employees; Declare Ann_comp number (6,2); Begin ... Ann_comp := annual_
comp(1000,.2); ... End; Select employee_id, annual_comp(salary) from employees;
(*) Correct 10. When using Invoker's rights, the invoker needs privileges on the
database objects referenced within the subprogram, as well as GRANT privilege o
n the procedure. True or False? (1) Points True False (*) Incorrect. Refer to Se
ction 9 Lesson 6. 11. Procedure p1 has a single OUT parameter of type DATE. Func
tion f1 returns a DATE. What is the difference between p1 and f1? Mark for Revie
w (1) Points p1 can be invoked from an anonymous block but f1 cannot f1 can be u
sed within a SQL statement but p1 cannot (*) p1 can have as many IN parameters a
s needed but f1 cannot have more than two IN parameters There is no difference b
ecause they both return a single value of the same datatype Incorrect. Refer to
Section 9 Lesson 1. 12. A PL/SQL function can have IN OUT parameters. True or Fa
lse? (1) Points Mark for Review Mark for Review
True False (*) Correct 13. A stored function: Mark for Review (1) Points must ha
ve at least one IN parameter. cannot be called in a SQL statement. must return o
ne and only one value. (*) is called as a standalone executable statement. Corre
ct 14. Function GET_JOB accepts an employee id as input and returns that employe
e's job id. Which of the following calls to the function will NOT work? (1) Poin
ts DBMS_OUTPUT.PUT_LINE(get_job(100)); IF get_job(100) = 'IT_PROG' THEN ... get_
job(100,v_job_id); (*) v_job_id := get_job(100); Correct 15. CREATE FUNCTION get
_sal (p_id employees.employee_id%TYPE)) RETURN number IS v_sal employees.salary%
TYPE := 0; BEGIN SELECT salary INTO v_sal FROM employees WHERE employee_id = p_i
d; RETURN v_sal; END get_sal; Which variable is passed to the function and which
variable is returned from the function? Mark for Review (1) Points GET_SAL is p
assed and V_SAL is returned. SALARY is passed and P_ID is returned. EMPLOYEE_ID
is passed and SALARY is returned. P_ID is passed and V_SAL is returned. (*) Corr
ect Mark for Review
LESSON 2
1. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE FUNCTION d
ouble_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN RETURN(p_sa
lary * 2); END; Which of the following calls to DOUBLE_SAL will NOT work? Mark f
or Review (1) Points SELECT * FROM employees WHERE double_sal(salary) > 20000; S
ELECT * FROM employees ORDER BY double_sal(salary) DESC; UPDATE employees SET sa
lary = double_sal(salary); SELECT last_name, double_sal(salary) FROM employees;
None of the above; they will all work (*) Correct 2. User-defined functions can
extend the power of SQL statements where Oracle does not provide ready-made func
tions such as UPPER and LOWER. True or False? (1) Points True (*) False Correct
3. The following function has been created: CREATE OR REPLACE FUNCTION upd_dept
(p_dept_id IN departments.department_id%TYPE) RETURN NUMBER IS BEGIN UPDATE depa
rtments SET department_name = 'Accounting' WHERE department_id = p_dept_id; RETU
RN p_dept_id; END; Which of the following will execute successfully? Mark for Re
view (1) Points DELETE FROM departments WHERE department_id = upd_dept(departmen
t_id); SELECT upd_dept(department_id) FROM employees; DELETE FROM employees WHER
E department_id = upd_dept(80); (*) SELECT upd_dept(80) FROM dual; Incorrect. Re
fer to Section 9 Lesson 2. 4. Which of the following is NOT a benefit of user-de
fined functions? (1) Points They can add business rules to the database and can
be reused many times. Mark for Review Mark for Review
They can be used in a WHERE clause to filter data. They can do the same job as b
uilt-in system functions such as UPPER and ROUND. (*) They can often be used ins
ide SQL statements. Correct 5. You want to create a function which can be used i
n a SQL statement. Which one of the following can be coded within your function?
(1) Points RETURN BOOLEAN One or more IN parameters (*) An OUT parameter COMMIT
; Correct 6. Which of the following is NOT a legal location for a function call
in a SQL statement? Review (1) Points FROM clause of a SELECT statement (*) WHER
E clause in a DELETE statement SET clause of an UPDATE statement VALUES clause o
f an INSERT statement Correct Mark for Mark for Review
LESSON 3
1. You have forgotten the name of the Dictionary view USER_TABLES. Which of the
following statements is the best and quickest way to remind yourself? Mark for R
eview (1) Points SELECT * FROM dictionary WHERE table_name LIKE USER%; Read the
online Oracle documentation at http://technet.oracle.com. SELECT * FROM dict WHE
RE table_name LIKE 'USER%TAB%'; (*) SELECT * FROM dictionary WHERE table_name =
'USER_TABLES'; Phone the database administrator. Correct 2. Which of the followi
ng is NOT a benefit of the Data Dictionary? Mark for Review (1) Points It allows
us to remind ourselves of the names of our tables, in case we have fogotten the
m.
It allows us to check which system privileges have been granted to us. It will s
peed up the execution of SELECT statements in which the WHERE clause column is n
ot indexed. (*) It allows the PL/SQL compiler to check for object existence; for
example, when creating a procedure which references a table, the PL/SQL compile
r can check that the table exists. Correct 3. Which of the following will displa
y how many objects of each type are in a user's schema? Mark for Review (1) Poin
ts SELECT COUNT(*) FROM user_objects; SELECT object_type, COUNT(*) FROM user_obj
ects GROUP BY object_type; (*) SELECT object_type, COUNT(*) FROM all_objects GRO
UP BY object_type; DESCRIBE user_objects GROUP BY object_type; Incorrect. Refer
to Section 9 Lesson 3. 4. A user executes the following statement: CREATE INDEX
fn_index ON employees(first_name); What output will the following statement now
display: SELECT index_name FROM user_indexes WHERE index_name LIKE 'fn%'; Mark f
or Review (1) Points fn_index FN_INDEX fn_index FN_INDEX No output will be displ
ayed (*) Correct 5. User BOB is not a database administrator. BOB wants to see t
he names of all the tables in his schema, as well as all the tables in other use
rs' schemas which he has privileges to use. Which Data Dictionary view would BOB
query to do this? (1) Points USER_TABLES ALL_TABLES (*) Mark for Review
DBA_TABLES USER_TAB_COLUMNS None of the above. Correct 6. User MARY executes the
SQL statement: SELECT COUNT(*) FROM USER_VIEWS; A value of 15 is returned. Whic
h of the following statements is true? Mark for Review (1) Points There are 15 v
iews in Mary's schema. (*) Mary has created views on 15 of her tables. There are
15 views in the database. Other users have granted Mary SELECT privilege on 15
of their views. Correct 7. Which of the following statements about the "super-vi
ew" DICTIONARY is true? Review (1) Points It lists all the dictionary views. It
can be thought of as a "catalog of the master catalog". We can use it like a Web
search engine to remind ourselves of the names of dictionary views. All of the
above. (*) None of the above. Correct 8. Which of the following best describes t
he Data Dictionary? Mark for Review (1) Points It is a set of tables which can b
e updated by any user who has the necessary privileges. It is an automatically m
anaged master catalog of all the objects stored in the database. (*) It contains
a backup copy of all the data in the database. It contains a list of all databa
se tables which are not in any schema. Correct Mark for
LESSON 4
1. Which dictionary view will list all the PL/SQL subprograms in your schema? (1
) Points user_source
Mark for Review
user_procedures user_objects (*) user_dependencies user_subprograms Correct 2. p
roc_a has been created as follows: CREATE OR REPLACE PROCEDURE proc_a IS v_last_
name employees.last_name%TYPE; BEGIN SELECT last_name INTO v_last_name FROM empl
oyees WHERE employee_id = 999; /* This SELECT will raise an exception because em
ployee_id 999 does not exist */ DBMS_OUTPUT.PUT_LINE('This SELECT failed'); END;
proc_b is now created as follows: CREATE OR REPLACE PROCEDURE proc_b IS BEGIN p
roc_a; DBMS_OUTPUT.PUT_LINE('proc_a was invoked'); EXCEPTION WHEN OTHERS THEN DB
MS_OUTPUT.PUT_LINE('An exception occurred'); END; What will be displayed when pr
oc_b is executed? Mark for Review (1) Points An exception occurred (*) This SELE
CT failed proc_a was invoked An exception occurred This SELECT failed This SELEC
T failed proc_a was invoked Nothing will be displayed Correct 3. The database ad
ministrator has granted the DROP ANY PROCEDURE privilege to user KIM. This allow
s Kim to remove other users' procedures and functions from the database. How wou
ld Kim now drop function GET_EMP, which is owned by user MEHMET? (1) Points DROP
FUNCTION get_emp FROM mehmet Mark for Review
DROP FUNCTION mehmet.get_emp (*) DROP PROCEDURE mehmet.get_emp DROP PROGRAM mehm
et.get_emp None of the above Correct 4. Which view would you query to see the de
tailed code of a procedure? (1) Points user_source (*) user_procedures user_obje
cts user_dependencies user_errors Correct 5. You need to remove procedure BADPRO
C from your schema. What is the correct syntax to do this? Mark for Review (1) P
oints DELETE PROCEDURE badproc; DROP PROGRAM badproc; ALTER PROCEDURE badproc DI
SABLE; DROP PROCEDURE badproc; (*) Incorrect. Refer to Section 9 Lesson 4. 6. Pr
ocedure ins_emp accepts an employee_id as an IN parameter and attempts to insert
a row with that employee_id into the EMPLOYEES table. Ins_emp does not contain
an exception section. A second procedure is created as follows: CREATE OR REPLAC
E PROCEDURE call_ins_emp IS BEGIN ins_emp(99); -- this employee does not exist i
ns_emp(100); -- this employee already exists ins_emp(999); -- this employee does
not exist EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An exception occurre
d'); END; When call_ins_emp is executed, which rows will be inserted into the EM
PLOYEES table? Mark for Review (1) Points 99 only (*) 99 and 999 All three rows
will be inserted Mark for Review
999 only No rows will be inserted Correct
LESSON 5
1. USERB creates a function called SEL_PROC (using Definer's Rights) which inclu
des the statement: SELECT ... FROM usera.employees ...; USERC needs to execute U
serB's procedure. What privileges are needed for this to work correctly? (Choose
two.) Mark for Review (1) Points (Choose all correct answers) UserB needs SELEC
T on userA.employees (*) UserC needs SELECT on userA.employees UserC needs EXECU
TE on userB.sel_proc (*) UserA needs EXECUTE on userB.sel_proc UserC needs EXECU
TE on Userb Correct 2. User TOM needs to grant both SELECT and INSERT privileges
on both his EMPLOYEES and DEPARTMENTS tables to both DICK and HARRY. What is th
e smallest number of GRANT statements needed to do this? (1) Points 1 2 (*) 3 4
8 Correct 3. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE t
o create indexes on the table. Which object privilege must Colleen grant to Ayse
? (1) Points SELECT on EMPLOYEES INDEX on EMPLOYEES (*) ALTER on EMPLOYEES CREAT
E on EMPLOYEES None of the above Correct Mark for Review Mark for Review
4. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the location_i
d column of Diane's table, but no other columns. Which SQL statement should Dian
e execute to allow this? Review (1) Points GRANT UPDATE ON departments TO joel;
GRANT UPDATE ON departments(location_id) TO joel; GRANT UPDATE ON departments.lo
cation_id TO joel; GRANT UPDATE(location_id) ON departments TO joel; (*) GRANT U
PDATE ON location_id OF departments TO joel; Correct 5. User SVETLANA creates a
view called EMP_VIEW that is based on a SELECT from her EMPLOYEES table. Svetlan
a now wants user PHIL to be able to query the view. What is the smallest set of
object privileges that Svetlana must grant to Phil? Mark for Review (1) Points S
ELECT on EMP_VIEW and SELECT on EMPLOYEES SELECT and EXECUTE on EMP_VIEW SELECT
on EMP_VIEW (*) SELECT on EMP_VIEW and REFERENCES on EMPLOYEES Correct 6. User F
RED creates a procedure called DEL_DEPT using Definer's Rights, which deletes a
row from Fred's DEPARTMENTS table. What privilege(s) will user BOB need to be ab
le to execute Fred's procedure? Mark for Review (1) Points EXECUTE on DEL_DEPT (
*) EXECUTE on DEL_DEPT and DELETE on DEPARTMENTS EXECUTE on DEL_DEPT and DELETE
on FRED.DEPARTMENTS DELETE on FRED.DEPARTMENTS Correct Mark for
LESSON 6
1. An autonomous transaction subprogram may be in a the same package as the call
ing subprogram or may be in a separate subprogram. True or False? (1) Points Tru
e False (*) Incorrect. Refer to Section 9 Lesson 6. Mark for Review
2. When using Invoker's rights, the invoker needs privileges on the database obj
ects referenced within the subprogram, as well as GRANT privilege on the procedu
re. True or False? (1) Points True False (*) Incorrect. Refer to Section 9 Lesso
n 6. 3. Procedure GET_EMPS includes a SELECT ... FROM EMPLOYEES. The procedure w
as created using Invoker's Rights. Which of the following statements are true? (
Choose three.) Mark for Review (1) Points (Choose all correct answers) The user
who executes the procedure needs EXECUTE privilege on the procedure. (*) The cre
ator of the procedure needs SELECT privilege on EMPLOYEES. (*) The user who exec
utes the procedure does not need any privileges. The user who executes the proce
dure needs SELECT privilege on EMPLOYEES. (*) Incorrect. Refer to Section 9 Less
on 6. 4. Which of the following is the correct syntax to create a procedure usin
g Invoker's Rights? for Review (1) Points CREATE PROCEDURE myproc IS AUTHID CURR
ENT_USER BEGIN ... CREATE PROCEDURE myproc AUTHID CURRENT_USER IS BEGIN ... (*)
CREATE PROCEDURE AUTHID CURRENT_USER myproc IS BEGIN ... CREATE PROCEDURE myproc
IS BEGIN AUTHID CURRENT_USER ... Correct 5. What will happen when the following
subprogram is compiled? PROCEDURE at_proc IS PRAGMA AUTONOMOUS_TRANSACTION; dep
t_id NUMBER := 90; BEGIN UPDATE ... INSERT ... END at_proc; Mark for Review (1)
Points The subprogram will fail because it is missing AUTHID CURRENT_USER before
IS. The autonomous transaction subprogram will fail because it must include COM
MIT or ROLLBACK. (*) Mark Mark for Review
The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTION is no
t needed. The program will compile successfully. Incorrect. Refer to Section 9 L
esson 6. 6. Users SYS (the DBA), TOM, DICK and HARRY each have an EMPLOYEES tabl
e in their schemas. SYS creates a procedure DICK.SEL_EMP using Invoker's Rights
which contains the following code: SELECT ... FROM EMPLOYEES ... ; HARRY now exe
cutes the procedure. Which employees table will be queried? Mark for Review (1)
Points SYS.EMPLOYEES DICK.EMPLOYEES HARRY.EMPLOYEES (*) None of the above Correc
t 7. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights to
create procedure GET_NEWEMP which includes the line: SELECT ... FROM NEWEMP ...
; Sally also grants EXECUTE privilege on the procedure to CURLY, but no other p
rivileges. What will happen when Curly executes the procedure? Mark for Review (
1) Points The procedure will execute successfully. The procedure will fail becau
se Curly does not have SELECT privilege on NEWEMP. The procedure will fail becau
se there is no NEWEMP table in Curly's schema. (*) The procedure will fail becau
se Curly does not have the EXECUTE ANY PROCEDURE system privilege. Correct