PLW-06002 unreachable code when using NULL;

oracle, plsql

Solution

Looks like this is by design. See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/controlstructures.htm#i5421

Example 4-23 Using NULL as a Placeholder When Creating a Subprogram

CREATE PROCEDURE ... AS
BEGIN  
  NULL; -- use NULL as placeholder, raises "unreachable code" if warnings enabled
END;
/

Problem

I occasionally do something like.... ``` IF very-likely-condition THEN NULL; ELSE <<code to deal with the unlikely condition>> END IF; ``` Which gives a PLW-06002 unreachable code warning from the PL/SQL compiler on the NULL line atfer the IF. Now whilst I can clearly ignore the warning and/or refactor the IF statement to be a NOT, I think it reads better this way. So does anybody know is there is another way of inserting an empty statement so that I don't get the compiler warning? EDIT: I'm not saying I do this often... in fact I'd do it very rarely. But occasionally I do think it reads better this way. EDIT 2: Plus there are other scenarios where it might be valid to do this (such as ignoring a specific error in an EXCEPTION block). I only used the IF as a simple example to illustrate the point.

Original source