You are on page 1of 46

Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

1. You try to create a function named MYFUNC. The function does not compile
correctly because there are errors in your code. Which Dictionary view can you query to see the
errors? Mark for Review

(1) Points

USER_SOURCE

USER_COMPILES

USER_ERRORS (*)

USER_DEPENDENCIES

USER_OBJECTS
Correct Correct

2. You have created a function named NEWFUNC. You now change some of the
function code, and try to recreate the function by executing:

CREATE OR REPLACE FUNCTION newfunc .... ;

What happens?

Mark for Review

(1) Points

A second function named NEWFUNC_2 is created.

The command fails because the function already exists.

The function is dropped but not recreated.

The function is automatically dropped and then recreated. (*)

The command fails because you should execute: CREATE AND REPLACE ....;
Correct Correct

3. To create a function successfully, the following steps should be performed.

A Re-execute the code until it compiles correctly

B Write the code containing the CREATE or REPLACE FUNCTION followed by the function code

C Test the function from a SQL statement or an anonymous block

D If the function fails to compile, correct the errors

E Load the code into Application Express

F Execute the code in Application Express

What is the correct order to perform these steps?

Mark for Review

(1) Points

A,B,E,F,D,C

B,C,E,F,D,A

D,B,E,F,A,C
B,E,F,D,A,C (*)

Correct Correct

4. Which of the following is a legal location for a function call in a SQL


statement? (Choose 3) Mark for Review

(1) Points

(Choose all correct answers)

VALUES clause of an INSERT statement (*)

CREATE TABLE statement

WHERE clause in a DELETE statement (*)

The ORDER BY and GROUP BY clauses of a query (*)

Correct Correct
5. You want to create a function which can be used in a SQL statement. Which
one of the following can be coded within your function? Mark for Review

(1) Points

COMMIT;

An OUT parameter

RETURN BOOLEAN

One or more IN parameters (*)

Correct Correct

Page 1 of 3 Next Summary

Test: Section 9 Quiz


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

6. Why will the following statement fail?

SELECT employee_id, tax(p_value => salary)

FROM employees;

Mark for Review

(1) Points

The data type for the tax variable does not match the data type for salary.

Name notation is not allowed. (*)

The statement will execute and not fail.

User-defined functions are not allowed in the SELECT clause.

Incorrect Incorrect. Refer to Section 9 Lesson 2.


7. How do you specify that you want a procedure MYPROCA to use "Definer's
Rights"? Mark for Review

(1) Points

CREATE OR REPLACE PROCEDURE myproca

AUTHID OWNER IS...

Definer's Rights are the default, therefore no extra code or commands are needed. (*)

ALTER PROCEDURE myproca TO DEFINER;

GRANT DEFINER TO myprocA;

CREATE OR REPLACE PROCEDURE myproca

AUTHID CURRENT_USER IS...

Correct Correct
8. What will happen when the following procedure is executed?

PROCEDURE log_usage (p_card_id NUMBER, p_loc NUMBER)

IS

PRAGMA AUTONOMOUS_TRANSACTION

BEGIN

INSERT INTO log_table (card_id, location, tran_date)

VALUES (p_card_id, p_loc, SYSDATE);

COMMIT;

END log_usage;

Mark for Review

(1) Points

The subprogram will fail because it is missing AUTHID CURRENT_USER before IS.

The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTION is


required. (*)

The subprogram will fail because the PRAGMA statement must be before IS.

The program will compile successfully.

Correct Correct
9. What is one of the main purposes of the Data Dictionary? Mark for
Review

(1) Points

To provide a structured list of all objects in the database (*)

To provide a list of all objects in your schema, but not in other users' schemas

To ensure correct spelling of the values in VARCHAR2 table columns

To translate data from one language to another

To prevent users from accidentally dropping tables

Incorrect Incorrect. Refer to Section 9 Lesson 3.

10. Which of the following statements about the "super-view" DICTIONARY is


true? Mark for Review
(1) Points

It can be thought of as a "catalog of the master catalog".

None of these.

It lists all the dictionary views.

All of these. (*)

We can use it like a Web search engine to remind ourselves of the names of dictionary
views.

Incorrect Incorrect. Refer to Section 9 Lesson 3.

Previous Page 2 of 3 Next Summary

Test: Section 9 Quiz


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

11. Which of the following will tell you how many functions you own?
Mark for Review

(1) Points

SELECT FUNCTIONS FROM USER_OBJECTS;

SELECT COUNT(*) FROM USER_OBJECTS;

SELECT COUNT(*) FROM USER_PROCEDURES;

SELECT COUNT(*) FROM USER_FUNCTIONS;

SELECT COUNT(*) FROM USER_OBJECTS WHERE OBJECT_TYPE='FUNCTION'; (*)

Incorrect Incorrect. Refer to Section 9 Lesson 3.


12. When a database object is first created, only its owner (creator) and the
Database Administrator are privileged to use it. True or False? Mark for Review

(1) Points

True (*)

False

Correct Correct

13. JOE's schema contains a COUNTRIES table. The following commands are
executed by JOE and TOM:

(JOE): GRANT SELECT ON countries TO tom WITH GRANT OPTION;

(TOM): GRANT SELECT on joe.countries TO dick WITH GRANT OPTION;

Now, JOE executes:

REVOKE SELECT ON countries FROM tom;

What happens to the grant to DICK?

Mark for Review

(1) Points
DICK also loses his SELECT privilege. (*)

The REVOKE statement fails because only the Database Administrator (not JOE) can revoke
privileges.

Nothing. DICK's privilege is preserved even though TOM lost his privilege.

The REVOKE statement fails because JOE must remove the SELECT privilege from both users
at the same time.

Incorrect Incorrect. Refer to Section 9 Lesson 5.

14. Which view would you query to see the detailed code of a procedure?
Mark for Review

(1) Points

user_dependencies

user_procedures
user_errors

user_objects

user_source (*)

Incorrect Incorrect. Refer to Section 9 Lesson 4.

15. Procedure 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 REPLACE PROCEDURE call_ins_emp IS

BEGIN

ins_emp(99); -- this employee does not exist

ins_emp(100); -- this employee already exists

ins_emp(999); -- this employee does not exist

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An exception occurred');

END;

When call_ins_emp is executed, (assuming Auto Commit is turned on), which rows will be inserted
into the EMPLOYEES table?
Mark for Review

(1) Points

999 only

99 and 999

99 only (*)

All three rows will be inserted

No rows will be inserted

Incorrect Incorrect. Refer to Section 9 Lesson 4.

Previous Page 3 of 3 Summary


Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

1. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the
location_id column of Diane's table, but no other columns. Which SQL statement should Diane
execute to allow this? Mark for Review

(1) Points

GRANT UPDATE ON departments TO joel;

GRANT UPDATE(location_id) ON departments TO joel; (*)

GRANT UPDATE ON location_id OF departments TO joel;

GRANT UPDATE ON departments(location_id) TO joel;

GRANT UPDATE ON departments.location_id TO joel;


Incorrect Incorrect. Refer to Section 9 Lesson 5.

2. You granted user JOE the privilege to query the EMPLOYEES table in your
schema. Now, you want to remove this privilege from JOE. Which command would you use?
Mark for Review

(1) Points

UNGRANT SELECT ON employees TO joe;

GRANT UNSELECT ON employees TO joe;

DENY SELECT ON employees TO joe;

REVOKE SELECT ON employees FROM joe; (*)

ROLLBACK;

Incorrect Incorrect. Refer to Section 9 Lesson 5.


3. Function GET_JOB accepts an employee id as input and returns that
employee's job id. Which of the following calls to the function will NOT work? Mark for Review

(1) Points

DBMS_OUTPUT.PUT_LINE(get_job(100));

IF get_job(100) = 'IT_PROG' THEN ...

v_job_id := get_job(100);

get_job(100,v_job_id); (*)

Incorrect Incorrect. Refer to Section 9 Lesson 1.

4. To create a function successfully,the first step is to test the code in an


anonymous block. Mark for Review

(1) Points

True
False (*)

Incorrect Incorrect. Refer to Section 9 Lesson 1.

5. Based on the following function definition:

Create function annual_comp

(sal employees.salary%type,

comm_pct IN employees.commission%type)

...

Which one of the following is an incorrect call for annual_comp?

Mark for Review

(1) Points

Execute dbms_output.put_line(annual_comp (1000,.2));

Select employee_id, annual_comp(salary)

from employees; (*)


Declare

Ann_comp number (6,2);

Begin

...

Ann_comp := annual_comp(1000,.2);

...

End;

Select employee_id, annual_comp(salary, commission_pct)

from employees;

Incorrect Incorrect. Refer to Section 9 Lesson 1.

Page 1 of 3 Next Summary

Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)


6. Which of the following is the correct syntax to create a procedure using
Invoker's Rights? Mark for Review

(1) Points

CREATE PROCEDURE myproc

AUTHID CURRENT_USER IS

BEGIN ...

(*)

CREATE PROCEDURE myproc IS

BEGIN

AUTHID CURRENT_USER ...

CREATE PROCEDURE myproc IS

AUTHID CURRENT_USER

BEGIN ...

CREATE PROCEDURE AUTHID CURRENT_USER myproc IS

BEGIN ...
Correct Correct

7. Procedure GET_EMPS includes a SELECTFROM EMPLOYEES. The procedure


was 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 creator of the procedure needs SELECT privilege on EMPLOYEES. (*)

The user who executes the procedure does not need any privileges.

The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*)

Incorrect Incorrect. Refer to Section 9 Lesson 6.

8. User MARY executes this SQL statement:


SELECT COUNT(*) FROM USER_VIEWS;

A value of 15 is returned. Which of the following statements is true?

Mark for Review

(1) Points

Mary has created views on 15 of her tables.

Other users have granted Mary SELECT privilege on 15 of their views.

There are 15 views in the database.

There are 15 views in Mary's schema. (*)

Incorrect Incorrect. Refer to Section 9 Lesson 3.

9. 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 for Review

(1) Points

No output will be displayed (*)

fn_index FN_INDEX

FN_INDEX

fn_index

Correct Correct

10. User JOHN wants to see the names of all the tables in his schema. He does
NOT want to see the names of any tables in other users' schemas. Which Dictionary view should he
query? Mark for Review
(1) Points

DICTIONARY

ALL_TABLES

DBA_TABLES

JOHN_TABLES

USER_TABLES (*)

Incorrect Incorrect. Refer to Section 9 Lesson 3.

Previous Page 2 of 3 Next Summary

Test: Section 9 Quiz


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

11. You want to remove the procedure NO_NEED from your schema. You
execute:

DROP PROCEDURE no_need;

Which Data Dictionary views are updated automatically?

Mark for Review

(1) Points

None of these

USER_SOURCE

USER_OBJECTS

All of the above (*)

USER_PROCEDURES
Incorrect Incorrect. Refer to Section 9 Lesson 4.

12. Procedure 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 REPLACE PROCEDURE call_ins_emp IS

BEGIN

ins_emp(99); -- this employee does not exist

ins_emp(100); -- this employee already exists

ins_emp(999); -- this employee does not exist

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An exception occurred');

END;

When call_ins_emp is executed, (assuming Auto Commit is turned on), which rows will be inserted
into the EMPLOYEES table?

Mark for Review

(1) Points

99 only (*)
All three rows will be inserted

No rows will be inserted

99 and 999

999 only

Incorrect Incorrect. Refer to Section 9 Lesson 4.

13. Which of the following is a legal location for a function call in a SQL
statement? (Choose 3) Mark for Review

(1) Points

(Choose all correct answers)

CREATE TABLE statement

WHERE clause in a DELETE statement (*)


VALUES clause of an INSERT statement (*)

The ORDER BY and GROUP BY clauses of a query (*)

Incorrect Incorrect. Refer to Section 9 Lesson 2.

14. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE


FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN
RETURN(p_salary * 2); END; Which of the following calls to DOUBLE_SAL will NOT work? Mark for
Review

(1) Points

None, they will all work (*)

SELECT last_name, double_sal(salary) FROM employees;

SELECT * FROM employees ORDER BY double_sal(salary) DESC;

SELECT * FROM employees WHERE double_sal(salary) > 20000;


UPDATE employees SET salary = double_sal(salary);

Correct Correct

15. Which of the following is a benefit of user-defined functions? (Choose 3)


Mark for Review

(1) Points

(Choose all correct answers)

They can do the same job as built-in system functions such as UPPER and ROUND.

They can often be used inside SQL statements. (*)

They can add business rules to the database and can be reused many times. (*)

They can be used in a WHERE clause to filter data and thereby increase efficiency. (*)
Incorrect Incorrect. Refer to Section 9 Lesson 2.

Previous Page 3 of 3 Summary

Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

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 Review

(1) Points

SELECT * FROM dictionary

WHERE table_name = 'USER%';

Read the online Oracle documentation at http://technet.oracle.com.

Phone the database administrator.


SELECT * FROM dict

WHERE table_name LIKE 'USER%TAB%';

(*)

SELECT * FROM dictionary

WHERE table_name = 'USER_TABLES';

Incorrect Incorrect. Refer to Section 9 Lesson 3.

2. Which of the following is NOT a benefit of the Data Dictionary? Mark for
Review

(1) Points

It allows the PL/SQL compiler to check for object existence; for example, when creating a
procedure which references a table, the PL/SQL compiler can check that the table exists.

It allows us to remind ourselves of the names of our tables, in case we have fogotten them.
It allows us to check which system privileges have been granted to us.

It will speed up the execution of SELECT statements in which the WHERE clause column is
not indexed. (*)

Incorrect Incorrect. Refer to Section 9 Lesson 3.

3. You want to display the names of all tables in your schema, but you have
forgotten which Dictionary view to query. Which of the following will remind you of the name of the
correct Dictionary view? Mark for Review

(1) Points

SELECT *

FROM USER_OBJECTS

WHERE table_name LIKE '%TABLE%';

HELP DICTIONARY

SELECT *

FROM DICTIONARY

WHERE table_name LIKE 'USER%TAB%';

(*)
SELECT *

FROM DICTIONARY

WHERE table_name LIKE 'user%table%';

SELECT *

FROM DICTIONARY

WHERE table_name LIKE 'DBA%TABLE%';

Incorrect Incorrect. Refer to Section 9 Lesson 3.

4. Procedure 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 REPLACE PROCEDURE call_ins_emp IS

BEGIN

ins_emp(99); -- this employee does not exist

ins_emp(100); -- this employee already exists

ins_emp(999); -- this employee does not exist

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An exception occurred');


END;

When call_ins_emp is executed, (assuming Auto Commit is turned on), which rows will be inserted
into the EMPLOYEES table?

Mark for Review

(1) Points

99 and 999

99 only (*)

999 only

No rows will be inserted

All three rows will be inserted

Incorrect Incorrect. Refer to Section 9 Lesson 4.


5. The following code shows the dependencies between three procedures:

CREATE PROCEDURE parent

IS BEGIN

child1;

child2;

END parent;

You now try to execute:

DROP PROCEDURE child2;

What happens?

Mark for Review

(1) Points

CHILD2 is dropped successfully. PARENT and CHILD1 are both marked INVALID.

The database automatically drops PARENT as well.

CHILD2 is dropped successfully. PARENT is marked INVALID, but CHILD1 is still valid. (*)

The database automatically drops CHILD1 as well.


You cannot drop CHILD2 because PARENT is dependent on it.

Incorrect Incorrect. Refer to Section 9 Lesson 4.

Page 1 of 3 Next Summary

Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

6. 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 privileges. What will
happen when Curly executes the procedure?

Mark for Review

(1) Points
The procedure will fail because Curly does not have the EXECUTE ANY PROCEDURE system
privilege.

The procedure will execute successfully.

The procedure will fail because Curly does not have SELECT privilege on NEWEMP.

The procedure will fail because there is no NEWEMP table in Curly's schema. (*)

Incorrect Incorrect. Refer to Section 9 Lesson 6.

7. How do you specify that you want a procedure MYPROCA to use Invoker's
Rights? Mark for Review

(1) Points

GRANT INVOKER TO myprocA;

Invoker's Rights are the default, therefore no extra code is needed.


CREATE OR REPLACE PROCEDURE myproca

AUTHID CURRENT_USER IS...

(*)

CREATE OR REPLACE PROCEDURE myproca

AUTHID OWNER IS...

ALTER PROCEDURE myproca TO INVOKER;

Incorrect Incorrect. Refer to Section 9 Lesson 6.

8. Which of the following is found in a function and not a procedure?


Mark for Review

(1) Points

Return statement in the header (*)

IN parameters
Local variables in the IS/AS section

An exception section

Correct Correct

9. You have created a function named NEWFUNC. You now change some of the
function code, and try to recreate the function by executing:

CREATE OR REPLACE FUNCTION newfunc .... ;

What happens?

Mark for Review

(1) Points

The function is automatically dropped and then recreated. (*)

The function is dropped but not recreated.

The command fails because the function already exists.


A second function named NEWFUNC_2 is created.

The command fails because you should execute: CREATE AND REPLACE ....;

Incorrect Incorrect. Refer to Section 9 Lesson 1.

10. A function must have at least one IN parameter, and must return exactly
one value. Mark for Review

(1) Points

True

False (*)

Incorrect Incorrect. Refer to Section 9 Lesson 1.

Previous Page 2 of 3 Next Summary


Test: Section 9 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct
answer.

Section 9 Quiz

(Answer all questions in this section)

11. You have created a function called USEFUL. You want every database user to
be able to invoke the function. Which command would you use to do this? Mark for Review

(1) Points

GRANT EXECUTE ON useful TO *;

GRANT useful TO PUBLIC;

GRANT EXECUTE ON useful TO PUBLIC; (*)

GRANT useful TO WORLD;

GRANT TO PUBLIC EXECUTE ON useful;


Incorrect Incorrect. Refer to Section 9 Lesson 5.

12. JOE's schema contains a COUNTRIES table. The following commands are
executed by JOE and TOM:

(JOE): GRANT SELECT ON countries TO tom WITH GRANT OPTION;

(TOM): GRANT SELECT on joe.countries TO dick WITH GRANT OPTION;

Now, JOE executes:

REVOKE SELECT ON countries FROM tom;

What happens to the grant to DICK?

Mark for Review

(1) Points

DICK also loses his SELECT privilege. (*)

Nothing. DICK's privilege is preserved even though TOM lost his privilege.

The REVOKE statement fails because JOE must remove the SELECT privilege from both users
at the same time.

The REVOKE statement fails because only the Database Administrator (not JOE) can revoke
privileges.
Correct Correct

13. Why will the following statement fail?

SELECT employee_id, tax(p_value => salary)

FROM employees;

Mark for Review

(1) Points

The data type for the tax variable does not match the data type for salary.

User-defined functions are not allowed in the SELECT clause.

The statement will execute and not fail.

Name notation is not allowed. (*)

Incorrect Incorrect. Refer to Section 9 Lesson 2.


14. User-defined functions can extend the power of SQL statements where
Oracle does not provide ready-made functions such as UPPER and LOWER. True or False?
Mark for Review

(1) Points

True (*)

False

Correct Correct

15. You want to create a function which can be used in a SQL statement. Which
one of the following can be coded within your function? Mark for Review

(1) Points

One or more IN parameters (*)

An OUT parameter
RETURN BOOLEAN

COMMIT;

Incorrect Incorrect. Refer to Section 9 Lesson 2.

Previous Page 3 of 3 Summary

You might also like