Why below function is not returning fresh param value every time I am altering session to set new NLS_DATE_FORMAT
FUNCTION get_param(p_parameter IN VARCHAR2)
RETURN VARCHAR2 RESULT_CACHE relies_on(nls_session_parameters) IS
l_value nls_session_parameters.value%TYPE;
BEGIN
dbg('Entered Fn_Get_nls_session_Parameter_frc to cache details for .. ' || p_parameter);
SELECT SYS_CONTEXT('USERENV', p_parameter) INTO l_value FROM dual;
RETURN l_value;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbg('In NDF : Gng to return value as null.. ');
l_value := NULL;
RETURN l_value;
END get_param;
Well... I would say the answer stands in the question! If you carefully read Oracle documentation about Cross Session Functions, then you'd know.
This is exactly what you're using when creating your function:
Indeed
nls_session_parameters
View doesn't change between your calls! it is a fixed system view. What changes it what your user sees from it.So you have solutions:
RESULT_CACHE
statement from your function declaration or find a way to refresh the cache between the callsadd a parameter that will change between your calls:
(you might need to actually do something with the "dummy" parameter for it to be taken into account)
1) With Oracle Database 11gR2, the
RELIES ON
clause is deprecated, which means that you don’t even have to list the dependencies: Oracle will figure everything out for you.2) Moreover Oracle has V$RESULT_CACHE_OBJECTS. There are information about cached object.
3) You can also force the oracle to refresh 'result_cache'