When you compile stored PL units, the PL compiler issues warnings for operations that are not supported but will not cause errors or jeopardize the compilation. For example, an alert is generated if an obsolete PL feature is used.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
PLSQL_WARNINGS parameters
The PL alert messages are in the format of PLW-nnnnn.
The following table describes the levels of Compile-Time alerts.
| Category | Description | Example |
|---|---|---|
| SEVERE | Alerts for issues that may lead to unexpected behaviors or invalid results. | Parameter aliasing issues. |
| PERFORMANCE | Alerts for issues that may lead to performance deterioration. | A VARCHAR2 value is passed to the NUMBER column in the INSERT statement. |
| INFORMATIONAL | Alerts for issues that do not affect performance or correctness but may require modifications to make the code easier to maintain. | Non-executable code. |
You can achieve the following purposes by setting the compilation parameter PLSQL_WARNINGS:
Enable and disable all alerts, including alerts of one or more categories or specific alerts.
Treat a specific alert as an error that must be corrected before PL unit compilation.
You can set the PLSQL_WARNINGS parameter for the following items by using different statements:
Database instances: Use the
ALTER SYSTEMstatement.Sessions: Use the
ALTER SESSIONstatement.Stored PL units: Use the
ALTERstatement andcompile_parameters_clause.
All the foregoing ALTER statements use the following syntax to set the PLSQL_WARNINGS parameter:
PLSQL_WARNINGS = 'value_clause [, value_clause] ...'
Examples: Use the ALTER statement to set the PLSQL_WARNINGS parameter.
Example 1: Enable all alerts for the current session.
ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
Example 2: Disable INFORMATIONAL alerts for the current session.
ALTER SESSION SET PLSQL_WARNINGS='DISABLE:INFORMATIONAL';
Example 3: Enable PERFORMANCE alerts, disable SEVERE alerts, and treat PLW-07002 alerts as errors for the session.
ALTER SESSION
SET PLSQL_WARNINGS='ENABLE:PERFORMANCE, DISABLE:SEVERE, ERROR:07002';
DBMS_WARNING package
To compile PL units in a development environment, call subprograms in the DBMS_WARNING package to display and set the PLSQL_WARNINGS parameter.
When you compile complex programs, you can use the DBMS_WARNING subprogram to set different values for PLSQL_WARNINGS. The DBMS_WARNING subprogram can save the current settings of PLSQL_WARNINGS. You can modify the settings to compile a specified subprogram set and then restore the original values.
Here is an example:
obclient> ALTER SESSION SET PLSQL_WARNINGS='DISABLE:ALL'; -- Disable all alert messages for this session.
Query OK, 0 rows affected
obclient> CREATE OR REPLACE PROCEDURE sample_code AUTHID DEFINER AS
n CONSTANT BOOLEAN := TRUE;
BEGIN
IF n THEN
DBMS_OUTPUT.PUT_LINE('TRUE');
ELSE
DBMS_OUTPUT.PUT_LINE('FALSE');
END IF;
END sample_code;
/
Query OK, 0 rows affected
obclient> CALL DBMS_WARNING.set_warning_setting_string ('ENABLE:ALL', 'SESSION'); --Enable all alert messages for this session
Query OK, 0 rows affected
obclient> SELECT DBMS_WARNING.get_warning_setting_string() FROM DUAL; --View the current alert settings
+-------------------------------------------+
| DBMS_WARNING.GET_WARNING_SETTING_STRING() |
+-------------------------------------------+
| ENABLE:ALL |
+-------------------------------------------+
1 row in set