1.基本的格式
2.变量的定义,有哪些
3.顺序,判断,选择,循环,异常处理
4.函数的定义(有参数,无参数),引用
5.游标的定义以及使用
----------------------------------------------------------------------
一、基本格式
declare 变量定义区域; begin code书写区域; end;
?
二、变量的声明以及使用
?????? 1.变量的数据类型
???????
number 数字型char 定长字符型varchar2 变长字符型,最大2000个字符long 变长字符型,最长2GBdate 日期型boolean 布尔型(true,false,null三者取一)
?
???? 2.变量的声明规则
?????????
字母,数字,下划线,以及$,# 必须字母开头!
?
???? 3.变量的赋值
?????????
变量名:=sql语句中的赋值 select .....into
??三、基本的流程
????????1. 条件结构????
if 逻辑判断 then code;end if;----------------------------------------------if 逻辑判断 then code;else code;end if;----------------------------------------------if 逻辑判断 then code;elseif 逻辑判断 then code;else code;end if;
???????? 2.循环
loop code; if 逻辑判断 then exit; end if;end loop;----------------------------------while 逻辑判断 loop code; end loop;-----------------------------------for count IN count_1..count_n loop code; end loop;
??????? 3.选择
case input_name when expression1 then; when expression2 then; ................................. else code;end case;
???????? 4.goto跳转
?
goto label; <<label>> code;
?????? 5.异常
when 异常 then code;
?四、用户自定义函数
?????????
create or replare function 函数名(变量参数 1. 变量名 in 类型;作为输入的变量只能传值 2. 变量名 out 类型 只能赋值 3. 变量名 in out 类型 均可) return 类型 is/as 变量名 类型; begin code;end 函数名;--------------------------函数的调用---------------------------------------1.无参函数直接函数名就可以了 例如: count_num:=get_count_num;2.有参数的直接写入就行了 例如: count_num:=get_count_num('男');
??五、游标的定义以及使用
???
create cursor 游标名 is sql的操作----------------------------------使用-------------------------------------open 游标名;fetch 游标名 into 变量1,变量2;//赋值操作------------------------------------------open 游标名;fetch 游标名 into 变量1,变量2;//赋值操作while 游标名%found loop fetch 游标名 into 变量1,变量2;//赋值操作 code; end loop;close 游标名;-------------------------%found 判断是否存在数据%isopen 判断是否游标开关状态
?游标标量的定义
?
type 游标变量isref cursor return 游标 (强类型)/ref cursor 游标(弱类型)
?
?