0% found this document useful (0 votes)
70 views

PLSQL 15 2 SG

The document discusses enabling and controlling PL/SQL warning messages. It describes using the PLSQL_WARNINGS initialization parameter and DBMS_WARNING package to selectively disable, enable, or treat individual warnings as errors. This allows developers to control warnings during compilation and identify potential issues in code.

Uploaded by

Andrei Vulpe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

PLSQL 15 2 SG

The document discusses enabling and controlling PL/SQL warning messages. It describes using the PLSQL_WARNINGS initialization parameter and DBMS_WARNING package to selectively disable, enable, or treat individual warnings as errors. This allows developers to control warnings during compilation and identify potential issues in code.

Uploaded by

Andrei Vulpe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

2

3
4
5
6
7
8
To make your programs more robust and avoid problems at run time, you can enable checking for certain
warning conditions. These conditions are not serious enough to produce an error and keep you from
compiling a subprogram. They might point out something in the subprogram that produces an undefined
result or might create a performance problem. For example, when this procedure is created (or replaced)
after the ALTER SESSION command enables all PL/SQL warning messages, you see this procedure
UNREACHABLE has a line of code identified that would never execute.

9
10
USER_ERRORS describes current errors on all stored objects (views, procedures, functions, packages, and
package bodies) owned by the current user. You can also treat particular messages as errors instead of
warnings. For example, if you know that the warning message PLW-05003 represents a serious problem in
your code, including ERROR:05003' in the PLSQL_WARNINGS setting makes that condition trigger an error
message (PLS_05003) instead of a warning message. You would do this when you want the result to be a
failed compilation rather than simply a warning message.

11
To work with PL/SQL warning messages, you use the PLSQL_WARNINGS initialization parameter. PL/SQL
warning messages are divided into categories so that you can suppress or display groups of similar warnings
during compilation.

12
13
14
15
'DISABLE:ALL‘ --all warnings are disabled.

'ENABLE:PERFORMANCE‘ --only performance warning level is enabled. Other categories are unchanged.

'ENABLE:SEVERE‘ --like the previous example, this only enables severe warning level and other categories
are unchanged.

'ENABLE:ALL', 'DISABLE:SEVERE‘ --This first enables all three categories, then disables the SEVERE category,
so that PERFORMANCE and INFORMATIONAL are still enabled.

'DISABLE:SEVERE', 'ENABLE:ALL‘ --This first disables the severe performance warning level and then enables
all warning levels overriding the first parameter setting.

16
17
Warning messages are prefixed with PLW and error messages are prefixed with PLS. Query the
USER_ERRORS table in the data dictionary to obtain warning and error messages on stored objects.

18
19
You can adjust your settings with a very high level of granularity by combining different options.

For example, suppose you want to see all severe issues and you want the compiler to treat PLW-05005:
function exited without a RETURN as a compile error.

If you leave PLW-05005 simply as a warning and compile the no_return function, the program does compile
and you can use it in an application. If you alter the treatment of that warning with the ALTER SESSION
command and then recompile no_return, the compiler fails with an error.

You can also specify ALL as a quick and easy way to refer to all compile-time warnings categories, as in:
ALTER SESSION SET PLSQL_WARNINGS = 'ENABLE:ALL';

20
Oracle's DBMS_WARNING allows the PL/SQL programmer to selectively control which categories of
warning and which individual warnings to disable, enable, or treat as errors.

If you are writing in a development environment that compiles PL/SQL subprograms, you can control
PL/SQL warning messages by calling subprograms in the DBMS_WARNING package.

You might also use this package when compiling a complex application, where different warning settings
apply to different subprograms.

You can save the current state of the PLSQL_WARNINGS parameter with one call to the package, change
the parameter to compile a particular set of subprograms, then restore the original parameter value.

21
22
You can modify the current session's or system's warning settings with the value supplied. The value will be
added to the existing parameter setting if the value for the warning category or warning value has not been
set, or override the existing value. The effect of calling this function is the same as adding the qualifier
(ENABLE/DISABLE/ERROR) on the category specified to the end of the current session or system setting.

23
This procedure replaces previous settings with the new value of ‘SEVERE’. This will have the same effect as
the example using the subsequent ALTER SESSION (OR ALTER SYSTEM) command.

Syntax:
DBMS_WARNING.SET_WARNING_SETTING_STRING (warning_value IN VARCHAR2, scope IN VARCHAR2);

warning_value – the new string that will constitute the new value (in the example above this is
‘ENABLE:SEVERE’)

scope – specifies if the changes are being done in the session context or system context.

Allowed values are SESSION or SYSTEM (in this example, we are activating this for just this user’s session)

24
This function returns the entire warning string for the current session. Use this function when you want to
parse the warning string yourself and then modify and set the new value using
SET_WARNING_SETTING_STRING.

25
26
27
28
29
• DBMS_WARNING - Server-supplied package that allows you to set the same warning categories as the
PLSQL_WARNINGS parameter, but also allows you to save your previous warning settings in a PL/SQL
variable so you can easily return to your original settings.

• PL/SQL Compiler Errors - Fatal situations identified during compilation that must be corrected prior to
successful compilation.

• PL/SQL Compiler Warnings - Non-fatal situations that can be identified during compilation by setting
PLSQL_WARNINGS. Using PLSQL_WARNINGS, you can selectively control which warning categories and
individual warnings to disable, enable, or treat as errors.

30
31

You might also like