当前位置:  数据库>oracle

Oracle编译时警告

    来源: 互联网  发布时间:2017-06-18

    本文导语: Compiler Warnings 编译器警告 Oracle 10g allows you to enable compile-time warnings that are useful to identify potential run-time problems in your programs. These warnings are not serious enough to raise an exception at compile time, but may cause run-time errors or poor performance.To enable t...

Compiler Warnings 编译器警告

Oracle 10g allows you to enable compile-time warnings that are useful to identify potential run-time problems in your programs. These warnings are not serious enough to raise an exception at compile time, but may cause run-time errors or poor performance.
To enable these warnings globally for your database, the administrator needs to set the database initialization parameter plsql_warnings either in the parameter file or dynamically with an ALTER SYSTEM SET PLSQL_WARNINGS statement. To enable warnings in only your session, use an ALTER SESSION SET PLSQL_WARNINGS statement. The setting string is a comma delimited list of settings.

Oracle 10g开始可以启用编译时警告来发现程序运行时异常。这些警告在编译时不足以抛出异常,但是却会在运行时造成错误或低性能。
需要DBA全局开启编译时警告时,可在参数文件指定参数plsql_warnings或者通过ALTER SYSTEM SET PLSQL_WARNINGS语句动态设置。
如果只是在会话中启用可使用ALTER SESSION SET PLSQL_WARNINGS语句。
该设置由逗号分隔。

The syntax for each setting is:
语法如下:

'[ENABLE | DISABLE | ERROR]:[ALL | SEVERE | INFORMATIONAL | PERFORMANCE | warning_number]'
To enable all warning messages execute:

例如:

ALTER SYSTEM SET plsql_warnings = 'enable:all';
To enable all severe and performance messages execute:  --启用所有严重和性能警告

ALTER SYSTEM SET plsql_warnings = 'enable:severe'
        ,'enable:performance';
To enable all warning messages except message 06002, execute:  --启用除了06002以外所有警告信息

ALTER SYSTEM SET plsql_warnings = 'enable:all'
        ,'disable:06002';
Alternatively, you can use the built-in package dbms_warnings to set or view your warning setting. For example, to see what the current setting is, execute:

可选的,你可以使用内置包dbms_warnings来设置或者查看警告设置。例如:查看当前警告设置
BEGIN
DBMS_OUTPUT.PUT_LINE(DBMS_WARNING.GET_WARNING_SETTING_STRING());
END;
/

DISABLE:ALL
--默认设置

 

The warning error codes all begin with a ‘PLW-‘. The SEVERE errors are in the range 05000 to 05999. The INFORMATIONAL errors are in the range 06000 to 06999. The PERFORMANCE errors are in the range 07000 to 07249. On UNIX systems, a text file with the all of error codes, together with their cause and action can be found in $ORACLE_HOME/plsql/mesg/plwus.msg or a similar filename (plw??.msg) if the locale is not US.
警告错误代码以'PLW-'开头;
严重错误代码范围:05000到05999;
报告错误代码范围:06000到06999;
性能错误代码范围:07000到07249;
UNIX系统中在以下文件中包含所有错误代号以及原因和处理方法。$ORACLE_HOME/plsql/mesg/plwus.msg

An example of compiler warnings appears below:
来看两个出现编译警告的例子:

--1 不作用的代码(dead code):
SQL> CREATE OR REPLACE PROCEDURE dead_code IS
  2    x NUMBER := 10;
  3  BEGIN
  4    IF x = 10 THEN  -- always TRUE
  5        x := 20;
  6    ELSE
  7        x := 100; -- dead code
  8    END IF;
  9  END dead_code;
 10  /

SP2-0804: Procedure created with compilation warnings

SQL> show errors
Errors for PROCEDURE DEAD_CODE:

LINE/COL ERROR
-------- -----------------------------------------------
7/7      PLW-06002: Unreachable code

 

--2 如何加固我们的函数返回值逻辑
说明:结构化编程应始终做到:One way in, one way out. 不要试图到处挖坑,最后坑的是自己。

考虑以下代码:
CREATE OR REPLACE FUNCTION status_desc (
  cd_in IN VARCHAR2)
  RETURN VARCHAR2
IS
BEGIN
  IF cd_in = 'C'
      THEN RETURN 'CLOSED';
  ELSIF cd_in = 'O'
      THEN RETURN 'OPEN';
  ELSIF cd_in = 'A'
      THEN RETURN 'ACTIVE';
  ELSIF cd_in = 'I'
      THEN RETURN 'INACTIVE';
  END IF;
END;

编译是无告警,表面看也没啥大问题是吧?那我执行以下语句呢?
BEGIN
  DBMS_OUTPUT.PUT_LINE (status_desc ('X'));
END;
/

ORA-06503: PL/SQL: Function returned without value

问题还不小呢!! 下面启用编译时警告来提早发现问题!

ALTER SESSION SET plsql_warnings ='ENABLE:5005'
/

ALTER FUNCTION status_desc COMPILE
/

PLW-05005: subprogram STATUS_DESC returns without value at line 15

警告是有了,但是函数依然可以被执行!那怎么行,这是有问题的程序!下面启用更严格的警告阻止程序编译成功!
ALTER SESSION SET plsql_warnings ='ERROR:5005'
/

ALTER FUNCTION status_desc COMPILE
/

PLS-05005: subprogram STATUS_DESC returns without value at line 15

这下OK了,程序编译返回了严重警告代码PLS-05005,无法编译通过了!
接下来要干的就是修复代码了。That's it!


    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Oracle 12c发布简单介绍及官方下载地址
  • 在linux下安装oracle,如何设置让oracle自动启动!也就是让oracle那个服务自动启动,不是手动的
  • oracle 11g最新版官方下载地址
  • 请问su oracle 和su - oracle有什么不同?
  • Oracle 数据库(oracle Database)Select 多表关联查询方式
  • 虚拟机装Oracle R12与Oracle10g
  • Oracle数据库(Oracle Database)体系结构及基本组成介绍
  • Oracle 数据库开发工具 Oracle SQL Developer
  • 如何设置让Oracle SQL Developer显示的时间包含时分秒
  • Oracle EBS R12 支持 Oracle Database 11g
  • Oracle 10g和Oracle 11g网格技术介绍
  • sqlserver iis7站长之家
  • oracle中如何把表中具有相同值列的多行数据合并成一行
  • 请问大家用oracle数据库, 用import oracle.*;下的东西么? 还是用标准库?
  • Oracle 数据库(oracle Database)性能调优技术详解
  • Linux /$ORACLE_HOME $ORACLE_HOME
  • ORACLE日期相关操作
  • Linux系统下Oracle的启动与Oracle监听的启动
  • ORACLE数据库常用字段数据类型介绍
  • 请问在solaris下安装ORACLE,用root用户和用oracle用户安装有什么区别么?
  • Oracle 12c的九大最新技术特性介绍
  • 网间Oracle的连接,远程连接Oracle服务器??


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3