存储过程和函数.doc

存储过程和函数.doc

ID:61483319

大小:42.00 KB

页数:10页

时间:2021-02-04

存储过程和函数.doc_第1页
存储过程和函数.doc_第2页
存储过程和函数.doc_第3页
存储过程和函数.doc_第4页
存储过程和函数.doc_第5页
资源描述:

《存储过程和函数.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、1、PL/SQL语句块PL/SQL语句块只适用于Oracle数据库,使用时临时保存在客户端,而不是保存在数据库。基本语法:declare变量声明、初始化begin业务处理、逻辑代码exception异常捕获end;变量声明:<变量名><类型及长度>[:=<初始值>]例:v_namevarchar2(20):=’张三’;例:见第3节2、循环语句loop循环语法:loopexitwhen表达式endloop;while循环语法:while表达式loopendloop;for循环语法:for<变量>in<变量取值范围(小值..大值,如1..1

2、00)>loopendloop;for循环的变量可不做声明及初始化。例:见第3节3、if判断语句基本语法:if<表达式>then…elseif<表达式>then…else…endif;endif;例:declarev_identitynumber(4):=0;beginloopifv_identity=1thendbms_output.put_line('v_identity=1');elseifv_identity=3thendbms_output.put_line('v_identity=3');elseifv_identity=6

3、thenexit;elsedbms_output.put_line('v_identityisnot1or3');endif;endif;endif;--注意,有多少个if就要有多少个endif结束标志。v_identity:=v_identity+1;endloop;exceptionwhenothersthendbms_output.put_line('error!');end;/4、分支case基本语法:case<变量>when常量then…when常量then…else…endcase;例:declarev_numbernumb

4、er(4):=3;v_stringvarchar(20):='abc';begincasev_numberwhen1thendbms_output.put_line('v_numberis'

5、

6、1);when2thendbms_output.put_line('v_numberis'

7、

8、2);when3thendbms_output.put_line('v_numberis'

9、

10、3);endcase;casev_stringwhen'ab'thendbms_output.put_line('v_stringis'

11、

12、'ab');when

13、'bc'thendbms_output.put_line('v_stringis'

14、

15、'bc');else--缺省匹配dbms_output.put_line('v_stringisothervalue');endcase;exceptionwhenothersthendbms_output.put_line('error!');end;/5、异常(exception)声明异常语法:<异常名>exception;抛出异常语法:raise<异常名>;捕获异常语法:when<异常名>then异常处理语句;例:declarev_inputva

16、rchar2(1):='&throw';--动态输入v_exception_1exception;--自定义异常v_exception_2exception;othersexception;--系统异常beginifv_input='1'thenraisev_exception_1;--抛出异常elseifv_input='2'thenraisev_exception_2;elseraiseothers;endif;endif;exception--捕获异常whenv_exception_1thendbms_output.put_lin

17、e('throwexception:v_exception_1');whenv_exception_2thendbms_output.put_line('throwexception:v_exception_2');whenothersthendbms_output.put_line('throwexception:others');end;/6、游标(cursor)声明游标语法:cursor<游标名>isselect语句;声明ref游标语法:<游标名>isrefcursor;打开游标语法:open<游标名>;移动游标并获取数据语法:f

18、etch<游标名>into<用于保存读取的数据的变量的名>;关闭游标语法:close<游标名>;游标属性(游标的属性必须在关闭游标之前):%isopen:判断游标是否打开%notfound:找不到数据时%f

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。