terça-feira, 15 de fevereiro de 2011

Compile-Time Warnings

Oracle can now produce compile-time warnings when code is ambiguous or inefficient be setting the PLSQL_WARNINGS parameter at either instance or session level. The categories ALL, SEVERE, INFORMATIONAL and PERFORMANCE can be used to alter the type of warnings that are produced. Examples of their usage include:

 

-- Instance and session level.

ALTER SYSTEM SET PLSQL_WARNINGS='ENABLE:ALL';

ALTER SESSION SET PLSQL_WARNINGS='DISABLE:PERFORMANCE';

 

-- Recompile with extra checking.

ALTER PROCEDURE hello COMPILE PLSQL_WARNINGS='ENABLE:PERFORMANCE';

 

-- Set mutiple values.

ALTER SESSION SET PLSQL_WARNINGS='ENABLE:SEVERE','DISABLE:PERFORMANCE','DISABLE:INFORMATIONAL';

 

-- Use the DBMS_WARNING package instead.

EXEC DBMS_WARNING.SET_WARNING_SETTING_STRING('ENABLE:ALL' ,'SESSION');

The current settings associated with each object can be displayed using the [USER|DBA|ALL]_PLSQL_OBJECT_SETTINGS views.
To see a typical example of the warning output try:

 

ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';

 

CREATE OR REPLACE PROCEDURE test_warnings AS

  l_dummy  VARCHAR2(10) := '1';

BEGIN

  IF 1=1 THEN

    SELECT '2'

    INTO   l_dummy

    FROM   dual;

  ELSE

    RAISE_APPLICATION_ERROR(-20000, 'l_dummy != 1!');

  END IF;

END;

/

 

SP2-0804: Procedure created with compilation warnings

 

SHOW ERRORS

 

LINE/COL ERROR

-------- ---------------------------

9/5      PLW-06002: Unreachable code

The errors can be queried using the %_ERRORS views.

Fonte: http://www.oracle-base.com/articles/10g/PlsqlEnhancements10g.php

Nenhum comentário :

Postar um comentário

Related Posts Plugin for WordPress, Blogger...