Examine the following code:
Which statement is true about the execution of the above code?
A.
It executes and displays null.
B.
It executes and the condition returns true.
C.
It executes and control goes to the else statement.
D.
It fails because no value is assigned to the v_myage variable.
C is correct
Ans :C
SQL> set serveroutput on;
SQL> declare
2 v_myage number;
3 begin
4 if v_myage
other cases:
SQL>
SQL> declare
2 v_myage varchar2;
3 begin
4 if v_myage<11 then
5 dbms_output.put_line ( 'I am a child');
6 else
7 dbms_output.put_line ( 'I am not a child');
8 end if;
9 end;
10 /
declare
v_myage varchar2;
begin
if v_myage
SQL> declare
2 v_myage varchar2(14);
3 begin
4 if v_myage
SQL> declare
2 v_myage boolean;
3 begin
4 if v_myage then
5 dbms_output.put_line ( ‘I am a child’);
6 else
7 dbms_output.put_line ( ‘I am not a child’);
8 end if;
9 end;
10 /
I am not a child
PL/SQL procedure successfully completed
SQL>
SQL> declare
2 v_myage boolean;
3 begin
4 if not v_myage then
5 dbms_output.put_line ( ‘I am a child’);
6 else
7 dbms_output.put_line ( ‘I am not a child’);
8 end if;
9 end;
10 /
I am not a child
PL/SQL procedure successfully completed
SQL>
C
Obviously C.
v_myage will be null, so program will go to else statement.
C
C