声明
[DECLARE]
BEGIN
[EXCEPTION]
END
tip:
[DECLARE]:声明开始关键字,用于声明变量
BEGIN:开始执行的标志
[EXCEPTION]:异常处理部分,发生异常时,程序流程进入此处
END:执行结束标志
声明变量
-
变量的名字 datatype
[
[not null] {:= | default} expression
]
tip:
datatype:数据类型
[not null]:非空约束
{:= | default}:当使用 not null属性时,大括号里面的内容必选一个:=代表赋值 default:表示默认值
expression:变量的值,可以是表达式 -
声明常量
常量的名字 constant datatype
[not null] {:= | default} expression -
特殊的变量常量类型%TYPE
使用已经存在的数据类型来定义新数据的数据类型
复合类型的变量
包含多个元素,可以存储多个值
- 记录类型
声明语法
type 变量名字 is record
(
[
[not null] {:= | default} expression
]
[
,[
[not null] {:= | default} expression
]…
]
)- 索引表类型(关联数组)
type 名字 is table of
{
column_type|
variable_name%TYPE|
table_name.column_name%TYPE|
table_name%ROWTYPE
}
[not null]
index by {pls_integer|binary_integer|varchar2(v_size)}
- 索引表类型(关联数组)
tip:
index by:数组下标的数据类型
- varray变长数组
type 名字 is {varray|varying array}(size_limit) of element_type [not null]
tip:
{varray|varying array}:二选一,表示数组类型
element_type:数组元素类型