PLSQL 编码规范 下载本文

内容发布更新时间 : 2024/6/11 2:01:15星期一 下面是文章的全部内容请认真阅读。

1 PL/SQL命名规范

1.1 包命名规范

存储过程包名为大写,以“SBP_”为前缀,后跟原则上10个字母以内的英文单词或缩写,特殊情况可扩展到15个字母以内。

1.2 存储过程命名规范

存储过程分为两种,如是Procedure类型的,以“P_”为前缀;如是Funcation类型的,以“F_”为前缀。注意为大写英文字母。名称以英文单词的组合为主,每个单词的首字母为大写。

存储过程名称要求具有具体的业务含义,并且应该为动词,表示其进行一定的处理或者逻辑判断。

例如:个人帐户结息可以为:P_CalculateAccountInterest

为了具有很好的可读性,便于理解,存储过程的参数名称必须具有具体的业务含义,如an_year、an_month、ac_employeeName、ad_deathDate,不允许采用数据库中的指标名称。

参数名称首字母小写。假如参数名称为多个单词的组合,则除了第一个单词外,其余单词的首字母大写。

1.3 变量命名规则

* 表字段相关变量的定义规则:<类型名>_<字段名>

类型名:varchar2类型为“v”,number类型为“n”,date类型为“d”…… 字段名:表中字段的名称。 例如:n_aac001,v_aac002

* 函数、存储过程传入参数的定义规则:“A”+<类型名>+<注释>。

例如:an_year,ac_employeeName

* 存储过程近回参数的定义规则:“R”+<类型名>+<注释>。

例如:rn_accountAmount,rc_message ? 普通变量的定义规则:<类型名>_<注释>

注释:英文命名,小写字母开头,后面的单词用大写字母开头。

浙江网新恩普软件有限公司

内部资料 妥善保管

第1页 共10页

例如:v_name,n_days

* 记录类型的定义规则:record_<记录注释> * 记录变量的定义规则:rec_<记录注释> * 类型的定义规则:type_<类型注释> * 类型变量的定义规则:t_<类型注释>

1.4 注释编写规范

PL/SQL的注释编写,遵循plsqldoc Plug-In的文档注释规范。 遵循本规范的PL/SQL,可以通过plsqldoc Plug-In生成格式化文档。 必须编写的注释说明主要有两类,分别是包说明、过程说明。 1、包说明

在包定义后编写该包的说明,主要说明该包面向的主要业务,以及该包主要包含的业务逻辑。包说明写在包定义后,范例如下:

create or replace package Department is

-- Package with functionality related to the Dept table. -- Most functions require a p_DeptNo parameter, which -- is the value of the DeptNo column in the {#link Dept} -- table.

2、过程说明

过程说明主要说明该业务过程主要处理什么业务逻辑,其内部的主要流程的关键处理有

哪些。过程说明写在过程前面,范例如下:

-- Open a cursor to select departments in a particular order. -- #param p_cursor The cursor that will be opened for all -- Dept records in the given order

-- #param p_order The order of the Dept records. Valid values are: -- {*} 'DEPTNO' Records are ordered by DeptNo. -- {*} 'NAME' Records are ordered by name.

浙江网新恩普软件有限公司 内部资料 妥善保管 第2页 共10页

-- {*} 'LOC' Records are ordered by loc. The secondary -- sort column is DeptNo.

-- {*} NULL The result set will not be ordered -- (default).

-- #raises e_InvalidOrder Raised when the value of p_order is invalid. procedure SelectRecords(p_Cursor in out t_DeptCursor, p_Order varchar2 default null);

其中参数说明的方法是: #param <参数名称> <参数说明> 对于funcation,则返回值这样说明: #return <返回值说明>

可以采用#author 和#version 标签来表示作者和版本信息 {*}表示缩进的项目符号。 一下是支持的所有注释标签。 Tag #param #return #value #raises Description The description of a function or procedure parameter. Subsequent #param tags will be placed in one table. A description of the return value of a function. A possible value for a package variable or object type attribute. Subsequent #value tags will be placed in one table. A list of exceptions that can be raised by a program unit. Subsequent #raises tags will be placed in one table. See also hyperlink. Subsequent #see tags will be placed in one table. To link to a specific overloading of a program unit, follow the name by a semi-colon and the overload index (1-based). For example: #see employee #see department.dname;2 A text to describe the usage of the element. The author of the object. The version of the object. An explicit hyperlink. To link to a specific overloading of a program unit, follow the name by a semi-colon and the overload index (1-based). The optional description will be placed in the document. For example: #see #usage #author #version {#link [description]} or {#link 浙江网新恩普软件有限公司 内部资料 妥善保管 第3页 共10页