Accessing environment variables in PL/SQL??

I have two oracle schemas; myenv1 and myenv2. They are both exact copies from each other except for the fact that one is my "developement" environment and the other my "production" environment.
So in each of them I have some packages with PL/SQL code.
I'd like to have an environment variable called PLATFORM (maybe not the best name) that should have the value "devel" in one schema and the value "prod" in the other schema. And I'd like to be able to access this variable in my PL/SQL code so I can slightly change some code or conditionate some code to the production environment only... or stuff like that.
Does anyone know how to do that? (where and how to configure the env. variable)
Any help will be most appreciated.
Thanks!

but I'm using the same 'current_user' in both schemas... is there other values I can get with sys_context ?? maybe there's one that would do it... but i think it's not 'current_user' It should be. Consider:
SQL> show user
USER is "SCOTT"
SQL> create or replace function show_user return varchar2
  2  as
  3  begin
  4    return sys_context('userenv','current_user');
  5  end show_user;
  6  /
Function created.
SQL> select show_user from dual;
SHOW_USER
SCOTT
SQL> grant execute on show_user to test;
Grant succeeded.
SQL> connect test/test
Connected.
SQL> select scott.show_user from dual;
SHOW_USER
SCOTT

Similar Messages

  • Can i use a environment variable inside a *.sql file?

    Hello,
    I want to create a external table.
    So i am using the command
    create or replace directory abc as 'C:\folder'.... inside a sql file.
    Now i want the path "C:\folder" to be dynamic as i am using this path in many other places also inside the sql file.So i thought to create a environment variable and put this value there.I tried using as %PATH% but it gives error..... where %PATH%=C:\folder.
    Can i use a environment variable inside a *.sql file?
    But how to do that or is there any other way.
    Thanks
    Swapna
    Edited by: user11018268 on Feb 19, 2010 1:03 AM

    user11018268 wrote:
    Actually what i want is the path "C:\folder" is not fixed it can be anything which i may not know the user may decide it later. Not supported. A directory object refers to a specific physical location (directory/folder) on a file system. Not a path.
    You can work around it by (creating and) using a function (running under a super user schema with authid definer privs). The caller (e.g. schema scott ) calls it with a physical path. E.g. GetDirectoryObject( 'C:\folder\2010\feb\week4' ).
    This function determines if there is an existing directory object for the path. If not, it uses a wildcard search to determine if there are any directory objects for parents in the path (e.g. for C:\folder\2010\feb or C:\folder\2010 or C:\folder ).
    If it finds a directory object, it interrogates the data dictionary to determine if the caller, schema scott for example, has read/write access on that directory object. If it has, it creates a new directory object and grants the caller read/write access to it. The function then returns the name of the directory object to the caller.
    The caller thus do not deal directly with directory objects. The function returns the object name given a physical path as input. Also, only a single base directory needs to be created (e.g. for C:\folder ) and access granted to the schema on it. Any sub-directory in that base directory can now be dynamically accessed by the schema.

  • How to pass Unix environment variable to a SQL procedure or SQL * Plus

    Can any body suggest me how to ,
    How to pass Unix environment variable to a SQL procedure or SQL * Plus file..
    I am trying to invoke a SQL Procedure from Unix
    by passing the value of a Unix environment variable.
    Is it possible..?
    Thanks in advance.
    Regards,
    Srinivas Jaltaru

    Within your shell script you can use what is known as a "here document" which is basically a way of wrapping a call to Oracle. The following call to Oracle loops and writes rows to files with numerically increasing file names. Two unix shell variables are used, one in a select statement and one in a spool command :
    <pre>
    #!/bin/bash
    export ORACLE_SID=DEV05
    FILENO=1007351
    while [ ${FILENO} -le 1008400 ]
    do
    FILENAME=farm_${FILENO}.txt
    DUMMY=`sqlplus -s user20/user20 <<SQLSTOP
    set lines 73
    set pages 0
    set head off
    set termout off
    set echo off
    set feedback off
    select rpad(searchx, 8)
    from blastx@PRODUCTION
    where searchx = ${FILENO} ### here's a shell variable
    spool /export/home/user20/sql/psiblast/BACKUP2_D/${FILENAME} ### here's a shell variable
    spool off
    SQLSTOP`
    FILENO=`expr ${FILENO} + 1`
    done
    exit 0
    </pre>

  • Apache Environment Variables inside PL/SQL

    How to access Apache Environment Variables inside HTMLDB (PL/SQL block)?

    Hi,
    You can use the owa_util.get_cgi_env packaged function -
    FUNCTION GET_CGI_ENV RETURNS VARCHAR2
    Argument Name                  Type                    In/Out Default?
    PARAM_NAME                     VARCHAR2                INSo, pass in the name of the Env var you want and it will give you back the value.

  • Accessing environment variables

    Good morning,
    I have an implementation of Oracle Application Server 10G using a Shibboleth Service Provider (SP) 2.1 for SSO authentication. The problem I am facing now is to accessing with APEX the environmental variables created by the SP. In my tests I used PHP and everything is working well. However with APEX I only have access to a very limited group of environment variables. Anybody have a suggestion or idea on how to solve this problem?
    The variable I need is "Login".
    Thank you very much.
    hugo

    Hello,
    Take a look at this thread, where I answer a similar problem -
    Re: Unable to access external HTTP Headers
    Hope this helps,
    John.
    Blog: http://jes.blogs.shellprompt.net
    Work: http://www.apex-evangelists.com
    Author of Pro Application Express: http://tinyurl.com/3gu7cd
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone!

  • Environment variable PATH and Sql*Plus

    Hi all,
    i have a problem with sqlplus.
    It might seem not to be able to read the path environment variable.
    I need to launch some sqls without typing their path (to put the path i should modify morre than 300 shell scripts), e.g.: @script.sql.
    My shell scripts are invoked by the database using java.
    Inside the shell scripts we have commands like "sqlplus -silent <login> @script.sql [parameters]"
    So if sqlplus is not able to read the PATH environment variable, the command hangs waiting for something to do without the chance to close it.(it is silent).
    I run RDBMS v8.1.7 on compaq tru64 Unix.
    Can someone help me??
    Thanks in advance.
    Marco - Milan, Italy

    Where do I set SQL*Plus SQLPATH variable??As every other unix environment variable - either in your profile or in your current shell whatever you like
    Is this the PATH where SQL*Plus searches for .sql
    files??SQL*Plus searches for your files in your current directory, and then the directories you specify with the SQLPATH environment variable.
    SQL*Plus searches this colon-separated list of directories in the order they are listed.

  • WebForms - Accessing Environment Variable on a Windows Client

    Hi. We access a Windows Environment Variable using Client-Server Forms 6i. We do this as follows:
    Tool_Env.GetVar('ALLUSERSPROFILE', myPath);
    message(myPath);This returns the value 'c:\documents and settings\all users' on Windows XP.
    This returns the value 'c:\programdata' on Windows 7.
    We'd like to keep similar logic in this form once it's migrated to Web Forms. Is there a way to access this 'allusersprofile' environment variable (or any environment variable to determine whether the user is XP or Win7) from a web form running our UNIX server? Maybe somehow using WebUtil or something?
    Any suggestions would be greatly appreciated. Thanks.

    WebUtil enable your form then do this:
    message (CLIENT_WIN_API_ENVIRONMENT.Get_Environment_string('allusersprofile'));To get the Windows version, do this:
    message(CLIENT_WIN_API_ENVIRONMENT.Get_Windows_Version);.
    Edited by: Michael Ferrante on May 23, 2012 5:06 PM

  • Access environment variables

    Hi,
              I'm running WebLogic 5.1 sp12 with an Apache 1.3.27 web server.
              Apache sets an environment variable ('REDIRECT_URL') upon occurence of
              a 40x error. How do I access such an environment variable from my jsp
              page? Thanks - Dave
              

              [email protected] (D. Alvarado) wrote:
              >Hi,
              > I'm running WebLogic 5.1 sp12 with an Apache 1.3.27 web server.
              >Apache sets an environment variable ('REDIRECT_URL') upon occurence of
              >a 40x error. How do I access such an environment variable from my jsp
              >page? Thanks - Dave
              Hi Dave,
              Hope this link will help you.
              http://developer.java.sun.com/developer/JDCTechTips/2001/tt1204.html#tip1
              Prema
              SIP Technologies & Exports Ltd., India
              

  • How to access environment variables from pluggable destination?

    Hi,
    I'm trying to create a java puggable destination for reports. Everything is working fine.
    I want to access reports environment variables from the java code (like REPORTS_PATH and other new variables that I want to create), but I can't find anything about this in the java API documentation.
    I want to use environment variables instead of destination properties (those I can easily access), because I want to be able to change context using env_id.
    Any ideas?
    Thanks,
    Luis

    I'm using Oracle Application Server Version 10.1.2.0.2
    Thanks

  • How to access environment variables from Oracle Forms

    Hi,
    Any idea how to use the Environment variables from Oracle Forms.
    My basic problem is that from Oracle form I am calling Batch file which calls excel file with a macro.
    So i want to check whether the macro was successful or not.
    So in my batch file i will set %errorlevel% which I should be able to read from Oracle Forms.
    I am able to read the registry from oracle forms, so is there anyway to read environment variable as well?
    Thanks!
    Avinash.

    Hello,
    Use the TOOL_ENV.Getvar() built-in
    Francois

  • Set environment variable in oracle 10g application server control rel3

    hi all,
    i am trying to connect to emc centera through 10g rel3 , here i am getting error .
    error name is:
    com.filepool.fplibrary.FPLibraryException: Error loading FPLibrary or one of its dependencies
    at com.filepool.fplibrary.FPPool.<init>(Unknown Source)
    if any body knows please help me.
    Thanks and regards
    Pravin

    Hello,
    Take a look to http://buttso.blogspot.com/2006/08/accessing-environment-variables-from.html
    Regards
    Tugdual Grall

  • Please help!!!! URGENT !!!! using environment variable

    How do I use the environment variable in my sql script.
    example:
    I am setting up environment variables through my .bat file. The batch file contain the following lines...
    SET ORACLE_SID=test
    SET SID_PWD=test
    SQLPLUS /NOLOG @C:\TEST.SQL
    In my TEST.SQL script, I have a single line as follows..
    CONNECT INTERNAL/%SID_PWD%@%ORACLE_SID%
    My problem is I am not able connect, because my CONNECT statement does not have the values for the variable.
    Please help me how to solve this
    thanks
    kamal

    Pokaloorie;
    If you are working with a local database, you can simply omit the Oracle Sid in your connect string. Make your test.sql file say
    connect "/ as sysdba"
    Regards,
    Russ

  • Environment Variable Values

    Hi all,
    how do i get the environment variables in PL/SQL on Windows NT/2000 or SUN environment..?
    Thanks.

    hi Andrew P Clarke ,
    Thanks for ur immediate reply. That's fine, using sys_context. But i'm not asking thatt...sorrry i didn't specified clearly.
    My question is how do i get the Operating system - User defined system variables. (Ex: in Win 2000 Server Box i've creadted the sysvariable like TEST='C:\TEST\FILE\', like our V$parameter in ORACLE...in 'C'/JAVA we will use the function "GETENV".
    Similllar one in oracle. how do i get the value?
    Thank You very much for ur help and OTN.

  • How do you get LOCAL_ADDR environment variable from weblogic?

    How can you access environment variables, such as LOCAL_ADDR? The request object does not expose methods to get at all the environment variables? I need to know which NIC Card the request is coming off of, which the LOCAL_ADDR will tell me.

    Some variables you can?t get this way.
    I made shellscript that just looked like this.
    set > /yourdir/yourfile.txt
    Then in my class I did Runtime.exec(shellxcript);
    then you just read in "/yourdir/yourfile.txt" as Resource and load it in
    a Property object.
    After that you can get variables to.

  • Windows System Environment Variables in "Sql * plus"

    Can i use/reference Windows System Environment variables in "Sql * plus"?
    For example, i want to create sql-script to run in database server computer that asks variable "ORA_HOME" and uses this value to execute some sql/plsql sentences.
    Oracle 10g Personal, Windows 7.
    Edited by: CharlesRoos on 12.11.2010 17:28

    CharlesRoos wrote:
    Business problem:
    I have created 2 databases in my computer. Both databases needs tablespaces created by a script. Tablespaces' datafiles (.dbf files) names are same for both database. Both database has it's own directory where it holds datafiles at the moment. At the moment the datafiles for Database1 are in folder something like "%ORACLE_HOME%"\oradata\%databasename1%\*.dbf, and second database has its datafiles in other folder, somewhere ""%ORACLE_HOME%"\oradata\%databasename1%\*.dbf". I want now the script to create tablespace called "INDX" with same datafile name "indx1.dbf" into both database. So into both mentioned folder the file "indx1.dbf" must be created by script. I think the script should do following:
    1. get ORACLE_HOME.
    2. connect to database "databasename1"
    3. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename1 || indx1.dbf"
    4. connect to database "databasename2"
    5. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename2 || indx1.dbf"I don't have Oracle database near by anymore, so the code was pseudocode.
    I don't understand how to use ?-shortcut.OK, my first impression is "why does this even NEED to be scripted? Creation of new tablespaces is usually a one-off operation.
    But that aside how about this sqlplus command-line substitution variables. This example is in linux, but will work as well in Windows with the change of the way environment variables are referenced:
    *nix - echo $myvariable
    Windows - echo %myvariable%
    First, the sqlscript to create the TS. Note the use of the substitution variable "&1"
    {code}
    [oracle@vmlnx01 ~]$ cat cat makets.sql
    set echo on feedback on verify on trimsp on
    prompt &1
    CREATE SMALLFILE TABLESPACE EDSTEST
    DATAFILE '/ora01/oradata/&1/edstest.dbf'
    SIZE 5M
    REUSE
    AUTOEXTEND ON
    NEXT 1280K
    MAXSIZE 32767M
    LOGGING
    EXTENT MANAGEMENT LOCAL
    SEGMENT SPACE MANAGEMENT AUTO
    drop tablespace edstest
    including contents and datafiles
    exit
    {code}
    So, at the OS prompt: Notice that the @ is separated by a space, makeing it a command line parm instead of part of the connect string
    {code}
    [oracle@vmlnx01 ~]$ export myparm=vlnxora1
    [oracle@vmlnx01 ~]$ sqlplus system/pswd @makets $myparm
    SQL*Plus: Release 10.2.0.4.0 - Production on Fri Nov 12 13:18:05 2010
    Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> prompt &1
    vlnxora1
    SQL> --
    SQL> CREATE SMALLFILE TABLESPACE EDSTEST
    2 DATAFILE '/ora01/oradata/&1/edstest.dbf'
    3 SIZE 5M
    4 REUSE
    5 AUTOEXTEND ON
    6 NEXT 1280K
    7 MAXSIZE 32767M
    8 LOGGING
    9 EXTENT MANAGEMENT LOCAL
    10 SEGMENT SPACE MANAGEMENT AUTO
    11 ;
    old 2: DATAFILE '/ora01/oradata/&1/edstest.dbf'
    new 2: DATAFILE '/ora01/oradata/vlnxora1/edstest.dbf'
    Tablespace created.
    SQL> --
    SQL> drop tablespace edstest
    2 including contents and datafiles
    3 ;
    Tablespace dropped.
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    [oracle@vmlnx01 ~]$
    {code}

Maybe you are looking for

  • So many problems... My MacBook Pro is full and I'm terrified I'm going to lose all of my photos and music.

    Where to even begin with the problames I'm having!?  I have a MacBook Pro  OS X 10.5.8, an iMac OS X 10.5.8, a 500GB Time Capsule, and an iPhone 4s. I know just enough about all of them to basically get myself into trouble... And It seems I have done

  • Idoc Output type

    Hi, I am using output types to trigger Idocs whenever a sales order is created or changed using EDI as output type. ORDERS05 Idoc type is triggered whenever a sales order is created/changed. But along with that outbound Idoc type, an Inbound Idoc is

  • Devices not showing up in client software Administration section

    None of our devices are showing in the "devices" portion of the administration section in the client app. Everything is functioning fine and I can administer devices through SysPrefs, but will eventually need to get back to this setup to add "edit in

  • Adding code to aid in responding to submitted forms

    I would like to add a line of code to my existing forms (.asp) so when I reply to the message by email the "to" line of the reply message is automatically poplulated by the email address entered in the form.

  • RMAN SBT_TAPE

    hello, as far as i learn that sbt_tape configuration needs a media manager i explore that some of them is netbackup, tivoli now, i think they are not open source . can any 1 tell me which media manager is open source ? i wanna do practice on sbt_tape