cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How do I access an OS environment variable from SQL?

VolkerBarth
Contributor
11,307

Say, I want to access the value of the Windows %TEMP% setting in order to write output to a particular directory...

Just as "cross documentation" - as it has been dealt with as a side effect of this question dealing witb DBISQL.

View Entire Topic

If you have the Perl external environment setup, this function will return value of the environment variable passed in:

CREATE FUNCTION getenv( env LONG VARCHAR )
RETURNS LONG VARCHAR
EXTERNAL NAME '$sa_perl_return = $ENV{$sa_perl_arg0}'
LANGUAGE PERL

You can do something similar with any of the other external environments, but Perl is most convenient because you can embed the code right in the external name, without having to deal with distributing dlls or jars.

VolkerBarth
Contributor
0 Likes

other, better, smarter, easier 🙂