2013-2014 Oracle Academy Database Programming with PL/SQL - Student

27
Test: Indexing Tables of Records: Quiz 1. To declare an INDEX BY table, we must first declare a type and then declare a collection variable of that type. True or False? True (*) False Correct 2. Which of the following methods can be used to reference elements of an INDEX BY table? (Choose three.) Mark for Review (1) Points (Choose all correct answers) PREVIOUS EXISTS (*) COUNT (*) FIRST (*) DROP 3. Which of the following successfully declares an INDEX BY table of records which could be used to store copies of complete rows from the departments table? Mark for Review (1) Points DECLARE TYPE t_depttab IS TABLE OF departments%ROWTYPE INDEX BY NUMBER; DECLARE TYPE t_depttab IS INDEX BY TABLE OF departments %ROWTYPE INDEX BY BINARY_INTEGER; DECLARE TYPE t_depttab IS TABLE OF departments%TYPE INDEX BY BINARY_INTEGER; DECLARE TYPE t_depttab IS TABLE OF departments%ROWTYPE INDEX BY BINARY_INTEGER; (*) Correct

description

Section 7 & 8 Quiz

Transcript of 2013-2014 Oracle Academy Database Programming with PL/SQL - Student

Test: Indexing Tables of Records: Quiz

1. To declare an INDEX BY table, we must first declare a type and then declare a collection variable of that type. True or False?

True (*)

False

Correct

2. Which of the following methods can be used to reference elements of an INDEX BY table? (Choose three.)  Mark for

Review (1) Points

(Choose all correct answers)

PREVIOUS

EXISTS (*)

COUNT (*)

FIRST (*)

DROP

3. Which of the following successfully declares an INDEX BY table of records which could be used to store copies of complete rows from the departments table?

 Mark for

Review (1) Points

DECLARE     TYPE t_depttab IS TABLE OF departments%ROWTYPE     INDEX BY NUMBER;DECLARE     TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE     INDEX BY BINARY_INTEGER;DECLARE     TYPE t_depttab IS TABLE OF departments%TYPE     INDEX BY BINARY_INTEGER;DECLARE     TYPE t_depttab IS TABLE OF departments%ROWTYPE    INDEX BY BINARY_INTEGER;

(*)

Correct

4. What is the largest number of elements (i.e., records) that an INDEX BY table of records can contain?  Mark for

Review (1) Points

100

4096

32767

Many millions of records because a BINARY_INTEGER or PLS_INTEGER can have a very large value (*)None of the above

5. Which of these PL/SQL data structures could store a complete copy of the employees table, i.e., 20 complete table rows?  Mark for

Review (1) Points

An INDEX BY table

An explicit cursor based on SELECT * FROM employees;

An INDEX BY table of records (*)

A record

Correct

6. Which of these PL/SQL data structures can NOT store a collection? Mark for

Review (1) Points

A PL/SQL record (*)

An INDEX BY table of records

An INDEX BY table indexed by BINARY_INTEGER

An INDEX BY table indexed by PLS_INTEGER

Correct

Section 7

Test: Handling Exceptions: Quiz

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 occurredAvoids costly and time-consuming correction of mistakes

Prevents errors from being propagated back to the calling environment

Prevents errors from occurring (*)

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

Review (1) Points

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

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

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

Review (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 OTHERS THEN statement_1;     WHEN NO_DATA_FOUND THEN statement_2; END;

EXCEPTION     WHEN OTHERS THEN statement_1; END;

(*)EXCEPTION     WHEN NO_DATA_FOUND THEN statement_1;     WHEN OTHERS 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;EXCEPTION     WHEN TOO_MANY_ROWS THEN statement_1; END;

(*)

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

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)

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

Include a WHEN OTHERS handler as the first handler in the exception section. (*)

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 section should include a WHEN TOO_MANY_ROWS exception handler. (*)You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.

The exception handler should COMMIT the transaction.

department_id 75 does not exist in the departments table.

The exception handler should test for the named exception NO_DATA_FOUND. (*)

Test: Trapping Oracle Server Exceptions: Quiz

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

 Mark for

Review (1) Points

e_sal_too_high EXCEPTION; (*)

ZERO_DIVIDE

NO_DATA_FOUND

TOO_MANY_ROWS

DUP_VAL_ON_INDEX

Correct

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

Review (1) Points

Has 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

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 programmer

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

Review (1) Points

Syntax errors (*)

Non-predefined Oracle Server errors

User-defined errors

Predefined Oracle Server errors

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

A user-defined exception (*)

A non-predefined Oracle server exception

A NO_DATA_FOUND exception

A predefined Oracle Server exception

A constraint violation

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

Review (1) Points

WHEN ORA-01403 THEN ...

WHEN NO_DATA_FOUND THEN ... (*)

WHEN NO DATA FOUND THEN ...

WHEN SQL%ROWCOUNT=0 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)

OTHERS (*)

OTHER

NO_DATA_FOUND

SQL%ROWCOUNT = 0

ZERO_DIVIDE (*)

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

WHEN (-2292, excepname) THEN ナ

SQLCODE (-2292, excepname);

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

 Mark for

Review (1) Points

END;

The exception will be raised and "Cannot be null" will be displayed.The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is wrong.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 the INSERT statement is wrong.

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 SQLCODE has not been declared.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. (*)

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

Review (1) Points

User-defined exceptions (*)

Predefined Oracle server errors such as TOO_MANY_ROWSNon-predefined Oracle server errors such as ORA-01203All of the above

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_TEXT

SQL%MESSAGE

SQLCODE

SQLERRM (*)

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

Review (1) Points

A SELECT statement returns exactly one row.

The PL/SQL programmer mis-spells the word BEGIN as BEGAN.An UPDATE statement modifies no rows.

A database constraint is violated. (*)

Test: Trapping User-Defined Exceptions: Quiz

1. What is a user-defined exception?

 Mark for

Review (1) Points

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 which has a predefined Oracle error number but no predefined name.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

BOOLEAN

VARCHAR2

EXCEPTION (*)

NUMBER

None of the above

Incorrect. Refer to Section 7 Lesson 3.

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

Line A should be: HANDLE NO_DATA_FOUND

You cannot explicitly raise predefined Oracle Server errors such as NO_DATA_FOUND.

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        DBMS_OUTPUT.PUT_LINE('Message 3');        RAISE e_myexcep;        DBMS_OUTPUT.PUT_LINE('Message 4'); END;

 Mark for

Review (1) Points

The code will not execute because it contains at least one syntax error.Message 1 Message 2 Message 3 Message 4The code will execute but will return an unhandled exception to the calling environment.

(*)Message 1 Message 3 Message 4Message 1 Message 3

Incorrect. Refer to Section 7 Lesson 3.

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

Review 

(1) Points

True

False (*)

Incorrect. Refer to Section 7 Lesson 3.

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

Review (1) Points

By PRAGMA EXCEPTION_INIT

By 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

Declare, Raise, Handle (*)

Handle, Raise, Declare

The steps can be performed in any order.

Raise, Handle, Declare

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

Incorrect. Refer to Section 7 Lesson 3.

Test: Recognizing the Scope of Exceptions: Quiz

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

True

False (*)

Correct

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 execute successfully and 'Outer Raised' will be displayed.The code will fail to compile because e_inner_excep was declared but never RAISEd.

Correct

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

DECLARE 

 Mark for

Review 

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

(1) Points

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. (*)It will fail to compile because you cannot declare more than one exception in the same block.It will fail to compile because e_excep1 is out of scope in the subblock.

Incorrect. Refer to Section 7 Lesson 4.

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;     DBMS_OUTPUT.PUT_LINE('Message 3'); EXCEPTION     WHEN OTHERS THEN        DBMS_OUTPUT.PUT_LINE('Message 4'); END;

 Mark for

Review (1) Points

Message 1 Message 3 Message 4Message 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; 

 Mark for

Review (1) Points

    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;

25

100

30 (*)

40

35

Incorrect. Refer to Section 7 Lesson 4.

Section 8

Test: Creating Procedures: Quiz

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)

Can take parameters

Are compiled every time they are executed (*)

Can begin with the keyword DECLARE (*)

Are unnamed (*)

Are stored in the database

Incorrect. Refer to Section 8 Lesson 1.

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

Review (1) Points

True

False (*)

Incorrect. Refer to Section 8 Lesson 1.

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)

Better data security (*)

Stored externally

Easier code maintenance (*)

Do not need to define exceptions

Code reuse (*)

Incorrect. Refer to Section 8 Lesson 1.

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

Review (1) Points

True

False (*)

Correct

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

Review (1) Points

A SELECT statement

An action (*)

A return of values

All of the above

None of the above

Incorrect. Refer to Section 8 Lesson 1.

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

 Mark for

Review 

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

(1) Points

The statement will raise a NO_DATA_FOUND exception because region_id 999 does not exist.The statement will fail because you cannot declare variables such as v_empid inside a procedure.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)

END (*)

DECLARE

BEGIN (*)

REPLACE

EXCEPTION

Incorrect. Refer to Section 8 Lesson 1.

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 statementD. Another PL/SQL procedure

 Mark for

Review (1) Points

A and C

B and C

A, B, and D (*)

A and B

A only

Incorrect. Refer to Section 8 Lesson 1.

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

BEGIN

 Mark for

Review (1) Points

  add_dept;END;

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 window5. Execute the code to re-create the procedure

 Mark for

Review (1) Points

Enter parameters and data type

Exe 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

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

True

False (*)

Incorrect. Refer to Section 8 Lesson 1.

13. Why will the following procedure fail?

CREATE OR REPLACE PROCEDURE mainproc  ...

 Mark for

Review (1) Points

IS  PROCEDURE subproc (...) IS BEGIN    ...BEGIN  ...    subproc (...);  ...END;

Procedure main proc must use the keyword AS not IS

Procedure mainproc does not need the keyword BEGIN

Procedure subproc does not need the keyword BEGIN

Procedure subproc does not have an END; statement (*)

Incorrect. Refer to Section 8 Lesson 1.

Test: Using Parameters in Procedures: Quiz

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

 Mark for

Review (1) Points

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.

Incorrect. Refer to Section 8 Lesson 2.

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 variable

A literal value

An expression

All of the above (*)

None of the above

Incorrect. Refer to Section 8 Lesson 2.

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

Correct

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.

Incorrect. Refer to Section 8 Lesson 2.

6. Procedure SUBPROC was created as:

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

 Mark for

Review (1) Points

You invoke the procedure by:

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

Which of the following is the actual parameter?

p_param

v_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 (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))

Test: Passing Parameters: Quiz

1. What are the three parameter modes for procedures?

 Mark for

Review (1) Points

IN, OUT, IN OUT (*)

R(ead), W(rite), A(ppend)

CONSTANT, VARIABLE, DEFAULT

COPY, NOCOPY, REF

Correct

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

Review (1) Points

OUT

IN (*)

COPY

DEFAULT

R(ead)

Incorrect. Refer to Section 8 Lesson 3.

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

Incorrect. Refer to Section 8 Lesson 3.

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 AS

Before the procedure name

After the keyword PROCEDURE

Incorrect. Refer to Section 8 Lesson 3.

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

Named

A combination of positional and named

None 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

Positional

Named

A combination of positional and named (*)

None of the above

Incorrect. Refer to Section 8 Lesson 3.

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

Review (1) Points

OUT (*)

IN

CONSTANT

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

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

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

Incorrect. Refer to Section 8 Lesson 3.

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

NULL

1000 (*)

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

Incorrect. Refer to Section 8 Lesson 3.

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

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

numproc(x=>10,20);