Subject Confusing behavior of UDF in stored procedure
Author lutterot
Hello!

I have written a UDF varchar_to_guid which seems to work fine:

/* Gives back the 16 byte GUID for a VARCHAR */
DECLARE EXTERNAL FUNCTION VARCHAR_TO_GUID
VARCHAR(32765) BY DESCRIPTOR
RETURNS CHAR(16) CHARACTER SET OCTETS FREE_IT
ENTRY_POINT 'udf_varchar_to_guid' MODULE_NAME 'guid_udf';

Now I am using this UDF in a stored procedure CreateStringId:

CREATE PROCEDURE CreateStringId(val VARCHAR(32765))
RETURNS (id CHAR(16))
AS BEGIN
id = varchar_to_guid(:val);
SUSPEND;
END^

Now when I am using this procedure like this

select id from CreateStringId('abc')

then I get a different result from using the UDF directly like this

select varchar_to_guid('abc') from SOMETABLE

And when I hard-code the string 'abc' into the store procedure like this

CREATE PROCEDURE CreateStringId(val VARCHAR(32765))
RETURNS (id CHAR(16))
AS BEGIN
id = varchar_to_guid('abc');
SUSPEND;
END^

then the result is the correct one (i.e. the same as using the UDF
directly).

Can anybody help me out and explain this behavior to me?

Thank you,
Christof