I have the same user defined function in Db2 defined in several schemas. How can I retrieve the schema used for the current invocation within the UDF ?
CURRENT_SCHEMA special register does not work in my case, as it only works after SET CURRENT SCHEMA '...' (which is not used).
Are there any other possibilities ?
Example UDFs:
--#SET TERMINATOR #
CREATE FUNCTION SCHEMA1.TEST_UDF ( )
RETURNS VARCHAR(100) LANGUAGE SQL
BEGIN
RETURN CURRENT_SCHEMA;
END#
CREATE FUNCTION SCHEMA2.TEST_UDF ( )
RETURNS VARCHAR(100) LANGUAGE SQL
BEGIN
RETURN CURRENT_SCHEMA;
END#
--#SET TERMINATOR ;
Invocation:
SELECT SCHEMA1.TEST_UDF() FROM SYSIBM.SYSDUMMY1;
I'd like to see 'SCHEMA1' as output for this invocation.
CURRENT_SCHEMAis going to give you the "default" schema where objects are being resolved, but this isn't going to be the only schema that's looked at (that's handled by the SQL path/library list). Normally you'd pick a canonical copy and only ever call that. - Clockwork-Muse