tags:

views:

285

answers:

4

what is the default value of a variable (VARCHAR2) at the time of declaration in PL SQL? Can i check it against NULL once after i declare a variable?

+2  A: 

Defaults are NULL, you can use IS NULL or IS NOT NULL.

Andrew from NZSG
+9  A: 

Variables are default initialized with NULL.

You can change that, for example:

create procedure show1
as
  l_start varchar2(10) := 'Hello';
begin
  if l_start is not null then 
    ....
  end if;
end;
/

You can also declare variables as not nullable:

create procedure show2
as
  l_start varchar2(10) not null := 'Hello';
begin
  null;
end;
/
tuinstoel
A: 

tuinstoel is correct.

One addition: Don't be fooled into trying "ls_my_variable = NULL" as comparing with NULL always returns FALSE. Always use "ls_my_variable IS NULL" or "IS NOT NULL".

darreljnz
A: 

And another small addition: if you're dealing with BLOBs (or CLOBS), "empty" is not the same as null. See the Oracle large objects manual if you need to.

Jim Hudson