So when using SQL*plus (which, to me is still the best tool ever for executing long scripts and long-running scripts), I added a few commands to my global login script which may be helpful to most people, I think.
First things first... WHAT is the global login script and WHERE is it?
WHAT: The global login script is a script that will run every time you login to a database using SQL*plus.
WHERE: It is a file named glogin.sql located in your oracle home \sqlplus\admin (example: D:\app\<username>\product\11.2.0\client_1\sqlplus\admin\glogin.sql)
Anyway, you might be thinking: "So... WHY would I want anything to run automatically every time I connect!??". The reason is simple... to configure your SQL*plus environment!
Here a little something I added to my glogin.sql, that's made my life much easier (and a little safer too!):
--let's not print all this stuff when we login
set echo off
set feedback off
set verify off
set head off
--get the currently logged in username as a variable
col user new_value uname
set termout off
select user from dual;
--get the current database name as a variable
col global_name new_value gname
select global_name from global_name;
set termout on
clear columns
--set the SQL prompt text to username@dbname>
def promptstr=&uname.@&gname
set sqlp '&promptstr>'
--undefine the variables
undef promptchar
undef promptstr
undef uname
undef gname
--set the usual stuff back on
set feedback on
set verify on
set head on
set serveroutput on
--Finally set echo back on
set echo on
Here's what my SQL*plus login looks like:
C:\>set local=testdb
C:\>sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Sex Abr 26 19:51:28 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
User name: scott
Password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
scott@testdb>conn foo/bar@proddb
Connected.
foo@proddb>
Nice huh? Never forget where you are connected to.
I got this trick from Natalka Roshak, in this great post, a long time ago:
No comments:
Post a Comment