standardsforOracleApplicationsProgrammingusingPLSQL PDF
standardsforOracleApplicationsProgrammingusingPLSQL PDF
Abstract
This general document provides the Coding Standards which are followed in the implementation and development of components in Oracle Applications Programming using PL/SQL.
Contents
INTRODUCTION ........................................................................................................................ 4 SCOPE............................................................................................................................................ 4 OVERALL CODING STANDARDS .......................................................................................... 4 SQL CODING STANDARDS ..................................................................................................... 5 PL/SQL CODING STANDARDS ............................................................................................. 6 SQL* PLUS CODING STANDARDS ...................................................................................... 8
INTRODUCTION
The purpose of this document is to establish a standard development approach for technical object naming conventions and coding standards. This is accomplished through strict standardization of the approach. Use of coding standards will Facilitate maintenance. Improve code efficiency.
SCOPE
This document assumes objects are developed for an Oracle Applications using PL/SQL. This includes operating system directories and files.
ALL-0002
Executable code and types should be located in the APPS schema. All other database objects should be located in the custom schema. All objects in the custom schema should grant APPS the appropriate privileges. Use a consistent style of indenting and capitalization throughout a program.
Standard ALL-0006
Description Define SQL*Plus concurrent program executables to execute PL/SQL stored programs.
ALL-0007 ALL-0008
Keep all code within the first 80 characters of a line. Use spaces to align code.
Comments In general, because of the nature of global variables and concurrent program concurrency, define PL/SQL type concurrent programs using the SQL*Plus execution method. This will effectively ensure each user has his own copy of the program. This makes the code easier to read when viewing it in UNIX, where it will ultimately be installed. Some editors use TAB characters and combinations of TAB and space characters to align code. This makes the code difficult to read if using a different editor. (In TOAD, select Edit > Editor Options from the menu. Expand General Options and uncheck Insert TABs as spaces and not #9 characters and uncheck Insert mix of TAB/space for optimal fill. To validate if code is following this standard, view the code in NOTEPAD or vi and verify the alignment is intact.
SQL-0002
SQL-0003
Use synonyms to hide database links. Use EXISTS or NOT EXISTS in WHERE clauses instead of COUNT.
SQL-0004
Description Use packages when defining procedures and functions instead of defining standalone procedures and functions.
Comments Packages provide several advantages over standalone code: Global variables Modularized code Prevents the invalidating of dependent packages if just the package body is changed
PLS-0002 PLS-0003
Follow the naming standards for PL/SQL objects above. Use %TYPE and %ROWTYPE when declaring variables and parameters. Use the CONSTANT keyword in declarations when the value of an identifier is not going to change. Remove unused variables from code. Separate distinct words in an identifier name with underscores (_). Functions should only have IN parameters. Boolean functions should return either TRUE or FALSE. Functions should have only one RETURN statement.
PLS-0004
Using %TYPE and %ROWTYPE anchors will ensure variables match their corresponding database columns. Using the CONSTANT keyword will prevent accidentally changing the values via an assign statement.
PLS-0005 PLS-0006
Keep functions pure by avoiding output mode parameters (OUT and IN OUT). Avoid coding Boolean functions that return NULL. Too many return statements make code difficult to read.
Standard PLS-0010
Description Package specifications should comment programs using the template shown at the right.
PLS-0011
PLS-0012
PLS-0013
PLS-0014
Document single-line change descriptions as shown at the right, either next to the line or directly above the line.
Comments /* ** NAME ** program_name short description ** DESCRIPTION ** A paragraph or two describing the ** programs functionality. For ** function programs, this section ** should describe the return value. ** NOTES ** This section contains technical ** implementation notes. It may be ** omitted if there is nothing ** significant. ** ASSUMPTIONS ** Clearly state the assumption on ** which your program is based. ** PARAMETERS ** p_parameter1 ** This parameter... ** p_parameter2 ** This parameter... */ PROCEDURE xxx IS -- This procedure... BEGIN . . . END xxx; PACKAGE [BODY] xxx IS -- Modification History: -- By Date Description -- -------- ----------- --------------- username DD-MON-YYYY Short descrip-tion of -changes -- XX: DD-MON -- This change... . . (Changed code here.) . -- END OF CHANGES -- XX: DD-MON Description of change
Description At a minimum, each block should be commented. Blocks should be kept to a page length, approximately 60 lines of code. Use a common error package for handling errors. Use a common debug package. Use BULK COLLECT and FORALL when prudent. The main (top-level) program should have an exception handler such that no exception goes unhandled. Capitalize keywords and keep user-defined identifiers in lower-case.
Comments
If a packaged program is longer than a page, consider creating one or more private programs to encapsulate that logic.
This option may not be wise for cursors that return a lot of data. If a sub-program needs to raise an exception to the calling program, it should log the error in its exception handler and raise or re-raise an exception.
PLS-0021
Avoid using anonymous PL/SQL in SQL*Plus as it makes the script more difficult to read and leads to less modular code.
SQP-0003 SQP-0004
Modification History By Date Description -------- ----------- ------------username DD-MON-YYYY Short scription of changes