You are on page 1of 10

Oracle 11G PL SQL Programming 2nd

Edition Casteel Test Bank


Visit to download the full and correct content document: https://testbankdeal.com/dow
nload/oracle-11g-pl-sql-programming-2nd-edition-casteel-test-bank/
CHAPTER 6 - FUNCTIONS

TRUE/FALSE

1. A function is quite similar to a procedure in that it is a program unit that achieves a task, can receive
input values, and returns values to the calling environment.

ANS: T PTS: 1 REF: 217

2. The main difference between functions and procedures is that a function is part of an expression.

ANS: T PTS: 1 REF: 217

3. Procedures can be used in SQL statements.

ANS: F PTS: 1 REF: 221

4. The RETURN statement can return constant values, such as a text string.

ANS: T PTS: 1 REF: 226

5. You can include multiple RETURN statements in the body of a function.

ANS: T PTS: 1 REF: 226

6. The RETURN statement in a function is used to control the flow of execution.

ANS: F PTS: 1 REF: 228

7. The term “actual parameters” refers to the parameters that are listed in the program unit.

ANS: F PTS: 1 REF: 228

8. The term “formal parameters” refers to the arguments that are used when calling or invoking the
program unit.

ANS: F PTS: 1 REF: 228

9. Formal parameters including the RETURN data type cannot include size information.

ANS: T PTS: 1 REF: 228

10. The term “passed by value” means that a pointer to the value in the actual parameter is created instead
of copying the value from the actual parameter to the formal parameter.

ANS: F PTS: 1 REF: 230

11. The term “passed by reference” means that the value is copied from the actual parameter to the formal
parameter.

ANS: F PTS: 1 REF: 230


12. It is possible to reference a data dictionary to determine what code is contained in a program unit.

ANS: T PTS: 1 REF: 236

13. The following is a correct example of the use of the DROP command.

DROP function_name;

ANS: F PTS: 1 REF: 238

MODIFIED TRUE/FALSE

1. A(n) procedure is one type of program unit that is used to accomplish one or more tasks, return none
or many values, and is used only in PL/SQL statements. _________________________

ANS: T PTS: 1 REF: 217

2. A(n) procedure is part of an expression and cannot serve an entire statement. ____________________

ANS: F, function

PTS: 1 REF: 217

3. A(n) procedure cannot be invoked in a standalone fashion. _________________________

ANS: F, function

PTS: 1 REF: 217

4. In a(n) function, the RETURN statement includes no arguments and is followed with a semicolon.
_________________________

ANS: F, procedure

PTS: 1 REF: 217

5. You cannot include data type information when declaring a formal parameter.
________________________

ANS: F, size

PTS: 1 REF: 218

6. The term passed by value implies that a pointer to the value in the actual parameter is created instead
of copying the value from the actual parameter to the formal parameter.
_________________________

ANS: F, passed by reference

PTS: 1 REF: 230

7. The term passed by reference implies that the value is copied from the actual parameter to the formal
parameter. _________________________
ANS: F, passed by value

PTS: 1 REF: 230

8. The default behaviors of value passing can be overridden by using a compiler hint named NOCOPY.
_________________________

ANS: T PTS: 1 REF: 230

9. Functions cannot be used in a(n) CHECK constraint or as a default value of a table column.
_________________________

ANS: T PTS: 1 REF: 232

10. Deleting a program unit can be accomplished by issuing a(n) DEL command.
_________________________

ANS: F, DROP

PTS: 1 REF: 238

MULTIPLE CHOICE

1. Which of the following statements is incorrect?


a. A procedure can serve as an entire statement.
b. A function is part of an expression.
c. Procedures can be used in SQL statements.
d. A function cannot serve as an entire statement.
ANS: C PTS: 1 REF: 221

2. Which of the following code fragments would not raise an error?


a. DECLARE
v_amt1 number(5,2);
v_amt2 number(3,0);
BEGIN
v_amt1 := 32.50;
v_amt2 := ROUND(v_amt1)
DBMS_OUTPUT.PUT_LINE(v_ amt2);
END;

b. DECLARE
v_amt1 number(5,2);
v_amt2 number(3,0);
BEGIN
v_amt1 := 32.50;
v_amt2 := ROUND(v_amt1,1);
DBMS_OUTPUT.PUT_LINE(v_ amt2);
END;

c. DECLARE
v_amt1 number(5,2);
v_amt2 number(3,0);
BEGIN
v_amt1 := 32.50;
v_amt2 := ROUND v_amt1, 2;
DBMS_OUTPUT.PUT_LINE(v_ amt2);
END;

d. DECLARE
v_amt1 number(5,2);
v_amt2 number(3,0);
BEGIN
v_amt1 := 32.50;
v_amt2 := ROUND[v_amt1,0];
DBMS_OUTPUT.PUT_LINE(v_ amt2);
END;

ANS: B PTS: 1 REF: 219

3. Which of the following code fragments would not raise an error?


a. CREATE OR REPLACE FUNCTION ship_calc(p_qty IN NUMBER)
IS
lv_ship_num NUMBER(5,2);
BEGIN
IF p_qty > 10 THEN
lv_ship_num := 11.00;
ELSE
lv_ship_num := 5.00;
END IF;
RETURN lv_ship_num;
END;

b. CREATE OR REPLACE ship_calc(p_qty)


RETURN NUMBER
IS
lv_ship_num NUMBER(5,2);
BEGIN
IF p_qty > 10 THEN
lv_ship_num := 11.00;
ELSE
lv_ship_num := 5.00;
ENDIF;
RETURN lv_ship_num;
END;

c. CREATE OR REPLACE FUNCTION ship_calc(p_qty IN NUMBER)


RETURN NUMBER
IS
lv_ship_num NUMBER(5,2);
BEGIN
IF p_qty > 10 THEN
lv_ship_num := 11.00;
ELSE
lv_ship_num := 5.00;
END IF;
RETURN lv_ship_num;
END;

d. CREATE OR REPLACE FUNCTION ship_calc(p_qty IN NUMBER)


RETURN NUMBER
BEGIN
IF p_qty > 10 THEN
lv_ship_num := 11.00;
ELSE
lv_ship_num := 5.00;
END IF;
RETURN lv_ship_num;
END;

ANS: C PTS: 1 REF: 218

4. At least one ____ statement must be included in a function body to instruct which value to return.
a. CREATE c. BEGIN
b. RETURN d. EXCEPTION
ANS: B PTS: 1 REF: 218

5. How many input values does the following code require?

CREATE OR REPLACE FUNCTION memfmt1_sf


(p_id IN NUMBER,
p_first IN VARCHAR2,
p_last IN VARCHAR2)
RETURN VARCHAR2
IS
lv_mem_txt VARCHAR2(35);
BEGIN
lv_mem_txt := 'Member ' ||p_id|| ' - ' ||p_first|| ' ' ||p_last;
RETURN lv_mem_txt;
END;

a. 1 c. 3
b. 2 d. 4
ANS: C PTS: 1 REF: 219

6. The following code is an example of a(n) ____.

DECLARE
lv_name_txt VARCHAR2(35);
lv_id_num NUMBER(4) := 25;
lv_first_txt VARCHAR2(15) := 'Scott';
lv_last_txt VARCHAR2(20) := 'David';
BEGIN
lv_name_txt := memfmt1_sf(lv_id_num,lv_first_txt, lv_last_txt);
DBMS_OUTPUT.PUT_LINE(lv_name_txt);
END;
a. procedure c. parameter
b. function d. anonymous block
ANS: D PTS: 1 REF: 217

7. Which of the following statements is true?


a. After IN OUT parameters are included in functions, the function can no longer be used in
SQL statements.
b. After OUT parameters are included in functions, the function can no longer be used in
SQL statements.
c. After INOUT parameters are included in functions, the function can no longer be used in
SQL statements.
d. After IN parameters are included in functions, the function can no longer be used in SQL
statements.
ANS: B PTS: 1 REF: 225

8. ____ refer to the parameters that are listed in the program unit.
a. Modes c. Procedures
b. Functions d. Formal parameters
ANS: D PTS: 1 REF: 228

9. ____ refer to the arguments that are used when calling or invoking the program unit.
a. Actual parameters c. Formal parameters
b. Functions d. Procedures
ANS: A PTS: 1 REF: 228

10. A good method to handle the size issue when declaring variables that hold values from a database table
is to use the ____ attribute to use the size of the database column.
a. NOCOPY c. << >>
b. %TYPE d. TYPE
ANS: B PTS: 1 REF: 219

11. A(n) ____ is a request a programmer includes within his or her code that asks Oracle to modify the
default processing in some manner.
a. compiler hint c. pass by reference
b. pass by value d. purity level
ANS: A PTS: 1 REF: 230

12. The term ____ is identified with a set of acronyms that indicate the restrictions on using the function.
a. compiler hint c. pass by reference
b. purity level d. pass by value
ANS: B PTS: 1 REF: 232

13. All of the following represent restrictions on functions, except ____.


a. Functions cannot modify any tables in Oracle8 and prior versions.
b. Functions cannot be used in a CHECK constraint or as a default value of a table column.
c. If used in a local operation, no reading or writing of packaged variables is allowed.
d. If used in a SELECT, VALUES, or SET clause, the function can write values to packaged
variables; otherwise, it is not allowed.
ANS: C PTS: 1 REF: 232

14. Functions used in SQL statements must meet all of the following requirements, except ____.
a. Must be a stored database object
b. Can use only OUT parameters
c. Return data types must be a database data type
d. Cannot issue ALTER SESSION or ALTER SYSTEM commands
ANS: B PTS: 1 REF: 232

15. All of the following are purity level acronyms, except ____.
a. WNDS c. WNPS
b. RINDS d. RNPS
ANS: B PTS: 1 REF: 232

16. The ____ purity level does not modify database tables.
a. WNDS c. RNPS
b. WNPS d. RNDS
ANS: A PTS: 1 REF: 232

17. Which of the following correctly creates a function that performs an update on the BB_TEST1 table?
a. CREATE OR REPLACE FUNCTION fct_test1_sf (p_num IN NUMBER)
RETURN NUMBER
IS
BEGIN
UPDATE bb_test1
SET col1 = p_num;
RETURN p_num;
END;

b. CREATE OR REPLACE FUNCTION fct_test1_sf (p_num IN NUMBER)


RETURN NUMBER
IS
BEGIN
UPDATE bb_test1;
SET col1 = p_num;
RETURN p_num;
END;

c. CREATE OR REPLACE FUNCTION fct_test1_sf (p_num)


RETURN NUMBER
IS
BEGIN
UPDATE bb_test1
RETURN p_num;
END;

d. CREATE OR REPLACE FUNCTION fct_test1_sf (p_num IN NUMBER(6))


RETURN NUMBER
IS
BEGIN
UPDATE bb_test1
SET col1 = p_num;
RETURN p_num
END

ANS: A PTS: 1 REF: 218

18. In the code below, which of the following is the parameter variable?

CREATE OR REPLACE FUNCTION fct_test1_sf (p_num IN NUMBER)


RETURN NUMBER
IS
BEGIN
UPDATE bb_test1
SET col1 = p_num;
RETURN p_num;
END;

a. bb_test1 c. p_num
b. col1 d. fct_test1_sf
ANS: C PTS: 1 REF: 218

19. The ____ command is used to view parameter information.


a. DROP c. DESC
b. SET d. OUT
ANS: C PTS: 1 REF: 236

COMPLETION

1. A(n) ____________________ cannot serve as an entire statement.

ANS: function

PTS: 1 REF: 217

2. ____________________ cannot be used in SQL statements.

ANS: Procedures

PTS: 1 REF: 221

3. The task of the ____________________ function is to use the two arguments provided, a numeric
value and the degree of rounding, and return the resulting value.

ANS: ROUND

PTS: 1 REF: 217

4. It is considered good form to return only one value from a function and to do so using the
____________________ statement.

ANS: RETURN
PTS: 1 REF: 226

5. You cannot include ____________________ information when declaring a formal parameter.

ANS: size

PTS: 1 REF: 228

6. Deleting a program unit can be accomplished by issuing a(n) ____________________ command.

ANS: DROP

PTS: 1 REF: 238

ESSAY

1. What are the main differences between a function and a procedure?

ANS:
The main difference between functions and procedures is that a function is part of an expression. It
cannot serve as an entire statement. A procedure, on the other hand, can serve as an entire statement.

PTS: 1 REF: 217

2. What are formal and actual parameters?

ANS:
The term formal parameters refers to the parameters that are listed in the program unit while the term
actual parameters refers to the arguments that are used when calling or invoking a program unit.

PTS: 1 REF: 228

3. Discuss the techniques available in PL/SQL for passing values between actual parameters and formal
parameters.

ANS:
PL/SQL uses two techniques for passing values between actual parameters and formal parameters. In
the first method, IN parameter values are passed by reference, which means a pointer to the value in
the actual parameter is created instead of copying the value from the actual parameter to the formal
parameter. In the second, OUT and IN OUT parameters are passed by value in which the value is
copied from the actual to the formal parameter.

PTS: 1 REF: 228-230

You might also like