53937816-quiz-s9

14

Click here to load reader

Transcript of 53937816-quiz-s9

Page 1: 53937816-quiz-s9

SECTION 9LESSON 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 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

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 transaction subprogram may be in the same package as the calling subprogram or

may be in a separate subprogram. True or False? Mark for Review (1) Points

True

False (*)

Incorrect. Refer to Section 9 Lesson 6.

Page 2: 53937816-quiz-s9

4. Which of the following is found in a function and not a procedure? Mark for Review (1) Points

An exception section.

IN parameters.

Local variables in the IS/AS section.

Return statement in the header. (*)

Correct 5. The following function has been created:

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 anonymous block:

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

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

Correct 6. You have created a function called GET_COUNTRY_NAME which accepts a country_id as an IN

parameter and returns the name of the country. Which one of the following calls to the function will NOT

work? Mark for Review (1) Points

v_name := get_country_name(100);

DBMS_OUTPUT.PUT_LINE(get_country_name(100));

SELECT 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; Mark for Review (1) Points

Page 3: 53937816-quiz-s9

The sal parameter should specify the IN keyword.

The RETURN NUMBER has a scale and precision. (*)

There should be parentheses (brackets) around NVL(comm_pct,0)*12*sal

The END; statement should not include the function name.

Correct 8. Function MYFUNC1 has been created, but has failed to compile because it contains syntax errors.

We now try to create procedure MYPROC1 which invokes this function. Which of the following statements is

true? Mark for Review (1) Points

MYPROC1 will compile correctly, but will fail when it is executed.

MYPROC1 will compile and execute succesfully.

MYPROC1 will fail to compile because the function is invalid. (*)

MYPROC1 will compile and execute successfully, except that the call to MYFUNC1 will be treated as a comment and ignored.

Correct 9. 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, commission_pct) 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 on the procedure. True or False? Mark for Review (1) Points

True

False (*)

Incorrect. Refer to Section 9 Lesson 6. 11. Procedure p1 has a single OUT parameter of type DATE. Function f1 returns a DATE. What is the

difference between p1 and f1? Mark for Review (1) Points

p1 can be invoked from an anonymous block but f1 cannot

f1 can be used within a SQL statement but p1 cannot (*)

p1 can have as many IN parameters as needed but f1 cannot have more than two IN parameters

There is no difference because 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 False? Mark for Review (1) Points

Page 4: 53937816-quiz-s9

True

False (*)

Correct

13. A stored function: Mark for Review (1) Points

must have at least one IN parameter.

cannot be called in a SQL statement.

must return one and only one value. (*)

is called as a standalone executable statement.

Correct 14. 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 ...

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_id; 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 passed 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. (*)

Correct

LESSON 2

Page 5: 53937816-quiz-s9

1. 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

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

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

UPDATE employees SET salary = 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 functions such as UPPER and LOWER. True or False? Mark for Review (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 departments SET department_name = 'Accounting' WHERE department_id = p_dept_id; RETURN p_dept_id; END;

Which of the following will execute successfully?

Mark for Review (1) Points

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

(*)SELECT upd_dept(80) FROM dual;

Incorrect. Refer to Section 9 Lesson 2.

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

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

Page 6: 53937816-quiz-s9

They can be used in a WHERE clause to filter data.

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

They can often be used inside SQL statements.

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

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

FROM clause of a SELECT statement (*)

WHERE clause in a DELETE statement

SET clause of an UPDATE statement

VALUES clause of an INSERT statement

Correct

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 Review (1) Points

SELECT * FROM dictionary WHERE table_name LIKE USER%; Read the online Oracle documentation at http://technet.oracle.com.

SELECT * FROM dict WHERE table_name LIKE 'USER%TAB%';

(*)SELECT * FROM dictionaryWHERE table_name = 'USER_TABLES'; Phone the database administrator.

Correct

2. Which of the following 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 them.

Page 7: 53937816-quiz-s9

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. (*)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.

Correct

3. Which of the following will display how many objects of each type are in a user's schema? Mark for Review (1) Points

SELECT COUNT(*) FROM user_objects; SELECT object_type, COUNT(*)FROM user_objectsGROUP BY object_type;

(*)SELECT object_type, COUNT(*)FROM all_objectsGROUP BY object_type;DESCRIBE user_objectsGROUP 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 for Review (1) Points

fn_index

FN_INDEX

fn_index FN_INDEX

No output will be displayed (*)

Correct 5. User BOB is not a database administrator. BOB wants to see the names of all the tables in his

schema, as well as all the tables in other users' schemas which he has privileges to use. Which Data Dictionary

view would BOB query to do this? Mark for Review (1) Points

USER_TABLES

ALL_TABLES (*)

Page 8: 53937816-quiz-s9

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. Which of the following statements is true?

Mark for Review (1) Points

There are 15 views 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-view" DICTIONARY is true? Mark for 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 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.

Correct

LESSON 4

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

user_source

Page 9: 53937816-quiz-s9

user_procedures

user_objects (*)

user_dependencies

user_subprograms

Correct 2. proc_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 employees WHERE employee_id = 999; /* This SELECT will raise an exception because employee_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 ISBEGIN proc_a; DBMS_OUTPUT.PUT_LINE('proc_a was invoked');EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An exception occurred');END;

What will be displayed when proc_b is executed?

Mark for Review (1) Points

An exception occurred

(*)This SELECT failed proc_a was invoked An exception occurred This SELECT failed

This SELECT failed proc_a was invoked Nothing will be displayed

Correct 3. The database administrator has granted the DROP ANY PROCEDURE privilege to user KIM. This

allows Kim to remove other users' procedures and functions from the database. How would Kim now drop

function GET_EMP, which is owned by user MEHMET? Mark for Review (1) Points

DROP FUNCTION get_emp FROM mehmet

Page 10: 53937816-quiz-s9

DROP FUNCTION mehmet.get_emp (*)

DROP PROCEDURE mehmet.get_emp

DROP PROGRAM mehmet.get_emp

None of the above

Correct

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

user_source (*)

user_procedures

user_objects

user_dependencies

user_errors

Correct 5. You need to remove procedure BADPROC from your schema. What is the correct syntax to do this?

Mark for Review (1) Points

DELETE PROCEDURE badproc;

DROP PROGRAM badproc;

ALTER PROCEDURE badproc DISABLE;

DROP PROCEDURE badproc; (*)

Incorrect. Refer to Section 9 Lesson 4. 6. 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, which rows will be inserted into the EMPLOYEES table?

Mark for Review (1) Points

99 only (*)

99 and 999

All three rows will be inserted

Page 11: 53937816-quiz-s9

999 only

No rows will be inserted

Correct

LESSON 5

1. USERB creates a function called SEL_PROC (using Definer's Rights) which includes the statement:

SELECT ... FROM usera.employees ...;

USERC needs to execute UserB's procedure. What privileges are needed for this to work correctly? (Choose two.)

Mark for Review (1) Points (Choose all correct answers)

UserB needs SELECT on userA.employees (*)

UserC needs SELECT on userA.employees

UserC needs EXECUTE on userB.sel_proc (*)

UserA needs EXECUTE on userB.sel_proc

UserC needs EXECUTE 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 the smallest number of GRANT statements

needed to do this? Mark for Review (1) Points

1

2 (*)

3

4

8

Correct 3. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE to create indexes on

the table. Which object privilege must Colleen grant to Ayse? Mark for Review (1) Points

SELECT on EMPLOYEES

INDEX on EMPLOYEES (*)

ALTER on EMPLOYEES

CREATE on EMPLOYEES

None of the above

Correct

Page 12: 53937816-quiz-s9

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

GRANT UPDATE ON departments.location_id TO joel;

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

GRANT UPDATE 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. Svetlana 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

SELECT 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 FRED 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 able 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

LESSON 6

1. An autonomous transaction subprogram may be in a the same package as the calling subprogram or may be

in a separate subprogram. True or False? Mark for Review (1) Points

True

False (*)

Incorrect. Refer to Section 9 Lesson 6.

Page 13: 53937816-quiz-s9

2. When using Invoker's rights, the invoker needs privileges on the database objects referenced within

the subprogram, as well as GRANT privilege on the procedure. True or False? Mark for Review (1) Points

True

False (*)

Incorrect. Refer to Section 9 Lesson 6. 3. Procedure GET_EMPS includes a SELECT ... FROM 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. Refer to Section 9 Lesson 6.

4. Which of the following is the correct syntax to create a procedure using Invoker's Rights? Mark for Review (1) Points

CREATE PROCEDURE myproc IS AUTHID CURRENT_USER BEGIN ... CREATE PROCEDURE myproc AUTHID CURRENT_USER ISBEGIN ...

(*)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; 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. (*)

Page 14: 53937816-quiz-s9

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. 6. Users SYS (the DBA), TOM, DICK and 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?

Mark for Review (1) Points

SYS.EMPLOYEES

DICK.EMPLOYEES

HARRY.EMPLOYEES (*)

None of the above

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

Mark for Review (1) Points

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. (*)

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

Correct