Tuesday, April 27, 2010

NULL statement IN Oracle

The NULL statement explicitly specifies inaction; it does nothing other than pass control to the next statement. In a construct allowing alternative actions, the NULL statement serves as a placeholder.


The NULL statement improves readability by making the meaning and action of conditional statements clear. It tells readers that the associated alternative has not been overlooked, but that indeed no action is necessary.

Each clause in an IF statement must contain at least one executable statement. The NULL statement meets this requirement. So, you can use the NULL statement in clauses that correspond to circumstances in which no action is taken. The NULL statement and Boolean value NULL are unrelated.

Examples

IF EMP_CODE = 'M' THEN

compute_salary_manager(emp_id);

ELSIF EMP_CODE = 'P' THEN

compute_salary_programmer(emp_id);

ELSE

NULL;

END IF;



In the next example, the NULL statement shows that no action is taken for unnamed exceptions:

EXCEPTION

WHEN NO_DATA_FOUND THEN

SQLERRM:='NO DATA FOUND';

...

WHEN OTHERS THEN

NULL;