Example PL/SQL StandardThis is a featured page

Naming Standard

Names shall be formed as a concatenation of the scope prefix, followed by the data type indicator, then an underline character followed by an alphanumeric descriptive name. The alphanumeric descriptor may contain underlines for readability. Variable names are all lowercase.
<scope prefix>[constant]<data type>_<descriptive name>
Each part of the name is discussed in detail in the following sub-sections.

Scope Prefixes

The scope of a variable should be indicated with a single-letter prefix as follows:
Scope Prefix Example Comments
Global [Private] g gv_last_nm These should be rare
Local (default) l ln_nbr_students
Parameter i, o, io iv_contact_nm See best practice notes

Data Types

Data type should be appended to the scope (locality) indicator.
Data type Prefix Example Comment
Boolean b_ gb_old_enough (all types use prefixes - no suffixes)
Date (Time) d_ ld_report_date
Number n_ ln_report_sum
Varchar2 v_ lv_street_name
Cursor cur_ lcur_new_accnt
Table tab_ ltab_emp
Record rec_ grec_account
Type typ_ ltyp_brkrg_acct For both Types and Subtypes
Table Type tt_ gtt_account “TYPE gtt_account IS TABLE OF grec_account”
Assoc. Array aa[t]_ laa_myarray aat_ for the type, aa_ for the instance
Varray va[t]_ lva_ln_sched vat_ for the type, va_ for the instance
Nested Table nt[t]_ lnt_eggs ntt_ for the type, nt_ for the instance
Exception ex_ ex_exceed_credit_limit Use a name that reflects the business rule

Prefix for Constants

Constant Prefix Example Comment
Constant ?c?_ lcv_progname Local constant varchar2


gcv_yes Global constant

Coding Standard

The coding standard includes many sub-topics.

Formatting

Use three (3) space indentation. Use spaces only, no tab characters. Trim all trailing spaces on lines of text.

White Space

White space should be used to clarify the purpose and structure of the code. Here is a bad and a good example:CASE ba.title WHEN 'President' THEN 'Officer' WHEN 'Vice President' THEN 'Officer' ELSE 'Staff' END

CASE ba.title
WHEN 'President' THEN 'Officer'
WHEN 'Vice President' THEN 'Officer'
ELSE 'Staff'
END

Commas

Commas shall be at the beginning of each line:
SELECT a.record_typ
, a.plan_nr
, a.file_nm
, a.posted_dt
, a.as_of_dt
FROM my_table a

Alignment (vertical) (of lists)

Left-Align lists of columns, indented to the appropriate level
Right-Align the key words of SELECT statements:
SELECT a.record_type
, a.error_message
FROM my_table a
WHERE 1 = 0
AND a.record_type = 'THISTLE';

Capitalization

Capitalize key words and reserved words (SELECT, FROM, INTO, WHERE). Do not use CamelCase. Lowercase variable names.

Comments

Use one comment per variable to explain its purpose. Use one comment per function or procedure to explain its use.

Header Block ("Doc Block")

Begin every package with the same key information immediately after the "IS" - for example:
PACKAGE tcb_yogurt IS
--=========================================================================
-- Name: TCB_YOGURT
-- Purpose : Provide support functions for manipulating Yogurt
--
-- MODIFICATION HISTORY
-- Person Date Comments
-- --------- ---------- ------------------------------------------
-- tcox 02/14/2008 Package created
-- tcox 02/20/2008 Major refactoring, using External Tables

Margins

The right margin shall be at 75 characters.

Parentheses

Put a space on either side of every open- and close-parenthesis.
So, not ROUND(TO_NUMBER(my_column)) but rather ROUND ( TO_NUMBER ( my_column ) )


tomcox
tomcox
Latest page update: made by tomcox , May 3 2008, 3:02 AM EDT (about this update About This Update tomcox Edited by tomcox

2 words added

view changes

- complete history)
Keyword tags: standard
More Info: links to this page
There are no threads for this page.  Be the first to start a new thread.

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)