home clear 64x64
en blue 200x116 de orange 200x116 info letter User
suche 36x36
Neueste VersionenFixList
11.1.0.7 FixList
10.5.0.9 FixList
10.1.0.6 FixList
9.8.0.5 FixList
9.7.0.11 FixList
9.5.0.10 FixList
9.1.0.12 FixList
Haben Sie Probleme? - Kontaktieren Sie uns.
Kostenlos registrieren anmeldung-x26
Kontaktformular kontakt-x26

DB2 - Problembeschreibung

Problem IC66498 Status: Geschlossen

String truncation does not raise an exception in PL/SQL code

Produkt:
DB2 FOR LUW / DB2FORLUW / 970 - 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.7                                          * 
**************************************************************** 
* PROBLEM DESCRIPTION:                                         * 
* 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;                                                         * 
*                                                              * 
* /                                                            * 
* ----                                                         * 
**************************************************************** 
* 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.7 Fix    * 
* Pack                                                         * 
* 3 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.7 Fix Pack 3, 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; 
/ 
 
If necessary, the conditional compilation features of DB2 can 
be used to isolate DB2-specific code in your PL/SQL 
applications.  For example: 
 
update db cfg for testdb using SQL_CCFLAGS DB2_TRUNC:TRUE; 
 
create or replace procedure test 
is 
$IF $$DB2_TRUNC $THEN 
  TRUNCATION_ERROR exception; 
  pragma db2_exception_init(TRUNCATION_ERROR, '01004'); 
$END 
  v_text varchar(1); 
begin 
  v_text := 'Hello'; 
  dbms_output.put_line('FAIL: No exception detected'); 
exception 
$IF $$DB2_TRUNC $THEN 
  when TRUNCATION_ERROR or OTHERS then 
$ELSE 
  when OTHERS then 
$END 
    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/v9r7/topic/com.i 
bm.db2.luw.apdv.plsql.doc/doc/c0053876.html
verfügbare FixPacks:
DB2 Version 9.7 Fix Pack 2 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 3 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 3a for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 4 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 5 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 6 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 7 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 9a for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 8 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 9 for Linux, UNIX, and Windows
DB2 Version 9.7 Fix Pack 10 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.7 Fix Pack 
3 or later.
Workaround
keiner bekannt / siehe Local-Fix
Bug-Verfolgung
Vorgänger  : APAR is sysrouted TO one or more of the following: IC67332 
Nachfolger : 
Weitere Daten
Datum - Problem gemeldet    :
Datum - Problem geschlossen :
Datum - der letzten Änderung:
19.02.2010
07.02.2012
07.02.2012
Problem behoben ab folgender Versionen (IBM BugInfos)
9.7.,
9.7.FP2
Problem behoben lt. FixList in der Version
9.7.0.2 FixList