Examine the following partial code:
Which statement is correct about the unnamed block of code at the end of a package body?
A.
It generates an error because all the blocks of code in a package body must be named.
B.
It generates an error because V_TAXRATE is a public variable that is already initialized in the package specification.
C.
It acts as a package initialization block that executes once, when the package is first invoked within the user session.
D.
It acts as a package initialization block that executes each time a package subprogram is invoked within the user session and refreshes the initialized variable value.
C is correct
C
La respuesta correcta es la C, esto se cubre en la unidad de WORKING WITH PACKAGES del curso de PL/SQL ADVANCED, podemos colocar un bloque al final del cuerpo del paquete y este actuara como un inicializador de variables del package specification, este bloque se ejecutara una sola vez cuando se mande llamar el package body y generalmente siempre se colocan hasta el final del package body.
EJEMPLO
CREATE OR REPLACE PACKAGE TAXES IS
VTAX NUMBER;
…..
— DECLARE ALL PUBLIC PROCEDURES/FUNCTIONS
END TAXES;
/
CREATE OR REPLACE PACKAGE BODY TAXES IS
……
— DECLARE ALL PRIVATE VARIABLES
……
— DECLARE PUBLIC/PRIVATE PROCEDURES/FUNCTIONS
BEGIN
SELECT RATE_VALUE INTO VTAX
FROM TAX_RATES
WHERE RATE_NAME=’TAX’;
END TAXES;
/
C