DB2 - Problembeschreibung
| Problem IC66926 | Status: Geschlossen |
DB2 CAN NOT HOOK NO_DATA_FOUND INSIDE OF A FOR CURSOR LOOP IN PL/SQL. | |
| Produkt: | |
DB2 FOR LUW / DB2FORLUW / 980 - DB2 | |
| Problembeschreibung: | |
The following PL/SQL script does not display the "Bottom of FOR
loop" message. Assume that table TEST2 contains one or more
rows, and that TEST1 is empty:
create or replace procedure cursor_test
is
cursor c2 is
select col1 from test2;
testv varchar2(10);
begin
for c2_rec in c2 loop
dbms_output.put_line('Top of FOR loop');
begin
select col1 into testv from test1;
exception
when no_data_found then
dbms_output.put_line('NO DATA
FOUND');
when others then
null;
end;
dbms_output.put_line('Bottom of FOR loop');
end loop;
end;
/
After the first execution of the SELECT ... INTO statement, the
FOR loop exits prematurely and the exception clause for
NO_DATA_FOUND is not run. | |
| Problem-Zusammenfassung: | |
****************************************************************
* USERS AFFECTED: *
* ALL *
****************************************************************
* PROBLEM DESCRIPTION: *
* The following PL/SQL script does not display the *
* "BottomofFORloop" message. Assume that table TEST2 contains *
* one ormorerows, and that TEST1 is empty:create or *
* replaceprocedure cursor_testiscursor c2 isselect col1 *
* fromtest2;testv varchar2(10);beginfor c2_rec in *
* c2loopdbms_output.put_line('Top of FOR loop');beginselect *
* col1into testv from test1;exceptionwhen *
* no_data_foundthendbms_output.put_line('NODATAFOUND');when *
* othersthennull;end;dbms_output.put_line('Bottom of FOR *
* loop');endloop;end;/After the first execution of the SELECT *
* ... INTOstatement,theFOR loop exits prematurely and the *
* exceptionclause forNO_DATA_FOUND is not run. *
****************************************************************
* RECOMMENDATION: *
* Upgrade to DB2 UDB version 9.8 fix pack 3. *
**************************************************************** | |
| Local-Fix: | |
Wrap the SELECT ... INTO statement in a separate PL/SQL
function, then invoke this function to obtain the column value;
for example:
create or replace function get_test1_col1 return varchar2(2)
as
declare v varchar2(2);
begin
select col1 into v from test1;
return v;
end;
/
-- In the calling procedure...
for c2_rec in c2 loop
dbms_output.put_line('Top of FOR loop');
begin
testv := get_test1_col1;
exception
when no_data_found then
dbms_output.put_line('NO_DATA_FOUND');
when others then
null;
end;
This will produce the intended behaviour. | |
| verfügbare FixPacks: | |
DB2 Version 9.8 Fix Pack 3 for Linux, UNIX, and Windows | |
| Lösung | |
Problem was first fixed in DB2 UDB Version 9.8 Fix Pack 3. | |
| Workaround | |
keiner bekannt / siehe Local-Fix | |
| Weitere Daten | |
Datum - Problem gemeldet : Datum - Problem geschlossen : Datum - der letzten Änderung: | 05.03.2010 08.11.2012 08.11.2012 |
| Problem behoben ab folgender Versionen (IBM BugInfos) | |
9.7.FP3, 9.8.FP3 | |
| Problem behoben lt. FixList in der Version | |
| 9.8.0.3 |
|