77范文网 - 专业文章范例文档资料分享平台

oracle数据库自学文档整理资料,详细!!!(8)

来源:网络收集 时间:2019-02-15 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

5、有输入和输出的存储过程

create or replace procedure sp_pro8 (spno in number,spName out varchar2 ) is begin

select ename into spName from emp where empno = spno ; end ;

6、返回结果集的过程

create or replace procedure sp_pro9(spNo in number,p_cursor out testpackage.test_cursor) is begin

open p_cursor for select * from emp where deptno = spNo ; end; 7、布置习题

请大家编写一个存储过程,要求可以输入表名,每页显示记录数、当前页、返回总记录数,总页数,和返回的结果集。 create or replace procedure fenye

( tableName in varchar2,Pagesize in number , pageNow in number ,myrows out number , myPageCount out number,p_cursor out tespackage.test_cursor )

v_sql varchar2(1000) ;

v_begin number :=(pageNow -1)*Pagesize +1 ; v_end number := pageNow*Pagesize; begin

v_sql:='select * from (select t1.*,rownum rn from (select * from '|| tablename

||') t1 where rownum <='v_end ||') where rn >='|| v_begin ; ----打开游标

open p_cursor for v_sql ;

v_sql:='select count(1) from '||tableName ; ----执行语句并赋值

execute immediate v_sql into myrows ; if mod(myrows,Pagesize) =0 then myPageCount := myrows/Pagesize ; else

myPageCount := myrows/Pagesize + 1; end if ;

close p_cursor; end ;

---------- 7.6 异常处理

1、 no_data_found 异常 declare

v_ename emp.ename%type ; begin

select ename into v_ename from emp where empno =&gno ; dbms_output.put_line('名字:'||v_ename); exception

when no_data_found then

dbms_output.put_line('编号没有!') ;

end ;

2、case_not_found 预定义例外。

create or replace procedure sp_pro6(spno number) is v_sal emp.sal%type ; begin

select sal into v_sal from emp where empno =spno;

case when v_sal <1000 then

update emp set sal =sal +100 where empno =spno ;

case when v_sal <2000 then

update emp set sal =sal +200 where empno =spno ;

end case ; exception

when case_not_found then

dbms_output.put_line('case语句没有与'||v_sal||'相匹配的条件');

end ;

3、cursor_already_open例外。 declare

cursor emp_cursor is select ename,sal from emp; begin

open emp_cursor ;

for emp_cursor1 in emp_cursor_loop dbms_output.put_line(emp_cursor1.ename) ; end loop ; exception

when cursor_already_open then dbms_output.put_line('游标已经打开') ; end; /

4、预定义例外 invaild_cursor

当试图在不合法的游标上执行操作时,会触发该例外。

例如:试图从没有打开的游标提取数据,或是关闭没有打开的游标。 则会触发该例外。 declare

cursor emp_cursor is select ename,sal from emp; emp_record emp_cursor%rowtype ; begin

--open emp_cursor ;

fetch emp_cursor into emp_record ; dbms_output.put_line(emp_record.ename) ; close emp_cursor; exception

when invaild cursor then

dbms_output.put_line('请检查游标是否打开') ; end ;

5、预定义例外 invaild_number , too_many_rows,zero_divide

invaild_number:当输入的数据有误时,会触发该例外;

too_many_rows:当执行select into 语句时,如果返回超过了一行,则会触发该例外。

zero_divide:当执行2/0时,则会触发该例外。

Value_error:当执行赋值操作时,如果变量的长度不足以容纳实际数据,则会触发该例外。

login_denied:用户非法登陆时,会触发该例外

not_logged_on:如果用户没有登陆就执行dml操作,就会触发该例外。

Storage_error:如果超出了内存空间或是内存被损坏,就是触发该例外

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库oracle数据库自学文档整理资料,详细!!!(8)在线全文阅读。

oracle数据库自学文档整理资料,详细!!!(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/466799.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: