plsql之pragma exception_init


---建立
create or replace procedure proc_exception_init
as
my_test_exception exception;
--pragma为编译器指令 exception_init有2个参数,各为异常名称和oracle错误号码,即把oracle错误号码和异常名称联系起来
--这样就可以根据异常名称在exception模块编写异常处理功能代码了
pragma exception_init(my_test_exception,-36100);

v_a pls_integer;
begin
  v_a:=1;
  if v_a=2 then
  dbms_output.put_line(v_a);
exception
  when   my_test_exception then --可以直接在exception when引用上述声明定义的my_test_exception异常,而此异常对应一个oracle错误代码即ora-xxxxx
    dbms_output.put_line('me defined exception');
end;

---exception_init第二参数的取值范围如下:
error_code
--oracle错误码可以是100或者> -10000000(但排除-1403)的任何错误代码
Error code to be associated with exception. error_code can be either 100
(the numeric code for "no data found" that "SQLCODE Function" returns) or any negative integer greater
than -10000000 except -1403 (another numeric code for "no data found").


------------下述测试oracle错误码的取值范围
---如果错误码不在上述的指定范围内,则报错
SQL> create or replace procedure proc_uniq
  2  as
  3  exception_test exception;
  4  pragma exception_init(exception_test,1);
  5  begin
  6  insert into t_unique values(1);
  7  commit;
  8  exception
  9  when exception_test then
 10  dbms_output.put_line('insert same record,please change other record');
 11  end;
 12  /
 
Warning: Procedure created with compilation errors
 
SQL> show err
Errors for PROCEDURE TBL_BCK.PROC_UNIQ:
 
LINE/COL ERROR
-------- ------------------------------------------------------------------
3/1      PLS-00701: illegal ORACLE error number 1 for PRAGMA EXCEPTION_INIT


--错误码为100就ok
SQL> create or replace procedure proc_uniq
  2  as
  3  exception_test exception;
  4  pragma exception_init(exception_test,100);
  5  begin
  6  insert into t_unique values(1);
  7  commit;
  8  exception
  9  when exception_test then
 10  dbms_output.put_line('insert same record,please change other record');
 11  end;
 12  /
 
Procedure created

--值为-10000000也报错
SQL> create or replace procedure proc_uniq
  2  as
  3  exception_test exception;
  4  pragma exception_init(exception_test,-10000000);
  5  begin
  6  insert into t_unique values(1);
  7  commit;
  8  exception
  9  when exception_test then
 10  dbms_output.put_line('insert same record,please change other record');
 11  end;
 12  /
 
Warning: Procedure created with compilation errors
 
SQL> show err
Errors for PROCEDURE TBL_BCK.PROC_UNIQ:
 
LINE/COL ERROR
-------- --------------------------------------------------------------------------
3/1      PLS-00701: illegal ORACLE error number -10000000 for PRAGMA EXCEPTION_INIT


--经测试与官方描述不一致,负数最大界限为-1000000,如果小于它,则报错,而非官方说的-10000000
SQL> create or replace procedure proc_uniq
  2  as
  3  exception_test exception;
  4  pragma exception_init(exception_test,-1000000);
  5  begin
  6  insert into t_unique values(1);
  7  commit;
  8  exception
  9  when exception_test then
 10  dbms_output.put_line('insert same record,please change other record');
 11  end;
 12  /
 
Procedure created


小结:
      1,pragma exception_init位于存储过程声明定部分
      2,真正使用在exception模块,直接引用它的异常即可,编写对应的异常处理功能代码
      3,oracle对一些常用的异常:比如插入重复值或未找到数据,已经把异常名称与错误代码联系起来,而还有大量的oracle错误代码未
        进行联系工作,此语句即此功能

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-762140/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-762140/

### 回答1: PL/SQL Developer是一款适用于Oracle数据库开发和管理的工具,它提供了丰富、高效的程序开发环境,支持快速开发和维护PL/SQL代码。此版本为PL/SQL Developer的第15个版本,支持64位的操作系统。在使用PL/SQL Developer进行开发时,可以通过它的多种功能提高开发的效率和质量,如代码自动完成、可视化调试、代码审计等,在开发和维护大型、复杂的应用程序时尤为实用。此外,PL/SQL Developer还支持多国语言,方便了不同国家的开发者进行使用。总之,PL/SQL Developer是一款强大而实用的Oracle数据库开发工具,能够使开发者更加轻松地进行PL/SQL程序设计和调试。 ### 回答2: PL/SQL Developer是一款功能强大、易于使用的集成开发环境(IDE),专门用于开发Oracle数据库应用程序,并支持64位系统。它支持在一个IDE中同时编辑、编译、调试和运行PL/SQL代码,提供了代码自动完成、语法高亮、代码折叠、版本控制等功能,让编写PL/SQL代码变得更加高效、快捷。 PL/SQL Developer还拥有强大的调试功能,可以逐行调试代码、设置断点、查看变量的值等,帮助开发人员快速定位和解决问题。同时它也支持SQL语句的编写和调试,方便开发人员进行SQL优化。 总之,PL/SQL Developer是一款强大的工具,既适用于初学者,也能够满足专业开发人员的需求,是开发Oracle数据库应用程序的不二之选。而64位支持让它可以更好地发挥性能优势,提高开发效率。 ### 回答3: PL/SQL Developer是一款针对Oracle数据库的存储过程和SQL语句编辑器。plsqldev_15_64位则是指PL/SQL Developer的版本号为15,且是64位系统的可执行文件。 PL/SQL Developer的最新版为21.0.1.2513,可支持Windows、Linux、Mac OS等多种操作系统。该软件提供了强大的编辑、调试、优化等功能,可用于编写、测试、调试Oracle数据库中的存储过程、触发器、函数等代码。同时,它还内置了许多实用的工具,如SQL解析器、依赖分析器、代码差异对比器等,方便开发人员提高开发效率。 plsqldev_15_64位版本是PL/SQL Developer 15的一个子版本,适用于运行在64位系统的电脑上。该版本相较于32位版本在访问内存等方面拥有更高的优势,能够更好地提高软件的稳定性和性能,计算机运行速度更快。 总之,PL/SQL Developer是一款强大的Oracle数据库开发工具,而plsqldev_15_64位版本则是其适用于64位系统的版本,可提供更好的性能和稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值