11 Customizing Your SQL*Plus Environment In this chapter: SQL*Plus settings You Can Control The Site and User Profiles Environment Variable Settings The SET Command The SHOW Command
Trang 1If you are responsible for backing up an Oracle database, make sure you know how to restore it! You should test yourself and your procedures by doing a trial restore of the database to another computer, or to another set of directories on the same computer Many people have found holes in their backup methods only after a disaster forces them to attempt a restoreit's too late then If you have never restored your database, then you do not have a good backup
In order to be prepared for the day when you lose a disk, and consequently some critical database files, you should
become familiar with the information in the Oracle8 Backup and Recovery Guide You don't need to read it cover to
cover, but you should be familiar with the concepts and procedures it describes In addition, and I can't emphasize this enough, practice recovering your database I am personally aware of cases where a database could not be recovered because the backups weren't being done correctly I have even been burned myself While writing this chapter, I
discovered to my great chagrin that one of our disk drives was not being backed up each night I was lucky I only lost one table with old data that nobody cared about Next time I may not be so lucky Practice pays
Trang 2
11
Customizing Your SQL*Plus Environment
In this chapter:
SQL*Plus settings You Can Control
The Site and User Profiles
Environment Variable Settings
The SET Command
The SHOW Command
This chapter will show you how you can modify the SQL*Plus environment in order to make things more convenient for you or for the users you support There are a number of settings that can be customized Some, like the search path used for SQL scripts, are more useful than others In addition, there are two SQL scripts that are automatically run whenever you start SQL*Plus These SQL scripts are useful, for example, if you have specific SET commands that you always want to execute at the beginning of a session
SQL*Plus Settings You Can Control
The specific customizations you can make may vary a bit depending on the operating system and the specific version of SQL*Plus you are using Generally, though, there are two types of things you need to be aware of: the login scripts and the environment variable settings
There are two SQL scripts that are executed whenever SQL*Plus starts up The first script is referred to as the site profile, and is named glogin.sql It applies globally to all users on a particular computer The second script is the user profile (not the same thing as the product user profile discussed in Chapter 9, The Product User Profile), and it is named login.sql As you can guess from the name, each user may have his or her own user profile script The most obvious use
for these files is to execute SET commands to customize the environment settings to something other than their defaults There are several operating-system environment variables that affect how SQL*Plus operates These environment variables allow you to specify:
The search path to use for SQL scripts (SQLPATH)
The location of the site profile script (PLUS80)
Trang 3
Whether the Windows or DOS version of SQL*Plus should be executed (PLUS_DFLT)
The location of the SQLUS.MSB message file (PRO80)
The language being used (NLS_LANG)
The location of the message files for the language being used (RDBMS80)
Under Windows NT and Windows 95, these settings are made in the registry On a Unix system, they are made using environment variables For detailed information on each of these environment variables, including how to set them under different operating systems, see the section titled Environment Variable Settings, later in this chapter
The Site and User Profiles
Two script files are executed every time SQL*Plus is started These scripts define the site profile and the user profile,
and are named, respectively, glogin.sql andlogin.sql.
The Site Profile
The site profile is made up of the commands contained in glogin.sql, which is the global login file, and is automatically executed every time a user runs SQL*Plus on a given computer system The location of glogin.sql varies from one
operating system to the next, but it is always below the directory containing the SQL*Plus product On a default
Windows 95 installation of Oracle8, glogin.sql may be found in the following directory:
C:\ORAWIN95\PLUS80
On a typical Unix system, such as the HP-9000, the glogin.sql file will be found in this directory:
$ORACLE_HOME/sqlplus/admin
The specific version of SQL*Plus you are running makes a difference as well If you have multiple versions of
SQL*Plus installed, the default installation procedures will result in your having a separate glogin.sql file for each For example, a Windows 95 PC running both SQL*Plus 8.0 and SQL*Plus 3.3 will have a glogin.sql file in each of the
following two directories:
C:\ORAWIN95\PLUS80
C:\ORAWIN95\PLUS33
Trang 4
The specific file that is executed will depend on which version of SQL*Plus you are running.
On Windows 95/NT, the PLUSXX registry setting, where XX refers to
the specific SQL*Plus version, points to the location of glogin.sql By pointing the
PLUS80 and PLUS33 registry settings to the same directory, it is possible to end up with one global login file that is consistent across all versions of SQL*Plus
The default glogin.sql file, supplied by Oracle for version 8.0 of SQL*Plus, looks like this:
$Header: /plus/v4/spam/precious/files/ACTIVE/glogin.sql,
v 1.1 1995/12/19 02:55:18 cjones Exp $
Copyright (c) Oracle Corporation 1988, 1994, 1995 All Rights Reserved
SQL*Plus Global Login startup file
This is the global login file for SQL*Plus
Add any sqlplus commands here that are to be
executed when a user invokes sqlplus
Used by Trusted Oracle
column ROWLABEL format A15
Used for the SHOW ERRORS command
column LINE/COL format A8
column ERROR format A65 WORD_WRAPPED
For backward compatibility
set pagesize 14
Defaults for SET AUTOTRACE EXPLAIN report
column id_plus_exp format 990 heading i
column parent_id_plus_exp format 990 heading p
column plan_plus_exp format a60
column object_node_plus_exp format a8
column other_tag_plus_exp format a29
column other_plus_exp format a44
Most of the commands in the default glogin.sql file are COLUMN commands that format the output from the SQL*Plus
autotrace facility and from the SHOW ERRORS command It is interesting to note that the pagesize has been set to 14 for compatibility purposes In Oracle 7.1 and earlier, the default pagesize was 14 In newer versions of Oracle, the pagesize is
24 In order to prevent problems with scripts that were written with the old default in mind, this glogin.sql file sets the
pagesize to the old value
Trang 5
The user profile is similar to the site profile, except that it is intended to be user-specific The command file name is
login.sql, and it is executed immediately after the glogin.sql file SQL*Plus searches for the login.sql file in the current
directory first; then it searches the directories listed in the SQLPATH environment variable In a Unix installation, there
will not be a default login.sql file, nor will there be a default SQLPATH variable Under the various Windows
environments, you will most likely have a default login.sql file in one of the following directories:
C:\ORAWIN95\DBS Windows 95
C:\ORANT\DBS Windows NT
C:\ORAWIN\DBS Windows 3.1, 3.11
You can add to the login.sql file, putting in whatever commands make your life easier If you are running under Unix, you should make certain that your SQLPATH environment variable points to the directory containing your login.sql;
otherwise, SQL*Plus won't be able to find it when you are working in another directory
Environment Variable Settings
There are a number of environment variables that can affect how SQL*Plus operates One of the most commonly used
of these is the SQLPATH variable SQLPATH functions much like a command search path, except that it applies to SQL scripts It contains a list of directories to search when looking for a script The way you set SQLPATH and other variables depends on the specific operating system you are using The next few sections demonstrate how SQLPATH is set under windows 3.1, Windows 95, Windows 98, Windows NT, and Unix Following these examples is a complete list
of all the environment variables that apply to SQL*Plus
Setting an Environment Variable
Under Unix, SQL*Plus settings are stored in environment variables You usually set these variables with the Unix
export command The situation is pretty much the same for Windows 3.1 and DOS, except that you use the DOS SET
command In later versions of Windows, such as Windows 95, these settings are stored in the registry
Unix
To set an environment variable from Unix, you generally use either the export or setenv command, depending on which
shell you are using The following example, using the Korn shell, shows how to set the SQLPATH variable to point to your home directory:
Trang 6
$ export SQLPATH=$HOME
Here is the same example using the C Shell's setenv command:
$ setenv SQLPATH $HOME
Note that with export you use an equals sign between the variable and the value, while with setenv you do not You can use the export (or setenv) command by itself to get a listing of all the variables you have set, including SQLPATH.
$ export
SQLPATH=/home/oracle
All other environment variables are set using the same method
Windows 95/98/NT
Under Windows 95, 98, and NT, the SQL*Plus environment variable settings are stored in the registry You can edit these registry settings using the REGEDIT program Go to the Start menu, select Run, and type REGEDIT into the Run dialog box Figure 11-1 shows how this will look
Figure 11-1 Running REGEDIT Click the OK button to run REGEDIT A window with two panes will open up (see Figure 11-2) The pane on the left contains a list of registry keys that you navigate through in a hierarchical manner very similar to that used in the
Windows Explorer You want to navigate to the following key:
My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
Be sure to actually click on the key named ORACLE, so that you can see the entries associated with it The resulting screen will look like that shown in Figure 11-2
The right-hand side of the screen now shows a large number of registry entries used by the Oracle database server, SQL*Plus, and other Oracle products Down
Trang 7
Figure 11-2 Registry entries for Oracle near the bottom of this list, you should see an entry named SQLPATH You can edit this entry by double-clicking on it
Be sure to double-click the word SQLPATH itself, and not the string representing its current value You should see the dialog shown in Figure 11-3
Trang 8< previous page page_362 next page >
Trang 9New → String Value menu item Once you've created the new entry and given it the appropriate name, you can edit its value as described earlier When you are done making changes, use the Registry → Exit menu option to exit REGEDIT
Be extremely careful when using REGEDIT Consider using REGEDIT's File → Export Registry File menu item to make a backup first
Without a backup, there is no recourse if you make a mistake, and deleting the wrong key or entry could cause you some serious grief If you've never used REGEDIT before, ask someone who has to help you
If you open an MS-DOS window, you may use the SET command to change an environment variable When you do this, that setting only takes effect when you start SQL*Plus from the same MS-DOS window Thus, it is possible to have two or more MS-DOS windows open, each with a different SQLPATH setting
Windows 3.1
In a Windows 3.1 environment, the SQL*Plus environment variables are set using the DOS SET command Often this is
done from within the autoexec.bat file, so that all the settings are in place when the system starts The following
example shows how you would define the SQLPATH variable from a DOS prompt:
C:\>SET SQLPATH=C:\JONATHAN\SQL
You can use the SET command by itself to get a list of variables you have set; for example:
C:\>SET
SQLPATH=C:\JONATHAN\SQL
Environment Variables That AffectSQL*Plus.
This section describes the environment variables that affect SQL*Plus's operation Not all settings are available in all environments, but most are PLUS_DFLT is an example of a setting that's relevant only under Windows The
description for each setting will note whether or not it is operating-system-specific
Trang 10
The LOCAL setting applies only to Windows environments, and specifies the default connect string to use when you start SQL*Plus For example, if you start SQL*Plus under Windows, and enter only a usename and password as shown
in Figure 11-4, one of two things will happen If you have Oracle8 Personal Edition installed, you will be connected to the local database on your PC Otherwise, you will receive the following error:
ORA-03121: no interface driver connected - function not performed
Figure 11-4
Starting SQL*Plus with no connect string The reason you get an error is that when you leave off the connect string, SQL*Plus has no idea where to go The only exception to this is that Oracle has added some extra code to the version of SQL*Plus included with the Personal
Edition, so it will default to the Personal Edition database if there is one
By setting the LOCAL variable, you can make any Oracle database the default Setting it to PRODUCTION, for
example, makes SQL&Plus interpret Figure 11-4 as if the user had really typed in PRODUCTION for the connect string In other words, SQL*Plus would reinterpret the inputs shown in Figure 11-4 as those shown in Figure 11-5
By default, the Oracle installer will not create a LOCAL entry in the registry You have to create it Once you do,
SQL*Plus, even the version that ships with Oracle Personal Edition, will respect it