Tech, Oracle, user experience, coffee, design standards, and shameless ranting

Getting the server name in Oracle 11g

In an APEX application i’m creating, I’m storing some output files that the public needs to get access to on the XMLDB server. The problem is, when i’m moving my code to production, I need to update the location to send the users to.

Previously, I’d used global variables in a Global package to store this value, but a better way is:

1
2
3
4
5
6
7
8
9
10
11
12
--Get the database host name
--Using this method rather than sys.v_$instance to access the hostname means that
--no grants are required - makes sense  
SELECT sys_context('USERENV','SERVER_HOST')
INTO l_hostname
FROM dual;
 
--Get the http port
SELECT dbms_xdb.gethttpport() INTO l_port FROM dual;
 
--piece it all together
l_return := 'You can find your output files by visiting : http://'||l_hostname||':'||l_port||'/public/rict/'||p_seq;

Hope this helps someone

Share

You can follow any responses to this entry through the RSS 2.0 feed.

Switch to our mobile site