Section 9

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

1.

How do
you Mark for Review
specify (1) Points
that you
want a
procedure
MYPROCA
to use
"Definer's
Rights"?

CREATE OR REPLACE PROCEDURE myproca


AUTHID CURRENT_USER IS...
GRANT DEFINER TO myprocA;
ALTER PROCEDURE myproca TO DEFINER;
Definer's Rights are the default, therefore no extra code or commands are
needed. (*)
CREATE OR REPLACE PROCEDURE myproca
AUTHID OWNER IS...

Correct

2. User BOB creates procedure MYPROC using the default Definer's Rights. BOB
then executes: Mark for Review
GRANT EXECUTE ON bob.myproc TO ted; (1) Points
When TED invokes BOB.MYPROC, whose privileges are checked?

SYSTEM's privileges
TED's privileges
PUBLIC's privileges
BOB's privileges (*)
ORACLE's privileges

Correct

3. CREATE FUNCTION get_sal (p_id employees.employee_id%TYPE)


RETURN number Mark for Review
IS (1) Points
v_sal employees.salary%TYPE := 0;
BEGIN
SELECT salary INTO v_sal
FROM employees
WHERE employee_id = p_id;
RETURN v_sal;
END get_sal;

Which variable is passed to the function and which variable is returned from the
function?
EMPLOYEE_ID is passed and SALARY is returned.
SALARY is passed and P_ID is returned.
P_ID is passed and V_SAL is returned. (*)
GET_SAL is passed and V_SAL is returned.

Incorrect. Refer to Section 9 Lesson 1.

4. Based on the following function definition:


Mark for Review
Create function annual_comp (1) Points
(sal employees.salary%type,
comm_pct IN employees.commission%type)
...

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

Select employee_id, annual_comp(salary)


from employees; (*)
Declare
Ann_comp number (6,2);
Begin
...
Ann_comp := annual_comp(1000,.2);
...
End;
Execute dbms_output.put_line(annual_comp (1000,.2));
Select employee_id, annual_comp(salary, commission_pct)
from employees;

Incorrect. Refer to Section 9 Lesson 1.

5. Which of the following is a difference between a procedure and a function?


Mark for Review
(1) Points

A function can be used inside a SQL statement, while a procedure cannot.


(*)
A procedure can include an EXCEPTION section, while a function cannot.
A procedure can return a BOOLEAN datatype, while a function cannot.
A procedure can include DML statements, but a function cannot.
A function must have at least one IN parameter, while parameters are
optional for a procedure.

Correct
6. You want to
allow user Mark for Review
JOE to query (1) Points
the
CD_DETAILS
table in your
schema.
Which
command
should you
use?

GRANT cd_details TO joe;


GRANT SELECT ON joe TO cd_details;
GRANT SELECT TO joe ON cd_details;
GRANT SELECT ON cd_details TO joe; (*)
GRANT QUERY ON cd_details TO joe;

Incorrect. Refer to Section 9 Lesson 5.

7. Your schema contains two procedures named CHILD1 and CHILD2. You now
create a third procedure by executing: Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE parent IS
BEGIN
child1;
child2;
END;
You now want user JOE to be able to invoke PARENT. Which of the following
gives JOE the privileges he needs, but no unnecessary privileges?

GRANT EXECUTE ON parent, child1, child2 TO joe;


GRANT EXECUTE ON parent TO joe;

(*)
GRANT EXECUTE ON * TO joe;
GRANT EXECUTE ON parent TO joe WITH ADMIN OPTION;
GRANT EXECUTE ON parent TO joe;
GRANT EXECUTE ON child1 TO joe;
GRANT EXECUTE ON child2 TO joe;

Incorrect. Refer to Section 9 Lesson 5.

8. JOHN and FRED are database users. JOHN grants SELECT privilege to FRED
on three of his (JOHN's) tables. Which Dictionary view should FRED query to Mark for Review
see the names of JOHN's three tables? (1) Points

DBA_TABLES
DICTIONARY
ALL_TABLES (*)
USER_TABLES
FRED_TABLES
Correct

9. User MARY executes this SQL statement:


Mark for Review
SELECT COUNT(*) FROM USER_VIEWS; (1) Points

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

There are 15 views in the database.


There are 15 views in Mary's schema. (*)
Other users have granted Mary SELECT privilege on 15 of their views.
Mary has created views on 15 of her tables.

Incorrect. Refer to Section 9 Lesson 3.

10. You want to find out how many Dictionary views will list objects in your
schema (but not in other users' schemas). Which of the following queries Mark for Review
should you use to do this? (1) Points

SELECT COUNT(*)
FROM DICTIONARY;
SELECT COUNT(*)
FROM DICTIONARY
WHERE TABLE_NAME LIKE 'USER%';

(*)
SELECT COUNT(*)
FROM DICTIONARY
WHERE TABLE_NAME NOT LIKE 'DBA%';
SELECT COUNT(*)
FROM DBA_OBJECTS
WHERE OWNER='USER';
SELECT COUNT(*)
FROM USER_DICTIONARY;

Correct
11. You need
to remove Mark for Review
procedure (1) Points
BADPROC
from your
schema.
What is
the
correct
syntax to
do this?

DELETE PROCEDURE badproc;


DROP PROGRAM badproc;
ALTER PROCEDURE badproc DISABLE;
DROP PROCEDURE badproc; (*)

Correct

12. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review
(1) Points

user_source
user_procedures
user_objects (*)
user_subprograms
user_dependencies

Correct

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)

WHERE clause in a DELETE statement (*)


CREATE TABLE statement
VALUES clause of an INSERT statement (*)
The ORDER BY and GROUP BY clauses of a query (*)

Correct

14. The following function has been created:


Mark for Review
CREATE OR REPLACE FUNCTION upd_dept (1) Points
(p_dept_id IN departments.department_id%TYPE)
RETURN NUMBER IS
BEGIN
UPDATE departments
SET department_name = 'Accounting'
WHERE department_id = p_dept_id;
RETURN p_dept_id;
END;

Which of the following will execute successfully?

SELECT upd_dept(80)
FROM dual;
SELECT upd_dept(department_id)
FROM employees;
DELETE FROM departments
WHERE department_id = upd_dept(department_id);
DELETE FROM employees
WHERE department_id = upd_dept(80);

(*)

Correct

15. 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 Mark for Review
False? (1) Points

True (*)
False

Correct
1. Which of
the Mark for Review
following (1) Points
is NOT a
benefit of
user-
defined
functions?

They can add business rules to the database and can be reused many
times.
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 be used in a WHERE clause to filter data.

Correct

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


Mark for Review
(1) Points

(Choose all correct answers)

They can add business rules to the database and can be reused many
times. (*)
They can often be used inside SQL statements. (*)
They can do the same job as built-in system functions such as UPPER and
ROUND.
They can be used in a WHERE clause to filter data and thereby increase
efficiency. (*)

Incorrect. Refer to Section 9 Lesson 2.


3. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE
FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER Mark for Review
IS BEGIN RETURN(p_salary * 2); END; Which of the following calls to (1) Points
DOUBLE_SAL will NOT work?

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


UPDATE employees SET salary = double_sal(salary);
SELECT * FROM employees ORDER BY double_sal(salary) DESC;
None, they will all work (*)
SELECT last_name, double_sal(salary) FROM employees;

Correct

4. 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 WHERE
OBJECT_TYPE='FUNCTION'; (*)
SELECT COUNT(*) FROM USER_FUNCTIONS;
SELECT COUNT(*) FROM USER_PROCEDURES;
SELECT COUNT(*) FROM USER_OBJECTS;

Incorrect. Refer to Section 9 Lesson 3.

5. JOHN and FRED are database users. JOHN grants SELECT privilege to FRED on
three of his (JOHN's) tables. Which Dictionary view should FRED query to see Mark for Review
the names of JOHN's three tables? (1) Points

DBA_TABLES
ALL_TABLES (*)
USER_TABLES
DICTIONARY
FRED_TABLES

Correct
6. User
JOHN Mark for Review
wants to (1) Points
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?

DBA_TABLES
DICTIONARY
ALL_TABLES
USER_TABLES (*)
JOHN_TABLES

Incorrect. Refer to Section 9 Lesson 3.

7. 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. Refer to Section 9 Lesson 1.

8. 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 Mark for Review
query to see the errors? (1) Points

USER_SOURCE
USER_ERRORS (*)
USER_DEPENDENCIES
USER_COMPILES
USER_OBJECTS

Correct

9. A stored function:
Mark for Review
(1) Points
cannot be called in a SQL statement.
must have at least one IN parameter.
must return one and only one value. (*)
is called as a standalone executable statement.

Correct

10. How do you specify that you want a procedure MYPROCA to use "Definer's
Rights"? Mark for Review
(1) Points

ALTER PROCEDURE myproca TO DEFINER;


CREATE OR REPLACE PROCEDURE myproca
AUTHID OWNER IS...
Definer's Rights are the default, therefore no extra code or commands are
needed. (*)
CREATE OR REPLACE PROCEDURE myproca
AUTHID CURRENT_USER IS...
GRANT DEFINER TO myprocA;

Correct

11. User SALLY's


schema Mark for Review
contains a (1) Points
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?
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. (*)

Correct

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

UNGRANT SELECT ON employees TO joe;


DENY SELECT ON employees TO joe;
ROLLBACK;
REVOKE SELECT ON employees FROM joe; (*)
GRANT UNSELECT ON employees TO joe;

Incorrect. Refer to Section 9 Lesson 5.

13. 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 Mark for Review
statement should Diane execute to allow this? (1) Points

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 TO joel;
GRANT UPDATE ON departments(location_id) TO joel;

Correct

14. The following code shows the dependencies between three procedures:
Mark for Review
CREATE PROCEDURE parent (1) Points
IS BEGIN
child1;
child2;
END parent;
You now try to execute:

DROP PROCEDURE child2;


What happens?
The database automatically drops PARENT as well.
CHILD2 is dropped successfully. PARENT and CHILD1 are both
marked INVALID.
CHILD2 is dropped successfully. PARENT is marked INVALID, but
CHILD1 is still valid. (*)
You cannot drop CHILD2 because PARENT is dependent on it.
The database automatically drops CHILD1 as well.

Correct

15. You want to see the names, modes, and data types of the formal
parameters of function MY_FUNC in your schema. How can you do this? Mark for Review
(Choose two) (1) Points

(Choose all correct answers)

Query USER_FUNCTIONS
Query USER_SOURCE (*)
DESCRIBE my_func; (*)
Query USER_PARAMETERS
SHOW PARAMETER my_func;

Correct
1. Function DOUBLE_SAL
has been created as Mark for Review
follows: CREATE OR (1) Points
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?

UPDATE employees SET salary = double_sal(salary);


SELECT last_name, double_sal(salary) FROM employees;
None, they will all work (*)
SELECT * FROM employees WHERE double_sal(salary) >
20000;
SELECT * FROM employees ORDER BY double_sal(salary)
DESC;

Correct
2. A benefit of user-defined functions is that the function can accept
any SQL or PL/SQL data type. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 9 Lesson 2.

3. Which of the following is NOT a legal location for a function call


in a SQL statement? Mark for Review
(1) Points

VALUES clause of an INSERT statement


FROM clause of a SELECT statement (*)
WHERE clause in a DELETE statement
SET clause of an UPDATE statement

Incorrect. Refer to Section 9 Lesson 2.

4. User SALLY's schema contains a NEWEMP table. Sally uses


Invoker's rights to create procedure GET_NEWEMP which Mark for Review
includes the line: (1) Points

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?

The procedure will execute successfully.


The procedure will fail because Curly does not have the
EXECUTE ANY PROCEDURE system privilege.
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. (*)

Correct

5. When must AUTHID CURRENT_USER be included in an


autonomous transaction subprogram? Mark for Review
(1) Points

When declaring Invoker's rights (*)


When declaring Definer's rights
When using GRANT on the subprogram
When using COMMIT or ROLLBACK

Correct

6. Which of
the Mark for Review
following (1) Points
is a
difference
between
a
procedure
and a
function?

A function can be used inside a SQL statement, while a procedure cannot.


(*)
A function must have at least one IN parameter, while parameters are
optional for a procedure.
A procedure can include an EXCEPTION section, while a function cannot.
A procedure can return a BOOLEAN datatype, while a function cannot.
A procedure can include DML statements, but a function cannot.

Correct

7. The following function has been created:


Mark for Review
CREATE OR REPLACE FUNCTION find_sal (1) Points
(p_emp_id IN employees.employee_id%TYPE)
RETURN NUMBER IS ...

We want to invoke this function from the following anonymous block:

DECLARE
v_mynum NUMBER(6,2);
v_mydate DATE;
BEGIN
... Line A
END;

Which of the following would you include at Line A?

v_mynum := find_sal(100); (*)


find_sal(v_mynum,100);
v_mydate := find_sal(100);
find_sal(100,v_mynum);

Correct
8. To create a function successfully,the first step is to test the code in an
anonymous block. Mark for Review
(1) Points

True
False (*)

Correct

9. Which of the following best describes the Data Dictionary?


Mark for Review
(1) Points

It is a set of tables which can be updated by any user who has the
necessary privileges.
It is an automatically managed 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 database tables which are not in any schema.

Incorrect. Refer to Section 9 Lesson 3.

10. 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.
SELECT * FROM dictionary
WHERE table_name = 'USER_TABLES';
SELECT * FROM dict
WHERE table_name LIKE 'USER%TAB%';

(*)
Phone the database administrator.

Incorrect. Refer to Section 9 Lesson 3.

11. You want


to display Mark for Review
the (1) Points
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?

SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'DBA%TABLE%';
HELP DICTIONARY
SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'USER%TAB%';

(*)
SELECT *
FROM USER_OBJECTS
WHERE table_name LIKE '%TABLE%';
SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'user%table%';

Incorrect. Refer to Section 9 Lesson 3.

12. 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 Mark for Review
would you use? (1) Points

ROLLBACK;
UNGRANT SELECT ON employees TO joe;
GRANT UNSELECT ON employees TO joe;
DENY SELECT ON employees TO joe;
REVOKE SELECT ON employees FROM joe; (*)

Correct

13. 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 TO PUBLIC EXECUTE ON useful;


GRANT useful TO WORLD;
GRANT useful TO PUBLIC;
GRANT EXECUTE ON useful TO *;
GRANT EXECUTE ON useful TO PUBLIC; (*)

Correct

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

user_errors
user_procedures
user_source (*)
user_objects
user_dependencies

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 Mark for Review
not contain an exception section. A second procedure is created as follows: (1) Points

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?

99 only (*)
999 only
No rows will be inserted
99 and 999
All three ro

Which
object Mark for Review
privilege (1) Points
can be
granted
on a
single
column
of a
table?

DROP
UPDATE (*)
CREATE
SELECT
DELETE

Incorrect. Refer to Section 9 Lesson 5.


Which of
the Mark for Review
following (1) Points
will tell
you how
many
functions
you
own?

SELECT FUNCTIONS FROM USER_OBJECTS;


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

Incorrect. Refer to Section 9 Lesson 3.


Which
Data Mark for Review
Dictionary (1) Points
view can
be used
to display
the
detailed
code of a
procedure
in your
schema?

USER_SOURCE (*)
USER_OBJECTS
USER_SUBPROGRAMS
USER_PROCEDURES
None of these
Incorrect. Refer to Section 9 Lesson 4.
Users SYS (the
DBA), TOM, Mark for Review
DICK, and (1) Points
HARRY each
have an
EMPLOYEES
table in their
schemas. SYS
creates a
procedure
DICK.SEL_EMP
using Invoker's
Rights which
contains the
following
code:

SELECT ...
FROM
EMPLOYEES ...
;

HARRY now
executes the
procedure.
Which
employees
table will be
queried?

HARRY.EMPLOYEES (*)
None of these.
DICK.EMPLOYEES
SYS.EMPLOYEES

Incorrect. Refer to Section 9 Lesson 6.


11. Why will the
following Mark for Review
statement (1) Points
fail?

SELECT
employee_id,
tax(p_value
=> salary)
FROM
employees;

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


Name notation is not allowed. (*)
The statement will execute and not fail.
The data type for the tax variable does not match the data type for salary.

Incorrect. Refer to Section 9 Lesson 2.


You have
created a Mark for Review
function (1) Points
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?

The command fails because the function already exists.


The function is dropped but not recreated.
A second function named NEWFUNC_2 is created.
The command fails because you should execute: CREATE AND REPLACE ....;
The function is automatically dropped and then recreated. (*)

Incorrect. Refer to Section 9 Lesson 1.

Which of
the Mark for Review
following (1) Points
is a
benefit of
user-
defined
functions?
(Choose
3)
(Choose all correct answers)

They can be used in a WHERE clause to filter data and thereby increase
efficiency. (*)
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.
(*)

The function
avg_ann_sal Mark for Review
returns the (1) Points
average annual
salary for a
particular
department. The
example below
is a valid use of
this function.
True or False?

SELECT
first_name,
last_name
FROM
employees
WHERE
avg_ann_sal(20)
> 15000;

True (*)
False

Examine the
following code: Mark for Review
(1) Points
CREATE
PROCEDURE
parent
IS BEGIN
child1;
child2;
EXCEPTION
WHEN
NO_DATA_FOUND
THEN NULL;
END parent;

Neither CHILD1
nor CHILD2 has
an exception
handler.
When PARENT is
invoked, CHILD1
raises a
NO_DATA_FOUND
exception. What
happens next?

CHILD1 ends abruptly; PARENT handles the exception and then ends; CHILD2 does not
execute. (*)
CHILD1 ends abruptly, PARENT handles the exception, and then CHILD2 executes.
PARENT handles the exception, and then CHILD1 continues to execute.
PARENT does not compile because you cannot use NULL; in an exception handler.
CHILD1 ends abruptly; PARENT also ends abruptly and returns an unhandled exception.
What is
wrong with Mark for Review
the (1) Points
following
code?

CREATE
FUNCTION
badfunc
(p_param
NUMBER(4))
RETURN
BOOLEAN
IS BEGIN
RETURN
(p_param >
10);
END
badfunc;

The datatype of the IN parameter cannot have a precision or scale. It must be NUMBER, not
NUMBER(4). (*)
The NUMBER datatype must have a scale as well as a precision.
P_PARAM must have a default value.
P_PARAM must be declared AFTER the RETURN clause.
RETURN (p_param > 10); is wrong because you cannot return an expression.
Which of
the Mark for Review
following (1) Points
is found in
a function
and not a
procedure?

IN parameters
Return statement in the header (*)
Local variables in the IS/AS section
An exception section
Incorrect. Refer to Section 9 Lesson 1.

You might also like