PLW-06002 unreachable code when using NULL;

I sometimes do something like ....

IF very-likely-condition THEN NULL; ELSE <<code to deal with the unlikely condition>> END IF; 

Which gives warning PLW-06002 with unreachable code from the PL / SQL compiler in the NULL string to set IF.

Now that I can clearly ignore the warning and / or refactoring, the IF statement is NOT, I think it reads this way better.

Does anyone know if there is another way to insert an empty statement so that I don't get a compiler warning?

EDIT:

I am not saying that I often do this ... in fact, I did it very rarely. But sometimes I think he reads this way better.

EDIT 2:

In addition, there are other scenarios where this may be true for this (for example, ignoring a specific error in the EXCEPTION block). I used IF only as a simple example to illustrate this point.

+4
source share
3 answers

It looks like it's in 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 routine

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

To recursive and weblog:

The following statements: NOT :

 IF :x = 0 THEN NULL; ELSE do_something; END IF; 

and

 IF NOT :x = 0 THEN do_something; END IF; 

If :x IS NULL, the do_something procedure will be called only in the first case . This is due to the fact that the expression NULL = 0 not TRUE and FALSE in Oracle, it is "unknown".

The correct way to overwrite the first statement:

 IF :x != 0 OR :x IS NULL THEN do_something; END IF; 

I see why in some cases we could write things like OP.

+4
source

Why do you have an empty statement? This is the smell of code. It is generally accepted that it is not easier to read with an empty if block.

Change the if condition to the opposite of what it is now:

 IF NOT very-likely-condition THEN <<code to deal with the unlikely condition>> END IF; 

If you need to do something when the condition is true, you can always add this block back. Empty blocks separate the condition from the block, which is executed when the condition is true. It also looks like you used the code in the if section and then deleted it, but were too lazy to rewrite the if condition to remove the empty statement.

Subjectively, if I were reading your code and saw an empty if block, I think you did not know what you were doing.

0
source

All Articles