Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

PL/SQL NULL operator Tips

Oracle Database Tips by Donald BurlesonMay 21, 2015

 

 Sometimes PL/SQL requires a code statement when you may not have anything to execute. Use of a nonsense statement is possible, but why have the server calculate or compare a value for no reason. This is when you use the NULL statement .

Remember that one of the requirements of the GOTO statement is that there is a least one line of code after the label.

SQL> declare
2 n_num number := 5;
3 begin
4 goto then_clause;
5 n_num := 3;
6 <<then_clause>>
7 end;
8 /
end;
*
ERROR at line 7:
ORA-06550: line 7, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:

What if you want to end the code block? You could add a "nonsense" code line. A nonsense code line is a piece of code that never performs any action.

Line 7 in the example below is a nonsense code example.

SQL> declare
2 n_num number := 5;
3 begin
4 goto then_clause;
5 n_num := 3;
6 <<then_clause>>
7 if 4=7 then n_num := 5; end if;
8 end;
9 /

PL/SQL procedure successfully completed.

As we see, line 7 will never execute (4 will never equal 7) but the server will have to compare 4=7 every time it hits that statement. It is better to just use the NULL statement .

SQL> declare
2 n_num number := 5;
3 begin
4 goto then_clause;
5 n_num := 3;
6 <<then_clause>>
7 null;
8 end;
9 /

PL/SQL procedure successfully completed.

The NULL statement can also be used to iteratively create a large section of code. Many developers like to build complicated code segments by building the skeleton (or stems) and then expanding each section one piece at a time, compiling and testing at each step.

SQL> declare
2 n_numb number := 4;
3 begin
4 -- check for valid value
5 begin
6 if n_numb < 0 AND n_numb > 10
7 then goto invalid_number;
8 end if;
9 end;
10 -- compute the requirements
11 begin
12 end;
13 -- handle invalid numbers
14 <<invalid_number>>
15 begin
16 end;
17 end;
18 /
end;
*
ERROR at line 12:
ORA-06550: line 12, column 3:
PLS-00103: Encountered the symbol "END" when expecting one of the following: …

The PL/SQL engine does not like the BEGIN and END statements on lines 11 and 12. It will have the same problem with lines 15 and 16. Use the NULL statement to allow this partially completed code to compile and execute.

SQL> declare
2 n_numb number := 4;
3 begin
4 -- check for valid value
5 begin
6 if n_numb < 0 AND n_numb > 10
7 then goto invalid_number;
8 end if;
9 end;
10 -- compute the requirements
11 begin
12 null;
13 end;
14 -- handle invalid numbers
15 <<invalid_number>>
16 begin
17 null;
18 end;
19 end;
20 /

Like the IF/THEN statement, the LOOP is another common flow control structure that all programming languages implement. PL/SQL implements three loop structures; the endless loop, the WHILE loop and the FOR loop . The loop boundaries are defined by the key words LOOP and END LOOP.

These never-ending WHILE loops are referred to as "indeterminate loops " because they continue to loop forever until a condition causes the loop to exit. This is in contrast to a FOR loop, a "determinate loop " that executes for a specified number of iterations.

   
Oracle Training from Don Burleson 

The best on site "Oracle training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

Oracle training
 
 


 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster