Multiple choice technology databases

what will be the output of the following block: set serveroutput on; declare a int; b int; begin a:=NULL; b:=NULL; if a< b then dbms_output.put_line('y'); else dbms_output.put_line('n'); end if; end;

  1. y

  2. n

  3. error

  4. no output

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When comparing NULL values in PL/SQL, any comparison operation (=, <, >, etc.) returns NULL (unknown), not true or false. In an IF statement, NULL is treated as false, so the condition a < b evaluates to false and the ELSE branch executes, printing 'n'. This is a fundamental NULL handling behavior in PL/SQL.

AI explanation

To answer this question, let's go through the code step by step:

  1. The statement set serveroutput on; enables the output display in Oracle.

  2. The keyword declare is used to declare variables within the block.

  3. The variables a and b of type int are declared.

  4. The value of a and b are set to NULL.

  5. The if statement checks if a is less than b. Since both a and b are NULL, the condition evaluates to NULL.

  6. In Oracle, NULL is considered an unknown value. When comparing NULL with any other value, the result is always NULL.

  7. The else part of the if statement is executed because the condition is not satisfied. It prints 'n' using the dbms_output.put_line function.

  8. Finally, the end if; marks the end of the if statement.

Based on the above explanation, the correct answer is:

Option B) n