|
| 1 | +# **Oracle SQL and PL/SQL Coding Guidelines** |
| 2 | + |
| 3 | +The main purpose of **Oracle SQL and PL/SQL Coding Guidelines** to define the standards and guidelines for Oracle PL/SQL developers. These guidelines will be maintained and reviewed frequently to improve it and reach the best practices to write, maintain and enhancement the Oracle SQL and Pl/SQL. It was created by Egyptian Programmers. |
| 4 | + |
| 5 | + ## Oracle SQL and PL/SQL Coding Guidelines |
| 6 | + |
| 7 | +1. **Introduction** |
| 8 | + - Overview |
| 9 | +2. **Naming Conventions** |
| 10 | + - Oracle Database Objects |
| 11 | + - Oracle PL/SQL Objects |
| 12 | + - File Extensions |
| 13 | + |
| 14 | +</br> |
| 15 | + |
| 16 | +## Introduction |
| 17 | + |
| 18 | +The main purpose of Oracle SQL and PL/SQL Coding Guidelines to define the standards and guidelines for Oracle PL/SQL developers. this guideline will be maintained and reviewed frequently to improve it and reach the best practices to write, maintain and enhancement the Oracle SQL and Pl/SQL code. |
| 19 | + |
| 20 | +**Naming Convention** In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation. |
| 21 | +</br> |
| 22 | +<b>Reference: </b><a href="https://en.wikipedia.org/wiki/Naming_convention_(programming)"> wikipedia</a> |
| 23 | + |
| 24 | +</br> |
| 25 | + |
| 26 | +## Naming Conventions |
| 27 | +This is the Egyptian programmers naming conventions for Oracle database objects and PL/SQL code. |
| 28 | + |
| 29 | +### Oracle Database Objects |
| 30 | +This is the standard of oracle database objects |
| 31 | +<br> |
| 32 | +##### Syntax |
| 33 | + |
| 34 | +> **[optional {module_abbr}{separator}]{prefix}{separator}{identifier_name}{separator}{suffix}** |
| 35 | +
|
| 36 | + | SEQ | Object Name | Length | Prefix | Suffix | Example | |
| 37 | + | :- | :---- | :-: | :--- | :--- | :---- | |
| 38 | + | 1 | **Tables** | - | - | - | -| |
| 39 | + | 1 | Table | 30 | | | customers, customer_headers and pos_customer_headers | |
| 40 | + | 1 | Temporary Table | 30 | | _tmp |customers_update_tmp| |
| 41 | + | 1.1 | **Table Constraints** | - | - | - | - | |
| 42 | + | 1.1.1 | Primary Key | | | _pk | customer_id_pk | |
| 43 | + | 1.1.2 | Foreign Key | | | _fk | customer_id_fk | |
| 44 | + | 1.1.3 | Check Key | | | _ck | customer_mobile_ck | |
| 45 | + | 1.1.4 | Unique Key | | | _uk | customer_mobile_uk | |
| 46 | + |1.1.5 | Index | 30 | | _idx | customer_id_idx | |
| 47 | + | 2 | Views | 30 | | _v | customers_v, customer_headers_v and pos_customer_headers_v | |
| 48 | + | 3 | Materialized Views | 30 | | _mv |customers_mv, customer_headers_mv and pos_customer_headers_mv | |
| 49 | + | 4 | **Packages** | - | - | - | - |-| |
| 50 | + | 4.1 | Packages: Table Handlers | 30 | | _pkg | customer_headers_pkg | |
| 51 | + | 4.1.1 | Insert Procedures | 30 |ins_ | | ins_customer | |
| 52 | + | 4.1.2 | Update Procedures | 30 |upd_ | | upd_customer | |
| 53 | + | 4.1.3 | Delete Procedures | 30 |del_ | | del_customer | |
| 54 | + | 4.2 | Public Packages | 30 | | _api | customer_headers_api | |
| 55 | + | 4.3 | Private Packages | 30 | | _pvt | customer_headers_pvt | |
| 56 | + | 4.4 | Wrapped Packages | 30 | | _wrap | customer_headers_wrap | |
| 57 | + | 4.5 | Procedures | 30 | | | transfer_customer | |
| 58 | + | 4.6 | Functions | 30 | | | get_customer_name | |
| 59 | + | 5 | Standalone Procedures | 30 | | | transfer_customer_proc | |
| 60 | + | 6 | Standalone Functions | 30 | | | get_customer_name_func | |
| 61 | + | 7 | Sequences | 30 | | _seq | customer_id_seq | |
| 62 | + | 8 | Synonyms | 30 | | | | |
| 63 | + | 9 | Triggers | 30 | | _trg | concate_cutomer_name_trg | |
| 64 | + | 10 | Directories | 30 | | _dir | customer_accounts_dir | |
| 65 | + | 11 | Context | 30 | | _con | customer_accounts_con | |
| 66 | + | 12 | Collection Types | - | | - | - | |
| 67 | + | 12.1 | Arrays | | r_ | _type | r_customer_type | |
| 68 | + | 12.2 | Tables | | t_ | _type | t_customer_type | |
| 69 | + | 12.3 | Objects | | o_ | _type | o_customer_type | |
| 70 | + |
| 71 | +</br> |
| 72 | + |
| 73 | +Notes: **pos** is abbreviation or short for **P**oint **O**f **S**ale, and we will use it as module abbreviation for example. |
| 74 | + |
| 75 | +</br> |
| 76 | + |
| 77 | +### Oracle PL/SQL Objects |
| 78 | +This is the standard of oracle PL/SQL objects. |
| 79 | +##### Syntax |
| 80 | + |
| 81 | +> **{scope}{prefix}{separator}{identifier_name}{separator}{suffix}** |
| 82 | +
|
| 83 | + | SEQ | Object Name | Length | scope | Prefix | Suffix | Example | |
| 84 | + | :- | :---- | :-: | :-- | :--- | :-- | :---- | |
| 85 | + | 1 | **Variables** | | | | | | |
| 86 | + | 1.1 | Global Variable | | g | _ | | g_enterprise_id | |
| 87 | + | 1.2 | Local Variable | | l | _ | | l_customer_id | |
| 88 | + | 2 | **Constants** | | | | | | |
| 89 | + | 2.1 | Global Constants | | g | c | | gc_max_discount | |
| 90 | + | 2.2 | Local Constants | | l | c | | lc_max_discount | |
| 91 | + | 3 | **Parameters** | - | | - | - | - | |
| 92 | + | 3.1 | Cursor Parameters | | | p | | p_customer | |
| 93 | + | 3.2 | In Parameters | | | p | | p_customer_id | |
| 94 | + | 3.3 | Out Parameters | | | x | | x_customer_id | |
| 95 | + | 3.4 | In/Out Parameters | | | px | | px_customer_id | |
| 96 | + | 4 | **Other Objects Definitions** | - | | - | - | - | |
| 97 | + | 4.1 | Cursors | | | cur | | cur_customers | |
| 98 | + | 4.2 | Record | | | r | type | r_customer_type | |
| 99 | + | 4.3 | Array / Table | | | t | type | t_customers_type | |
| 100 | + | 4.4 | Objects | | | o | type | o_customers_type | |
| 101 | + | 4.5 | Exceptions | | | e | | e_customer_exists | |
| 102 | + | 4.6 | Exception Number | | | en | | en_customer_exists| |
| 103 | + |
| 104 | +</br> </br> |
| 105 | +<h2>File Extensions</h2> |
| 106 | + |
| 107 | + | SEQ | Object Name | Extension | Example | Remarks | |
| 108 | + | :-: | :--- | :--- | :--- | :-------- | |
| 109 | + | 1 | **Package** | |
| 110 | + | 1.1 | Package Specification | .pks | customer_headers_api.pks | | |
| 111 | + | 1.2 | Package Body | .pkb | customer_headers_api.pkb | | |
| 112 | + | 2 | Everything else | .sql | customer_headers.sql | | |
| 113 | + |
| 114 | + |
| 115 | +</br> |
| 116 | + |
| 117 | +## Appendix |
| 118 | +The appendix section that presents elements syntax and describes it. |
| 119 | + |
| 120 | + | SEQ | Element Syntax | Element Name. | Description | |
| 121 | + | :-: | :--- | :-- | :-------- | |
| 122 | + | 1 | {separator} | Separator | | |
| 123 | + | 2 | {scope} | Scope | | |
| 124 | + | 3 | {identifier_name} | Identifier Name | | |
| 125 | + | 4 | {module_name} | Module* Name | | |
| 126 | + | 5 | {module_abbr} | Module Name | | |
| 127 | + | 6 | {table_name} | Table Name | | |
| 128 | + | 7 | {table_abbr} | Table Abbreviation | | |
| 129 | + | 8 | {column_name} | Column Name | | |
| 130 | + | 9 | {column_abbr} | Column Abbreviation | | |
| 131 | + |
| 132 | +</br> |
| 133 | + |
| 134 | +## Contributing to the guidelines |
| 135 | +We welcome new Oracle developers to join our community and contribute to the Oracle coding guidelines project. If you are interested in helping please don’t hesitate to contact on an e-mail: info@egyptianprogrammers.com |
| 136 | + |
| 137 | +</br> |
| 138 | + |
| 139 | +###### Suggestions & Issues |
| 140 | +> If you find any issue or have a great idea in mind please create an issue on <a href="https://github.com/EgyptianProgrammers/Oracle-Coding-Guidelines/issues">GitHub</a>. |
0 commit comments