In a PL/SQL block, a variable is declared as NUMBER without an initial value. What will its value be when it is first used in the executable section of the PL/SQL block?
-
NULL
-
0
-
Results in a compilation error
-
An exception will be raised
The answer to the question is A. NULL.
When a variable is declared in PL/SQL without an initial value, it is initialized to NULL. This means that the variable has no value, and any attempt to use it will result in a NULL value.
Option B is incorrect because the value of a NUMBER variable is not automatically initialized to 0. Option C is incorrect because a compilation error will not occur if a variable is declared without an initial value. Option D is incorrect because an exception will not be raised if a variable is declared without an initial value.
Here is an example of how a NULL value is handled in PL/SQL:
DECLARE
v_number NUMBER;
BEGIN
v_number := NULL;
dbms_output.put_line(v_number); -- This will print 'NULL'
END;
As you can see, the value of v_number is printed as NULL when it is first used in the executable section of the PL/SQL block. This is because the variable was declared without an initial value, and therefore its value is NULL.
In PL/SQL, any variable declared without an explicit initial value (and without a NOT NULL constraint) is automatically initialized to NULL by default. This applies to NUMBER and other scalar types alike — PL/SQL does not default numeric variables to 0 the way some other languages do, so using it in a calculation before assignment would propagate NULL rather than error out or use zero.