+ All Categories
Home > Documents > Quiz SQL 8-12

Quiz SQL 8-12

Date post: 21-Apr-2017
Category:
Upload: angeeeldust
View: 647 times
Download: 6 times
Share this document with a friend
43
Test: Handling Exceptions: Quiz Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 1 (Answer all questions in this section) 1. Which of the following is NOT an advantage of including an exception handler in a PL/SQL block? Mark for Review (1) Points Code is more readable because error-handling routines can be written in the same block in which the error occurred Prevents errors from occurring (*) Prevents errors from being propagated back to the calling environment Avoids costly and time-consuming correction of mistakes Correct 2. Which of the following best describes a PL/SQL exception? Mark for Review (1) Points An error occurs during the execution of the block, which disrupts the normal operation of the program. (*) A user enters an invalid password while trying to log on to the database. The programmer forgets to declare a cursor while writing the PL/SQL code. A compile-time error occurs because the PL/SQL code references a non-existent table. Correct 3. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL block? Mark for Review (1) Points An attempt is made to divide by zero A SELECT statement returns no rows Any other kind of exception that can occur within the block All of the above (*) None of the above
Transcript
Page 1: Quiz SQL 8-12

Test: Handling Exceptions: Quiz

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

Section 1(Answer all questions in this section)

1. Which of the following is NOT an advantage of including an exception handler in a PL/SQL block?  Mark for

Review (1) Points

Code is more readable because error-handling routines can be written in the same block in which the error occurredPrevents errors from occurring (*)Prevents errors from being propagated back to the calling environmentAvoids costly and time-consuming correction of mistakes

Correct

2. Which of the following best describes a PL/SQL exception? Mark for Review 

(1) Points

An error occurs during the execution of the block, which disrupts the normal operation of the program. (*)A user enters an invalid password while trying to log on to the database.The programmer forgets to declare a cursor while writing the PL/SQL code.A compile-time error occurs because the PL/SQL code references a non-existent table.

Correct

3. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL block?  Mark for

Review (1) Points

An attempt is made to divide by zeroA SELECT statement returns no rowsAny other kind of exception that can occur within the blockAll of the above (*)None of the above

Correct

4. Only one exception at a time can be raised during one execution of a PL/SQL block. True or False?  Mark for

Review 

Page 2: Quiz SQL 8-12

(1) Points

True (*)False

Correct

5. Which of the following EXCEPTION sections is constructed correctly? (Choose three.)  Mark for

Review (1) Points

(Choose all correct answers)

EXCEPTION     WHEN NO_DATA_FOUND THEN statement_1;     WHEN OTHERS THEN statement_2; END;

(*)EXCEPTION     WHEN TOO_MANY_ROWS THEN statement_1; END;

(*)EXCEPTION     WHEN OTHERS THEN statement_1; END;

(*)EXCEPTION     WHEN OTHERS THEN statement_1;     WHEN NO_DATA_FOUND THEN statement_2; END;

EXCEPTION     WHEN NO_DATA_FOUND THEN statement_1;     WHEN NO_DATA_FOUND THEN statement_2;     WHEN OTHERS THEN statement_3; END;

Correct

6. The following EXCEPTION section is constructed correctly. True or False?

EXCEPTION     WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND        THEN statement_1;           statement_2;              WHEN OTHERS        THEN statement_3; END;

 Mark for Review 

(1) Points

True (*)False

Page 3: Quiz SQL 8-12

Correct

7. Which of the following are NOT good practice guidelines for exception handling? (Choose two.)  Mark for

Review (1) Points

(Choose all correct answers)

Test your code with different combinations of data to see what potential errors can happen.Use an exception handler whenever there is any possibility of an error occurring.Allow exceptions to propagate back to the calling environment. (*)Handle specific named exceptions where possible, instead of relying on WHEN OTHERS.Include a WHEN OTHERS handler as the first handler in the exception section. (*)

Correct

8. Examine the following code. Why does this exception handler not follow good practice guidelines? (Choose two.)

DECLARE     v_dept_name departments.department_name%TYPE; BEGIN     SELECT department_name INTO v_dept_name FROM departments        WHERE department_id = 75; EXCEPTION     WHEN OTHERS THEN        DBMS_OUTPUT.PUT_LINE('A select returned more than one row'); END; 

 Mark for Review 

(1) Points

(Choose all correct answers)

The exception handler should test for the named exception NO_DATA_FOUND. (*)The exception section should include a WHEN TOO_MANY_ROWS exception handler. (*)You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.department_id 75 does not exist in the departments table.The exception handler should COMMIT the transaction.

Incorrect. Refer to Section 7 Lesson 1.

Test: Trapping Oracle Server Exceptions: Quiz

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

Section 1(Answer all questions in this section)

Page 4: Quiz SQL 8-12

1. Which of the following is NOT a predefined Oracle Server error? Mark for Review 

(1) Points

TOO_MANY_ROWSNO_DATA_FOUNDDUP_VAL_ON_INDEXe_sal_too_high EXCEPTION; (*)ZERO_DIVIDE

Correct

2. Which of the following best describes a predefined Oracle Server error? Mark for Review 

(1) Points

Has a standard Oracle error number but must be declared and named by the PL/SQL programmerIs not raised automatically but must be declared and raised explicitly by the PL/SQL programmerHas a standard Oracle error number and a standard name which can be referenced in the EXCEPTION section (*)Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT

Correct

3. Which kind of error can NOT be handled by PL/SQL? Mark for Review 

(1) Points

Non-predefined Oracle Server errorsUser-defined errorsPredefined Oracle Server errorsSyntax errors (*)

Correct

4. Examine the following code. At Line A, you want to raise an exception if the employee's manager_id is null. What kind of exception is this?

DECLARE     v_mgr_id employees.manager_id%TYPE; BEGIN     SELECT manager_id INTO v_mgr_id FROM employees        WHERE employee_id = 100;     IF v_mgr_id IS NULL THEN        -- Line A     END IF; ...

 Mark for Review 

(1) Points

Page 5: Quiz SQL 8-12

A NO_DATA_FOUND exceptionA user-defined exception (*)A non-predefined Oracle server exceptionA predefined Oracle Server exceptionA constraint violation

Correct

5. How would you trap Oracle Server exception ORA-01403: no data found? Mark for Review 

(1) Points

WHEN NO DATA FOUND THEN ...WHEN SQL%ROWCOUNT=0 THEN ...WHEN NO_DATA_FOUND THEN ... (*)WHEN ORA-01403 THEN ...

Correct

6. No employees exist whose salary is less than 2000. Which exception handlers would successfully trap the exception that will be raised when the following code is executed? (Choose two.)

DECLARE     v_mynum NUMBER := 10;     v_count NUMBER; BEGIN     SELECT COUNT(*) INTO v_count FROM employees        WHERE salary < 2000;     v_mynum := v_mynum / v_count; EXCEPTION ... END; 

 Mark for Review 

(1) Points

(Choose all correct answers)

NO_DATA_FOUNDZERO_DIVIDE (*)OTHERS (*)OTHERSQL%ROWCOUNT = 0

Correct

7. What is the correct syntax to associate an exception named EXCEPNAME with the non-predefined Oracle Server error ORA-02292?  Mark for

Review (1) Points

SQLCODE (-2292, excepname);

Page 6: Quiz SQL 8-12

WHEN (-2292, excepname) THEN ナPRAGMA EXCEPTION_INIT (excepname, -2292) (*)RAISE_APPLICATION_ERROR (-2292, excepname);

Correct

8. An ORA-1400 exception is raised if an attempt is made to insert a null value into a NOT NULL column. DEPARTMENT_ID is the primary key of the DEPARTMENTS table. What will happen when the following code is executed?

DECLARE     e_not_null EXCEPTION; BEGIN     PRAGMA EXCEPTION_INIT(e_not_null, -1400);     INSERT INTO departments (department_id, department_name)        VALUES(null, 'Marketing'); EXCEPTION     WHEN e_not_null THEN        DBMS_OUTPUT.PUT_LINE('Cannot be null'); END; 

 Mark for Review 

(1) Points

The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the DECLARE section. (*)The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is wrong.The code will not execute because the syntax of the INSERT statement is wrong.The exception will be raised and "Cannot be null" will be displayed.

Correct

9. Examine the following code. The UPDATE statement will raise an ORA-02291 exception.

BEGIN   UPDATE employees SET department_id = 45; EXCEPTION   WHEN OTHERS THEN    INSERT INTO error_log_table VALUES (SQLCODE); END;

What will happen when this code is executed?

 Mark for Review 

(1) Points

The code will fail because we access error message numbers by using SQLERRNUM, not SQLCODE.The code will execute and insert error number 02291 into error_log_table.The code will fail because we cannot use functions like SQLCODE directly in a SQL statement. (*)The code will fail because SQLCODE has not been declared.

Correct

10. Which type of exception MUST be explicitly raised by the PL/SQL programmer?  Mark for

Review (1) Points

Page 7: Quiz SQL 8-12

User-defined exceptions (*)Predefined Oracle server errors such as TOO_MANY_ROWSNon-predefined Oracle server errors such as ORA-01203All of the above

Correct

11. A PL/SQL block executes and an Oracle Server exception is raised. Which of the following contains the text message associated with the exception?

 Mark for Review 

(1) Points

SQL_MESSAGE_TEXTSQLERRM (*)SQLCODESQL%MESSAGE

Correct

12. Which one of the following events would implicitly raise an exception? Mark for Review 

(1) Points

An UPDATE statement modifies no rows.A SELECT statement returns exactly one row.The PL/SQL programmer mis-spells the word BEGIN as BEGAN.A database constraint is violated. (*)

Correct

Test: Trapping User-Defined Exceptions: Quiz

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

Section 1(Answer all questions in this section)

1. What is a user-defined exception? Mark for Review 

(1) Points

An exception which has a predefined Oracle error number but no predefined name.

Page 8: Quiz SQL 8-12

An exception which is not raised automatically by the Oracle server, but must be declared and raised explicitly by the PL/SQL programmer. (*)A predefined Oracle server exception such as NO_DATA_FOUND.An exception handler which the user (the programmer) includes in the EXCEPTION section.

Correct

2. What is the datatype of a user-defined exception? Mark for Review 

(1) Points

BOOLEANVARCHAR2EXCEPTION (*)NUMBERNone of the above

Correct

3. What is wrong with the following code?

BEGIN     UPDATE employees SET salary = 20000        WHERE job_id = 'CLERK';     IF SQL%ROWCOUNT = 0 THEN        RAISE NO_DATA_FOUND; -- Line A     END IF; EXCEPTION     WHEN NO_DATA_FOUND THEN        DBMS_OUTPUT.PUT_LINE('No employee was updated'); END; 

 Mark for Review 

(1) Points

You cannot explicitly raise predefined Oracle Server errors such as NO_DATA_FOUND.Line A should be: HANDLE NO_DATA_FOUNDYou cannot use SQL%ROWCOUNT in conditional control statements such as IF or CASE.NO_DATA_FOUND has not been DECLAREd.Nothing is wrong; the code will execute correctly. (*)

Correct

4. What will be displayed when the following code is executed?

DECLARE     e_myexcep EXCEPTION; BEGIN     DBMS_OUTPUT.PUT_LINE('Message 1');     RAISE e_myexcep;     DBMS_OUTPUT.PUT_LINE('Message 2'); EXCEPTION     WHEN e_myexcep THEN 

 Mark for Review 

(1) Points

Page 9: Quiz SQL 8-12

       DBMS_OUTPUT.PUT_LINE('Message 3');        RAISE e_myexcep;        DBMS_OUTPUT.PUT_LINE('Message 4'); END; 

The code will execute but will return an unhandled exception to the calling environment.

(*)The code will not execute because it contains at least one syntax error.

Message 1 Message 3

Message 1 Message 2 Message 3 Message 4

Message 1 Message 3 Message 4

Correct

5. The following line of code is correct. True or False? RAISE_APPLICATION_ERROR(-21001,'My error message');  Mark for

Review (1) Points

TrueFalse (*)

Correct

6. How are user-defined exceptions raised ? Mark for Review 

(1) Points

By PRAGMA EXCEPTION_INITBy DECLARE e_my_excep EXCEPTION;By RAISE exception_name; (*)None of the above. They are raised automatically by the Oracle server.

Correct

7. The following three steps must be performed to use a user-defined exception: - Raise the exception - Handle the exception - Declare the exception In what sequence must these steps be performed?

 Mark for Review 

(1) Points

Page 10: Quiz SQL 8-12

Handle, Raise, DeclareDeclare, Raise, Handle (*)Raise, Handle, DeclareThe steps can be performed in any order.

Correct

8. You want to display your own error message to the user. What is the correct syntax to do this?  Mark for

Review (1) Points

RAISE_APPLICATION_ERROR('My own message', -20001);RAISE_APPLICATION_ERROR(20001, 'My own message');RAISE application_error;RAISE_APPLICATION_ERROR (-20001, 'My own message'); (*)

Correct

Test: Recognizing the Scope of Exceptions: Quiz

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

Section 1(Answer all questions in this section)

1. Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised automatically in inner blocks and handled in outer blocks. True or False?

 Mark for Review 

(1) Points

True (*)False

Correct

2. Non-predefined Oracle Server errors (associated with Oracle error numbers by PRAGMA EXCEPTION_INIT) can be declared and raised in inner blocks and handled in outer blocks. True or False?

 Mark for Review 

(1) Points

TrueFalse (*)

Correct

Page 11: Quiz SQL 8-12

3. What will happen when the following code is executed? DECLARE     e_outer_excep EXCEPTION; BEGIN     DECLARE        e_inner_excep EXCEPTION;     BEGIN        RAISE e_outer_excep;     END; EXCEPTION     WHEN e_outer_excep THEN        DBMS_OUTPUT.PUT_LINE('Outer raised');     WHEN e_inner_excep THEN        DBMS_OUTPUT.PUT_LINE('Inner raised'); END; 

 Mark for Review 

(1) Points

The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)The code will propagate the e_outer_excep back to the calling environment (Application Express).The code will fail to compile because e_inner_excep was declared but never RAISEd.The code will execute successfully and 'Outer Raised' will be displayed.

Correct

4. What will happen when the following code is executed?

DECLARE     e_excep1 EXCEPTION;     e_excep2 EXCEPTION; BEGIN     RAISE e_excep1; EXCEPTION     WHEN e_excep1 THEN BEGIN        RAISE e_excep2; END; END; 

 Mark for Review 

(1) Points

It will fail to compile because e_excep1 is out of scope in the subblock.It will fail to compile because you cannot declare more than one exception in the same block.It will fail to compile because you cannot have a subblock inside an exception section.It will compile successfully and return an unhandled e_excep2 to the calling environment. (*)

Correct

5. There are three employees in department 90. What will be displayed when this code is executed?

DECLARE     v_last_name employees.last_name%TYPE; BEGIN     DBMS_OUTPUT.PUT_LINE('Message 1');     BEGIN        SELECT last_name INTO v_last_name           FROM employees WHERE department_id = 90;        DBMS_OUTPUT.PUT_LINE('Message 2');     END; 

 Mark for Review 

(1) Points

Page 12: Quiz SQL 8-12

    DBMS_OUTPUT.PUT_LINE('Message 3'); EXCEPTION     WHEN OTHERS THEN        DBMS_OUTPUT.PUT_LINE('Message 4'); END; 

Message 1 Message 3 Message 4

Message 1 Message 4

(*)Message 1

An unhandled exception will be propagated back to the calling environment.

None of the above

Correct

6. What will be displayed when the following code is executed?

<<outer>> DECLARE     v_myvar NUMBER; BEGIN     v_myvar := 25;     DECLARE        v_myvar NUMBER := 100;     BEGIN        outer.v_myvar := 30;        v_myvar := v_myvar / 0;        outer.v_myvar := 35;     END;     v_myvar := 40; EXCEPTION     WHEN ZERO_DIVIDE THEN        DBMS_OUTPUT.PUT_LINE(v_myvar); END; 

 Mark for Review 

(1) Points

25354030 (*)100

Correct

Page 13: Quiz SQL 8-12

Test: Creating Procedures: Quiz

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

Section 1(Answer all questions in this section)

1. Which of the following are characteristics of anonymous PL/SQL blocks but not PL/SQL subprograms? (Choose three.)  Mark for

Review (1) Points

(Choose all correct answers)

Are unnamed (*)Can take parametersAre stored in the databaseAre compiled every time they are executed (*)Can begin with the keyword DECLARE (*)

Correct

2. Subprograms and anonymous blocks can be called by other applications. True or False?  Mark for

Review (1) Points

TrueFalse (*)

Correct

3. Which of the following are benefits of using PL/SQL subprograms rather than anonymous blocks? (Choose three.)  Mark for

Review (1) Points

(Choose all correct answers)

Easier code maintenance (*)Stored externallyCode reuse (*)Better data security (*)Do not need to define exceptions

Correct

Page 14: Quiz SQL 8-12

4. PL/SQL subprograms, unlike anonymous blocks, are compiled each time they are executed. True or False?  Mark for

Review (1) Points

TrueFalse (*)

Correct

5. Procedures are generally used to perform what? Mark for Review 

(1) Points

A SELECT statementAn action (*)A return of valuesAll of the aboveNone of the above

Correct

6. A programmer wants to create a PL/SQL procedure named MY_PROC. What will happen when the following code is executed?

CREATE OR REPLACE PROCEDURE my_proc IS     v_empid employees.empid%TYPE; BEGIN     SELECT employee_id INTO v_empid FROM employees        WHERE region_id = 999;     DBMS_OUTPUT.PUT_LINE('The salary is: ' || v_salary); 

 Mark for Review 

(1) Points

The statement will fail because you cannot declare variables such as v_empid inside a procedure.The statement will raise a NO_DATA_FOUND exception because region_id 999 does not exist.The statement will fail because the last line of code should be END my_proc; (*)

Incorrect. Refer to Section 8 Lesson 1.

7. Which of the following keywords MUST be included in every PL/SQL procedure definition? (Choose two.)  Mark for

Review (1) Points

(Choose all correct answers)

BEGIN (*)EXCEPTIONEND (*)

Page 15: Quiz SQL 8-12

REPLACEDECLARE

Correct

8. A stored PL/SQL procedure can be invoked from which of the following?A. A PL/SQL anonymous blockB. A calling applicationC. A SELECT statement

D. Another PL/SQL procedure

 Mark for Review 

(1) Points

A and CA, B, and D (*)A and BA onlyB and C

Correct

9. A stored procedure add_dept may be invoked by the following command in Application Express. True or False?

BEGIN  add_dept;END;

 Mark for Review 

(1) Points

True (*)False

Correct

10. The following are the steps involved in creating, and later modifying and re-creating, a PL/SQL procedure in Application Express. Which step is missing?

1. Type the procedure code in the SQL Commands window2. Click on the "Save" button and save the procedure code3. Retrieve the saved code from "Saved SQL" in SQL Commands4. Modify the code in the SQL Commands window

5. Execute the code to re-create the procedure

 Mark for Review 

(1) Points

Enter parameters and data typeExe ute the procedure from USRE_SOURCE data dictionary viewExecute the code to create the procedure (*)Invoke the procedure from an anonymous block

Correct

11. When modifying procedure code, the procedure code statement must be re-executed to validate and store it in the database. True or False?  Mark for

Page 16: Quiz SQL 8-12

Review (1) Points

True (*)False

Correct

12. A nested subprogram can be called from the main procedure or from the calling environment. True or False?  Mark for

Review (1) Points

TrueFalse (*)

Correct

13. Why will the following procedure fail?

CREATE OR REPLACE PROCEDURE mainproc  ...IS  PROCEDURE subproc (...) IS BEGIN    ...BEGIN  ...    subproc (...);  ...END;

 Mark for Review 

(1) Points

Procedure main proc must use the keyword AS not ISProcedure mainproc does not need the keyword BEGINProcedure subproc does not need the keyword BEGINProcedure subproc does not have an END; statement (*)

Correct

Test: Using Parameters in Procedures: Quiz

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

Section 1(Answer all questions in this section)

1. Which of the following best describes the difference between a parameter and an argument?  Mark for

Review (1) Points

Page 17: Quiz SQL 8-12

They are both names of variables. A parameter is passed into the procedure, while an argument is passed out of the procedure.A parameter is the name of a variable, while an argument is the datatype of that variable.A parameter is a variable that accepts a value that is passed to it, while an argument is the value that is passed. (*)There is no difference; parameters and arguments are the same thing.

Correct

2. What is the correct syntax to create procedure MYPROC that accepts two number parameters X and Y?  Mark for

Review (1) Points

CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*)CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...

CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER) ナCorrect

3. Which of the following can be used as an argument for a procedure parameter?  Mark for

Review (1) Points

The name of a variableA literal valueAn expressionAll of the above (*)None of the above

Correct

4. A procedure has been created as:

CREATE PROCEDURE myproc   (p_left NUMBER, p_right NUMBER) IS BEGIN ....

You want to call the procedure from an anonymous block. Which of the following calls is valid?

 Mark for Review 

(1) Points

myproc(p_left, p_right);myproc(v_left, v_right);myproc(v_left, 30);All of the above (*)

Incorrect. Refer to Section 8 Lesson 2.

Page 18: Quiz SQL 8-12

5. What is the purpose of using parameters with stored procedures? Mark for Review 

(1) Points

They prevent the procedure from modifying data in the database.They allow values to be passed between the calling environment and the procedure. (*)They count the number of exceptions raised by the procedure.They speed up the execution of the procedure.

Correct

6. Procedure SUBPROC was created as:

CREATE PROCEDURE subproc   (p_param VARCHAR2) IS BEGIN ...

You invoke the procedure by:

DECLARE   v_param VARCHAR2(20) := 'Smith'; BEGIN   subproc(v_param); END;

Which of the following is the actual parameter?

 Mark for Review 

(1) Points

p_paramv_param (*)Smith'None of the above

Correct

7. Which one of the following statements about formal and actual parameters is true?  Mark for

Review (1) Points

Formal and actual parameters must have the same name.Formal and actual parameters must have different names.A formal parameter is declared within the called procedure, while an actual parameter is declared in the calling environment. (*)An actual parameter is declared within the called procedure.

Correct

8. Procedure TESTPROC accepts one parameter P1, whose value is up to 1000 characters in length. Which one of the following declares this parameter correctly?

 Mark for Review 

Page 19: Quiz SQL 8-12

(1) Points

CREATE PROCEDURE testproc   (p1 VARCHAR2(100) )IS BEGIN ....

CREATE PROCEDURE testproc IS   p1 VARCHAR2(100); BEGIN ....

CREATE PROCEDURE testproc DECLARE  p1 VARCHAR2(100);BEGIN ....

CREATE PROCEDURE testproc   p1 VARCHAR2IS BEGIN ....

CREATE PROCEDURE testproc   (p1 VARCHAR2)ISBEGIN ....

(*)

Incorrect. Refer to Section 8 Lesson 2.

9. You want to create a procedure which accepts a single parameter. The parameter is a number with a maximum value of 9999.99. Which of the following is a valid declaration for this parameter?

 Mark for Review 

(1) Points

(v_num NUMBER(6,2))(v_num NUMBER) (*)(v_num)(v_num NUMBER(4,2))

Correct

Test: Passing Parameters: Quiz

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

Section 1(Answer all questions in this section)

1. What are the three parameter modes for procedures? Mark for Review 

(1) Points

Page 20: Quiz SQL 8-12

IN, OUT, IN OUT (*)R(ead), W(rite), A(ppend)CONSTANT, VARIABLE, DEFAULTCOPY, NOCOPY, REF

Correct

2.  If you don't specify a mode for a parameter, what is the default mode? Mark for Review 

(1) Points

OUTIN (*)COPYDEFAULTR(ead)

Correct

3. Which of the following statements about IN OUT parameters are true? (Choose two.)  Mark for

Review (1) Points

(Choose all correct answers)

The data type for the parameter must be VARCHAR2.The parameter value passed into the subprogram is always returned unchanged to the calling environment.The parameter value can be returned as the original unchanged value. (*)The parameter value can be returned as a new value that is set within the procedure. (*)

Correct

4. When creating a procedure, where in the code must the parameters be listed?  Mark for

Review (1) Points

After the procedure name (*)After the keyword IS or ASBefore the procedure nameAfter the keyword PROCEDURE

Correct

Page 21: Quiz SQL 8-12

5. A procedure is invoked by this command:

myproc('Smith',100,5000);

What is the method of passing parameters used here?

 Mark for Review 

(1) Points

Positional (*)NamedA combination of positional and namedNone of the above

Correct

6. A procedure is invoked by this command:

myproc('Smith',salary=>5000);

What is the method of passing parameters used here?

 Mark for Review 

(1) Points

PositionalNamedA combination of positional and named (*)None of the above

Correct

7. Which kind of parameters cannot have a DEFAULT value? Mark for Review 

(1) Points

OUT (*)INCONSTANTR(ead)W(rite)

Correct

8. The following procedure has been created:

CREATE OR REPLACE PROCEDURE myproc   (p_p1 NUMBER, p_p2 VARCHAR2) IS BEGIN ...

Which one of the following calls to the procedure will NOT work?

 Mark for Review 

(1) Points

myproc(80, 'Smith');myproc(p_p1 => 80, 'Smith'); (*)

Page 22: Quiz SQL 8-12

myproc(80, p_p2 => 'Smith');myproc(p_p1 => 80, p_p2 => 'Smith');

Correct

9. Three IN parameters for procedure ADD_EMPLOYEE are defined as: (p_name VARCHAR2 , p_salary NUMBER := 1000,p_hired DATE DEFAULT SYSDATE)

The procedure is invoked by:

    add_employee('Jones');

What is the value of P_SALARY when the procedure starts to execute?

 Mark for Review 

(1) Points

NULL1000 (*)The procedure will not compile because P_SALARY should have been coded as DEFAULT 1000The call will fail because P_SALARY is a required parameter

Correct

10. What will happen when the following procedure is called as format_phone (8005551234)?

CREATE OR REPLACE PROCEDURE format_phone  (p_phone_no IN OUT VARCHAR2) ISBEGINp_phone_no := SUBSTR(p_phone_no,1,3) ||    '.' || SUBSTR(p_phone_no,4,3) ||    '.' || SUBSTR(p_phone_no,7);END format_phone;

 Mark for Review 

(1) Points

The phone number 800.555.1234 is printed to the screen.The phone number (800) 555-1234 is printed to the screen.The phone number 800.555.1234 is placed into the p_phone_no variable. (*)The procedure does not execute because the input variable is not properly declared.

Incorrect. Refer to Section 8 Lesson 3.

11. Procedure NUMPROC has been created as:

CREATE PROCEDURE numproc   (x NUMBER, y NUMBER := 100, z NUMBER) IS BEGIN ....

You want to call the procedure, passing arguments of 10 for X and 20 for Z. Which one of the following calls is correct?

 Mark for Review 

(1) Points

numproc(10,,20);numproc(x=10,z=20);

Page 23: Quiz SQL 8-12

numproc(10,z=>20); (*)numproc(x=>10,20);

Correct

Test: Creating Functions: Quiz

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

Section 1(Answer all questions in this section)

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

2. A PL/SQL function can have IN OUT parameters. True or False? Mark for Review 

(1) Points

TrueFalse (*)

Correct

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

Page 24: Quiz SQL 8-12

P_ID is passed and V_SAL is returned. (*)

Correct

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

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

Page 25: Quiz SQL 8-12

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

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

(1) Points

An exception sectionIN parametersLocal variables in the IS/AS sectionReturn statement in the header (*)

Correct

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

Correct

10. 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)ISBEGIN     RETURN (sal*12) + NVL(comm_pct,0)*12*sal;END annual_comp; 

 Mark for Review 

(1) Points

The sal parameter should specify the IN keyword.The RETURN NUMBER has a scale and precision. (*)

Page 26: Quiz SQL 8-12

There should be parentheses () around the expression: NVL(comm_pct,0)*12*salThe END; statement should not include the function name.

Correct

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

12. 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,CB,C,E,F,D,AA,B,E,F,D,C

Correct

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

Page 27: Quiz SQL 8-12

False (*)

Correct

14. 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 work without errorsThe subprogram will fail because of an error in the SELECT statement. (*)The subprogram will fail because the RETURN is not specified.The program will compile successfully.

Incorrect. Refer to Section 9 Lesson 6.

15. A function may execute more than one RETURN statement found in the body of that function. True or False?  Mark for

Review (1) Points

TrueFalse (*)

Correct

Test: Using Functions in SQL Statements: Quiz

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

Section 1(Answer all questions in this section)

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

Page 28: Quiz SQL 8-12

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. 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 statementSET clause of an UPDATE statementVALUES clause of an INSERT statement

Correct

4. 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;

Correct

Page 29: Quiz SQL 8-12

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 BOOLEANOne or more IN parameters (*)An OUT parameterCOMMIT;

Correct

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

Test: Review of Data Dictionary: Quiz

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

Section 1(Answer all questions in this section)

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

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

Page 30: Quiz SQL 8-12

Review (1) Points

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. (*)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. 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_TABLESALL_TABLES (*)DBA_TABLESUSER_TAB_COLUMNSNone of the above

Correct

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

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

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

Page 31: Quiz SQL 8-12

FN_INDEXfn_index FN_INDEXNo output will be displayed (*)

Correct

6. 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;

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

Page 32: Quiz SQL 8-12

Correct

Test: Managing Procedures and Functions: Quiz

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

Section 1(Answer all questions in this section)

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

2. 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.  Mark for

Page 33: Quiz SQL 8-12

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?

Review (1) Points

99 only (*)99 and 999All three rows will be inserted999 onlyNo rows will be inserted

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 mehmetDROP FUNCTION mehmet.get_emp (*)DROP PROCEDURE mehmet.get_empDROP PROGRAM mehmet.get_empNone of the above

Correct

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

Correct

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

Page 34: Quiz SQL 8-12

Review (1) Points

user_source (*)user_proceduresuser_objectsuser_dependenciesuser_errors

Correct

6. Which dictionary view will list all the PL/SQL subprograms in your schema? Mark for Review 

(1) Points

user_sourceuser_proceduresuser_objects (*)user_dependenciesuser_subprograms

Correct

Test: Review of Object Privileges: Quiz

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

Section 1(Answer all questions in this section)

1. 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 EMPLOYEESSELECT and EXECUTE on EMP_VIEWSELECT on EMP_VIEW (*)SELECT on EMP_VIEW and REFERENCES on EMPLOYEES

Correct

2. 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  Mark for

Page 35: Quiz SQL 8-12

Ayse? Review (1) Points

SELECT on EMPLOYEESINDEX on EMPLOYEES (*)ALTER on EMPLOYEESCREATE on EMPLOYEESNone of the above

Correct

3. 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 DEPARTMENTSEXECUTE on DEL_DEPT and DELETE on FRED.DEPARTMENTSDELETE on FRED.DEPARTMENTS

Correct

4. 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.employeesUserC needs EXECUTE on userB.sel_proc (*)UserA needs EXECUTE on userB.sel_procUserC needs EXECUTE on Userb

Correct

5. 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;

Page 36: Quiz SQL 8-12

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

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

12 (*)348

Correct

Test: Using Invoker's Rights and Autonomous Transactions: Quiz

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

Section 1(Answer all questions in this section)

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

Correct

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

Review (1) Points

Page 37: Quiz SQL 8-12

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

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

4. 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.EMPLOYEESDICK.EMPLOYEESHARRY.EMPLOYEES (*)None of the above

Correct

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

Page 38: Quiz SQL 8-12

(1) Points

TrueFalse (*)

Correct

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

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

TrueFalse (*)

Correct


Recommended