Thursday, May 29, 2008

How to set Environmental variable to SQL*Plus automatically

When SQL*Plus starts up, it looks for a global login script called glogin.sql in the $ORACLE_HOME/sqlplus/admin directory. If found, this script will be executed. If you want to set your SQL*Plus environmental variable like PAGESIZE or LINESIZE or SQLPROMPT then you can set within the file glogin.sql. Then all of the database users who use SQL*Plus will be affected of this site profile glogin.sql.

After checking site profile oracle checks for user profile named login.sql in the user's home. If you want to set environmental variable for a particular Oracle user then you can use user profile named login.sql. Other users of the OS will not be affected. You will create login.sql, put environmental variables inside it and place it to the user's home location.

In the following section I demonstrate the procedure with an example.

AT first I connected to database without any login.sql file. And then it displays prompt as SQL>
-bash-3.00$ sqlplus arju/a

SQL*Plus: Release 10.2.0.1.0 - Production on Sat May 31 23:27:34 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Now I am creating login.sql and put an entry of sql prompt which will show username@database_name SQL>
SQL> !vi login.sql
set sqlprompt "&&_USER@&&_CONNECT_IDENTIFIER SQL>"


SQL>exit

Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Now connect to database and see the prompt.
-bash-3.00$ sqlplus arju/a
SQL*Plus: Release 10.2.0.1.0 - Production on Sat May 31 23:28:56 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

ARJU@dbase SQL>


Along with connection identifier you set set other environmental variables like pagesize linesize for a user or globally.

No comments:

Post a Comment