Administering SQL*Plus

 


Using Setup Files

When you start SQL*Plus, it executes the glogin.sql site profile set-up file and then executes the login.sql user profile set-up file.

 

Using the Site Profile File

The global site profile file is $ORACLE_HOME/sqlplus/admin/glogin.sql. If a site profile already exists at this location, it is overwritten when you install SQL*Plus. If SQL*Plus is removed, the site profile file is deleted.

 

Using the User Profile File

The user profile file is login.sql. SQL*Plus looks for this file in the current directory, and then in the directories you specify using the SQLPATH environment variable. Set this environment variable to a colon-separated list of directories. SQL*Plus searches these directories for the login.sql file in the order they are listed.

The options set in the login.sql file override those set in the glogin.sql file.

 

Using the PRODUCT_USER_PROFILE Table

During a Typical installation, the PRODUCT_USER_PROFILE table is created automatically. This table is used to disable the SQL and SQL*Plus commands you specify. To recreate this table, run the
$ORACLE_HOME/sqlplus/admin/pupbld.sql script in the SYSTEM schema.

For example, enter:

$ sqlplus SYSTEM/MANAGER
SQL> @?/sqlplus/admin/pupbld.sql

SQL*Plus uses the value of the ORACLE_HOME environment variable wherever a question mark ( ? ) appears.

 

Using Demonstration Tables

SQL*Plus is shipped with demonstration tables that you can use for testing.

 

Performing a Typical Installation

During a Typical installation, the user SCOTT and the demonstration tables are created automatically.

 

Creating Demonstration Tables Manually

Use the $ORACLE_HOME/sqlplus/demo/demobld.sql SQL script to create the demonstration tables. In SQL*Plus, you can use any username to run the demobld.sql file to create the demonstration tables in a schema. For example, enter:

$ sqlplus SCOTT/TIGER 
SQL> @?/sqlplus/demo/demobld.sql

You can also use the $ORACLE_HOME/bin/demobld shell script to run the demobld.sql script by entering the following command:

$ demobld scott tiger

 

Deleting Demonstration Tables

Use the $ORACLE_HOME/sqlplus/demo/demodrop.sql script to drop the demonstration tables. In SQL*Plus, you can use any username to drop the demonstration tables from the user's schema. For example, enter:

$ sqlplus SCOTT/TIGER 
SQL> @?/sqlplus/demo/demodrop.sql

You can also use the $ORACLE_HOME/bin/demodrop shell script to run the demodrop.sql script by entering the following:

$ demodrop SCOTT TIGER


Both the demobld.sql and demodrop.sql scripts drop the EMP, DEPT, BONUS, SALGRADE, and DUMMY tables. Before you run these scripts, make sure that these tables do not exist or are not in use for other purposes. 

 

SQL*Plus Online Help

This section describes how to install and remove the SQL*Plus online help.

 

Installing the SQL*Plus Online Help

There are four ways to install the SQL*Plus online help:

  • Perform a Typical installation

    When you copy a starter database with pre-built datafiles as part of the Typical installation, SQL*Plus automatically installs the SQL*Plus online help.

  • Use the Database Configuration Assistant

    You can use the Oracle Database Configuration Assistant to create help tables when creating a database.

  • Install the online help manually using the helpins shell script

    You can use the $ORACLE_HOME/bin/helpins shell script to manually install the online help. Before you run the script, set the SYSTEM_PASS environment variable to the SYSTEM username and password. For example, enter:

    $ SYSTEM_PASS=SYSTEM/MANAGER; export SYSTEM_PASS
    
    
  • Install the online help manually using the helpbld.sql SQL script

    You can use the $ORACLE_HOME/sqlplus/admin/help/helpbld.sql script with the helpus.sql script to manually install the online help. For example, enter:

    $ cd $ORACLE_HOME/sqlplus/admin/help
    $ sqlplus SYSTEM/MANAGER
    SQL> @helpbld.sql helpus.sql
    
    

    Both the helpins shell script and the helpbld.sql SQL*Plus script drop existing online help tables before creating new tables. 

 

Removing the SQL*Plus Online Help

You can also run the $ORACLE_HOME/sqlplus/admin/help/helpdrop.sql in SQL*Plus to manually drop the online help tables from a schema. For example, enter:

$ sqlplus SYSTEM/MANAGER
SQL> @?/sqlplus/admin/help/helpdrop.sql

 

Using SQL*Plus

This section describes how to use SQL*Plus on UNIX systems.

 

Using a System Editor from SQL*Plus

If you enter an ED or EDIT command at the SQL*Plus prompt, the system starts an operating system editor, such as ed, emacs, ned, or vi. The PATH variable must include the directory where the editor executable is located.

When you start the editor, the current SQL buffer is placed in the editor. When you exit the editor, the changed SQL buffer is returned to SQL*Plus.

You can specify which editor starts by defining the SQL*Plus _EDITOR variable. You can define this variable in the glogin.sql site profile, the login.sql user profile, or define it during the SQL*Plus session. For example, to set the default editor to vi, enter:

SQL> DEFINE _EDITOR=vi

If you do not set the _EDITOR variable, the value of either the EDITOR or the VISUAL environment variable is used. If both environment variables are set, the value of the EDITOR variable is used. When _EDITOR, EDITOR, and VISUAL are not specified, the default editor is ed.

If you start the editor, SQL*Plus uses the afiedt.buf temporary file to pass text to the editor. You can use the SET EDITFILE command to specify a different filename. For example, enter:

SQL> SET EDITFILE /tmp/myfile.sql

SQL*Plus does not delete the temporary file.

 

Running Operating System Commands from SQL*Plus

Using the HOST command or an exclamation mark (!) as the first character after the SQL*Plus prompt causes subsequent characters to be passed to a sub-shell. The SHELL environment variable sets the shell used to execute operating system commands. The default shell is the Bourne shell (/bin/sh). If the shell cannot be executed, an error message is displayed.

To return to SQL*Plus, enter EXIT or press Ctrl+d.

For example, to execute one command, enter:

SQL>! command

In the preceding example, command  represents the operating system command you want to execute.

To execute multiple operating system commands from SQL*Plus, enter the HOST or ! command then press Return. SQL*Plus returns you to the operating system prompt.

 

Interrupting SQL*Plus

While running SQL*Plus, you can stop the scrolling record display and terminate a SQL statement by pressing Ctrl+c.

 

Using the SPOOL Command

The default file extension of files generated by the SPOOL command is .lst. To change this extension, specify a spool file containing a period (.). For example, enter:

SQL> SPOOL query.txt

 

SQL*Plus Restrictions

This section describes SQL*Plus restrictions.

 

Resizing Windows

The default values for SQL*Plus LINESIZE and PAGESIZE do not automatically adjust for window size.

 

Return Codes

UNIX return codes use only one byte, which is not enough space to return an Oracle error code. The range for a return code is 0 to 255.