|
|
|
|
|
12.6 e05 |
|
02 Aug 2005 |
Fixed |
|
|
|
|
|
If an expression contained a reference to a proxy table, the engine failed if that expression was used as an expression in a message or PRINT statement, an expression in a RETURN statement of a function or procedure, a time/delay expression in a WAITFOR statement, or an offset expression of a FETCH statement. |
|
Workaround Description |
|
Change the original user function to return single value:
===============================================================
set temporary option on_error = 'continue';
drop table DATE_CONTROL;
Create table DATE_CONTROL
(
VALUE_IN char(20),
VALUE_OUT date
);
insert into DATE_CONTROL values('ALL SPACES ','0001-01-01');
insert into DATE_CONTROL values('NULL ','0001-01-01');
insert into DATE_CONTROL values('INVALID DATE ','0001-01-02');
insert into DATE_CONTROL values('LOW VALUES ','0001-01-01');
insert into DATE_CONTROL values('HIGH VALUES ','9999-12-31');
commit;
drop function MVS_DATE_CONVERT;
create function MVS_DATE_CONVERT(inValue varchar(50))
RETURNS DATE
BEGIN
RETURN (
CASE
WHEN invalue is null then ('0001-01-01')
WHEN invalue = ' ' then ('0001-01-01')
WHEN invalue = '00000000' then ('0001-01-01')
WHEN invalue < '0' then ('0001-01-01')
WHEN ((SUBSTR(invalue,1,4) = '0000') OR (SUBSTR(invalue,5,2) > '12')
OR (SUBSTR(invalue,5,2) = '00') OR (SUBSTR(invalue,7,2) > '31')
OR (SUBSTR(invalue,7,2) = '00')
OR (SUBSTR(invalue,5,2) IN ('04','06','09','11') AND SUBSTR(invalue,7,2) > '30')
OR (SUBSTR(invalue,5,2) = '02' AND SUBSTR(invalue,7,2) > '29')
OR (SUBSTR(invalue,5,2) = '02' AND SUBSTR(invalue,7,2) = '29'
AND ((MOD(cast(SUBSTR(invalue,1,4) as integer),4) > 0)
OR ((SUBSTR(invalue,3,2) = '00') AND ( MOD(cast(SUBSTR(invalue,1,2) as integer),4)> 0)))))
THEN ('0001-01-02')
ELSE CAST(SUBSTR(invalue,1,4)||'-'||(SUBSTR(invalue,5,2))||'-'||(SUBSTR(invalue,7,2)) AS DATE)
END)
END;
SELECT MVS_DATE_CONVERT('2004-05-05');
================================================================
Or use procedure to return result set like below:
==============================================================
set temporary option on_error = 'continue';
drop table DATE_CONTROL;
Create table DATE_CONTROL
(
VALUE_IN char(20),
VALUE_OUT date
);
insert into DATE_CONTROL values('ALL SPACES ','0001-01-01');
insert into DATE_CONTROL values('NULL ','0001-01-01');
insert into DATE_CONTROL values('INVALID DATE ','0001-01-02');
insert into DATE_CONTROL values('LOW VALUES ','0001-01-01');
insert into DATE_CONTROL values('HIGH VALUES ','9999-12-31');
commit;
drop procedure MVS_DATE_CONVERT;
create procedure MVS_DATE_CONVERT(inValue varchar(50))
RESULT(MVS_DATE DATE)
BEGIN
CASE
WHEN invalue is null
then (SELECT VALUE_OUT FROM DATE_CONTROL WHERE VALUE_IN = 'NULL')
WHEN invalue = ' '
then (SELECT VALUE_OUT FROM DATE_CONTROL WHERE VALUE_IN = 'ALL SPACES')
WHEN invalue = '00000000'
then (SELECT VALUE_OUT FROM DATE_CONTROL WHERE VALUE_IN = 'LOW VALUES')
WHEN invalue < '0'
then (SELECT VALUE_OUT FROM DATE_CONTROL WHERE VALUE_IN = 'LOW VALUES')
WHEN ((SUBSTR(invalue,1,4) = '0000') OR (SUBSTR(invalue,5,2) > '12')
OR (SUBSTR(invalue,5,2) = '00') OR (SUBSTR(invalue,7,2) > '31')
OR (SUBSTR(invalue,7,2) = '00')
OR (SUBSTR(invalue,5,2) IN ('04','06','09','11') AND SUBSTR(invalue,7,2) > '30')
OR (SUBSTR(invalue,5,2) = '02' AND SUBSTR(invalue,7,2) > '29')
OR (SUBSTR(invalue,5,2) = '02' AND SUBSTR(invalue,7,2) = '29'
AND ((MOD(cast(SUBSTR(invalue,1,4) as integer),4) > 0)
OR ((SUBSTR(invalue,3,2) = '00') AND ( MOD(cast(SUBSTR(invalue,1,2) as integer),4)> 0)))))
then (SELECT VALUE_OUT FROM DATE_CONTROL WHERE VALUE_IN = 'INVALID DATE')
ELSE (SELECT CAST(SUBSTR(invalue,1,4)||'-'||(SUBSTR(invalue,5,2))||'-'||(SUBSTR(invalue,7,2)) AS DATE))
END CASE;
END;
CALL MVS_DATE_CONVERT('2004-05-05');
============================================================ |
|
|
|