Subject | NULLIF and NVL cannot use variables?? |
---|---|
Author | csswa |
Post date | 2002-05-25T08:10:50Z |
I wrote a stored proc to do some null handling, realised it was not
returning the expected results, so I modified it for testing:
DECLARE EXTERNAL FUNCTION TEMP_UDF_SNVL
VARCHAR(500),
VARCHAR(500),
VARCHAR(500)
RETURNS PARAMETER 3
ENTRY_POINT 'sNvl' MODULE_NAME 'fbudf';
set term ^;
CREATE PROCEDURE TEMP_SP_FIX1
(PAR_STRING VARCHAR(500))
RETURNS
(RET_STRING VARCHAR(500))
AS
DECLARE VARIABLE VAR_STRING VARCHAR(500);
begin
var_string = temp_udf_snvl(par_string,'was_null');
ret_string = var_string;
end^
set term ;^
This SQL works:
select TEMP_UDF_SNVL(a_field,'was_null') from some_table;
correctly replacing any null records in a_field with 'was null'.
However this SQL fails:
execute procedure TEMP_SP_FIX1(null);
It does not return 'was null'.
However,
execute procedure TEMP_SP_FIX1('test');
correctly returns 'test'.
So it appears that you cannot use variable values for SNVL, only
valid fields.
If this is the case, a note should be put into the docs pointing it
out: that the NVL function won't handle null variables, only null
field values.
Regards,
Andrew Ferguson
-- Creating a better tomorrow using the leftovers from yesterday.
returning the expected results, so I modified it for testing:
DECLARE EXTERNAL FUNCTION TEMP_UDF_SNVL
VARCHAR(500),
VARCHAR(500),
VARCHAR(500)
RETURNS PARAMETER 3
ENTRY_POINT 'sNvl' MODULE_NAME 'fbudf';
set term ^;
CREATE PROCEDURE TEMP_SP_FIX1
(PAR_STRING VARCHAR(500))
RETURNS
(RET_STRING VARCHAR(500))
AS
DECLARE VARIABLE VAR_STRING VARCHAR(500);
begin
var_string = temp_udf_snvl(par_string,'was_null');
ret_string = var_string;
end^
set term ;^
This SQL works:
select TEMP_UDF_SNVL(a_field,'was_null') from some_table;
correctly replacing any null records in a_field with 'was null'.
However this SQL fails:
execute procedure TEMP_SP_FIX1(null);
It does not return 'was null'.
However,
execute procedure TEMP_SP_FIX1('test');
correctly returns 'test'.
So it appears that you cannot use variable values for SNVL, only
valid fields.
If this is the case, a note should be put into the docs pointing it
out: that the NVL function won't handle null variables, only null
field values.
Regards,
Andrew Ferguson
-- Creating a better tomorrow using the leftovers from yesterday.