05 August 2010

Explicitly assign NULL to variable? Question on 4 August Quiz(1284)

A few players have written to me suggesting that one of the choices I scored as correct was incorrect because I never explicitly assigned a value of NULL to the l_value variable:
DECLARE
  l_value   NUMBER;
  l_count   PLS_INTEGER;
BEGIN
  EXECUTE IMMEDIATE 'update my_table set my_column = :value' USING l_value;

  SELECT COUNT (*)
    INTO l_count
    FROM my_table
   WHERE my_column IS NULL;

  DBMS_OUTPUT.put_line (l_count);

  ROLLBACK;
END;
In fact, the default behavior in PL/SQL is to automatically initialize the value of your variable (when appropriate, by datatype) to NULL. Therefore, I did not need to explicitly make this assignment.

No comments:

Post a Comment