Call (800) 766-1884 for Oracle support & training
Free Oracle Tips


Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance
 

Free Oracle Tips


 

HTML Text

BC Oracle tuning

Oracle training

Oracle support

Remote Oracle

 

 

   
 

Pseudocode for the Parse_String() Function
Oracle Tips by Burleson
 

Pseudocode

Itís often useful when designing a module to generate pseudocode that outlines the logical steps that the module must take. Listing 5.21 shows a very simple bit of pseudocode for the Parse_String() function.

Listing 5.21 Pseudocode for the Parse_String() function.

store the string to be parsed in a local variable;
 
enter a loop
 
   get the location of the caret inside the string;
   if there is no delimiter in the string then
      return the array to the calling procedure;
 
   store the first section of the string in the array;
 
   chop off the first section of the string;
   increment the index variable for the array;
 
if the VALUE_ERROR exception occurs then
   log an error using the system log function;

This approach is especially useful with procedures, but functions often handle some very tough problems, too. Breaking the functionality of the module down into steps is the real work when writing code. Once the logic for the function has been thoroughly defined, the code can be written without too many problems.

Comments

Used thoughtfully, comments are an excellent tool for documenting code. The best comments describe why code works the way it does instead of describing how it works. Consider the following two sample comments:

Comment A:

--
-- If the employee has been late for work less than 1% of the time,
-- grant the employee a 0.5% raise.
--
IF (nOntimePercent > 99.0) THEN
   nRaiseAmount := nRaiseAmount + 0.005;
END IF;

Comment B:

--
-- If nOntimePercent > 99 add .005 to nRaiseAmount.
--
IF (nOntimePercent > 99.0) THEN
   nRaiseAmount := nRaiseAmount + 0.005;
END IF;

Comment A explains why the code is written in a particular way. Comment B paraphrases the code but doesnít explain the business rules behind the code. There is nothing in comment B that will help you understand what business rules the code satisfies. The sample PL/SQL coding standard in Appendix D includes some guidelines about the content and location of comments.

Identifiers

Consider this example:

IF (x > 99.0) THEN
   y := y + 0.05;
END IF;

It might take you a moment to recognize this block of code as the code from the previous example, only with different variable names. While itís relatively easy to keep track of x and y in this example, when repeated several times in 200 lines of code, x and y will become painfully and hair-wrenchingly obscure.

The only time variable names like x and y are potentially meaningful is when referencing a loop control variable or the index of a PL/SQL table. Even then, itís better to give variables names related to their functions. Using meaningful identifiers is one of the easiest ways to document code.

 

             
This is an excerpt from the book "High Performance Oracle Database Automation" by Jonathan Ingram and Donald K. Burleson, Series Editor.

††
 

Oracle performance tuning software 
 
 
 
 

Oracle performance tuning book

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

   

Copyright © 1996 -  2014 by Burleson. All rights reserved.

Oracleģ is the registered trademark of Oracle Corporation. 

Hit Counter