Instead of calling a function, when you can get the same effect by accessing a documented PL/SQL variable, you should. For example:
v('APP_USER') = APEX_APPLICATION.g_user v('REQUEST') = APEX_APPLICATION.g_request v('APP_ID') = APEX_APPLICATION.g_flow_id v('APP_PAGE_ID') = APEX_APPLICATION.g_flow_step_id v('DEBUG') = APEX_APPLICATION.g_debug
g_debug is a boolean, unlike the
UPDATE: If you’re using Apex 5, you can now get the User and Session ID from the APEX$SESSION application context.
There’s more here: documentation for the APEX_APPLICATION package
I suspect that the implementation of
v() is something like this [EDIT: read the comments for more commentary on this, and a more accurate picture of what v() actually does]:
FUNCTION v (p_name IN VARCHAR2) RETURN VARCHAR2 IS res VARCHAR2(4000); BEGIN CASE p_name WHEN 'APP_ID' THEN res := APEX_APPLICATION.g_flow_id; WHEN 'APP_USER' THEN res := APEX_APPLICATION.g_user; WHEN 'DEBUG' THEN IF APEX_APPLICATION.g_debug THEN res := 'YES'; ELSE res := 'NO'; END IF; WHEN 'REQUEST' THEN res := APEX_APPLICATION.g_request; ... etc. ... ELSE BEGIN SELECT s.item_value INTO res FROM wwv_<session-values-or-something> s WHERE s.item_name = p_name AND s.flow_id = APEX_APPLICATION.g_flow_id AND s.session_id = APEX_APPLICATION.g_instance; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN NULL; END; END CASE; RETURN res; END v;
In addition, instead of calling
v('SESSION'), you could call the undocumented function
APEX_APPLICATION.get_session_id instead, which is probably faster, or refer to the global variable
APEX_APPLICATION.g_instance instead. I would suspect that the function normally just returns
g_instance anyway, but it’s possible there’s some more logic behind the function.
Disclaimer: use undocumented bits at your own risk.
Some other undocumented goodies that may be useful include (and a lot of these are not available at all via
APEX_APPLICATION.g_flow_alias = application alias
APEX_APPLICATION.g_flow_name = application name
APEX_APPLICATION.g_flow_version = application version string
APEX_APPLICATION.g_flow_status = app availability status code, e.g.
APEX_APPLICATION.g_build_status = app build status code, e.g.
APEX_APPLICATION.g_base_href = the base URL for the site, not including the
TRUE if the page was requested with Printer Friendly flag
TRUE if the page’s report is being rendered in CSV format
APEX_APPLICATION.g_date_format = Application default date format
APEX_APPLICATION.g_date_time_format = Application date time format
APEX_APPLICATION.g_timestamp_format = Application default timestamp format
APEX_APPLICATION.g_timestamp_tz_format = Application default timestamp with time zone format
You can have a peek at all the globals in this package with this query (but be warned, any undocumented ones may change, and may not necessarily be set to any meaningful value when your code is running):
select owner, trim(text) from dba_source where name = 'WWV_FLOW' and type = 'PACKAGE' and ltrim(text) like 'g%' order by owner desc, line;