DB2 - Problembeschreibung
| Problem IC67332 | Status: Geschlossen |
String truncation does not raise an exception in PL/SQL code | |
| Produkt: | |
DB2 FOR LUW / DB2FORLUW / 980 - DB2 | |
| Problembeschreibung: | |
In PL/SQL, when a string value is stored into a CHAR or VARCHAR
variable that is too small to hold it, a VALUE_ERROR exception
should be raised. DB2 is not raising the exception as expected.
The following example demonstrates the problem:
CREATE OR REPLACE FUNCTION test_func_plsql
RETURN VARCHAR
IS
v_text VARCHAR(1);
BEGIN
v_text := 'Hello';
RETURN 'FAILURE: Exception was not dispatched.';
EXCEPTION
WHEN VALUE_ERROR THEN
RETURN 'SUCCESS: Exception dispatched.';
END;
/
BEGIN
test_func_plsql;
END;
/ | |
| Problem-Zusammenfassung: | |
**************************************************************** * USERS AFFECTED: * * DB2 UDB Version 9.8 * **************************************************************** * PROBLEM DESCRIPTION: * * See Error description field for more information. * **************************************************************** * RECOMMENDATION: * * Please see the LOCAL FIX section for detailed information * * about * * how to handle truncation warnings as exceptions in PL/SQL * * code. * * These recommended workarounds require DB2 Version 9.8 Fix * * Pack * * 1 or later. * **************************************************************** | |
| Local-Fix: | |
This problem occurs because string truncation results in a
warning condition in SQL routines under DB2, instead of the
exception condition that is expected by PL/SQL. Beginning with
DB2 Version 9.8 Fix Pack 1, you can map user-declared
conditions to specific DB2 SQLSTATE values, including warnings,
using PRAGMA DB2_EXCEPTION_INIT.
Here is an example of a PL/SQL routine with a condition handler
to detect DB2 truncation warnings, SQLSTATE '01004':
declare
TRUNCATION_ERROR exception;
pragma db2_exception_init(TRUNCATION_ERROR, '01004');
v_text varchar(1);
begin
v_text := 'Hello';
dbms_output.put_line('FAIL: No truncation detected');
exception
when TRUNCATION_ERROR then
dbms_output.put_line('PASS: Truncation detected');
end;
/
Please note that an OTHERS clause in an exception handler will
not catch this type of exception by itself; if you wish to catch
a truncation warning with an OTHERS clause, you must specify the
exception name explicitly, along with OTHERS. For example:
declare
TRUNCATION_ERROR exception;
pragma db2_exception_init(TRUNCATION_ERROR, '01004');
v_text varchar(1);
begin
v_text := 'Hello';
dbms_output.put_line('FAIL: No exception detected');
exception
when TRUNCATION_ERROR or OTHERS then
dbms_output.put_line('PASS: Exception detected');
end;
/
You can find additional information about PRAGMA
DB2_EXCEPTION_INIT in the DB2 Information Center, at:
http://publib.boulder.ibm.com/infocenter/db2luw/v9r8/topic/com.i
bm.db2.luw.apdv.plsql.doc/doc/c0053876.html | |
| verfügbare FixPacks: | |
DB2 Version 9.8 Fix Pack 3 for Linux, UNIX, and Windows | |
| Lösung | |
Please see the LOCAL FIX section for detailed information about how to handle truncation warnings as exceptions in PL/SQL code. These recommended workarounds require DB2 Version 9.8 Fix Pack 1 or later. | |
| Workaround | |
keiner bekannt / siehe Local-Fix | |
| Weitere Daten | |
Datum - Problem gemeldet : Datum - Problem geschlossen : Datum - der letzten Änderung: | 19.03.2010 07.02.2012 07.02.2012 |
| Problem behoben ab folgender Versionen (IBM BugInfos) | |
9.8., 9.8.FP3 | |
| Problem behoben lt. FixList in der Version | |
| 9.8.0.3 |
|