SQL Plus

SQL Plus

To save settings of a SQLplus session (like "set linesize") as default

Check out ORACLE_HOME/sqlplus/admin. There's a file in there called "glogin.sql". Make changes to that, such as pagesize
and linesize, and every time you then log onto SQL*Plus, those settings will take effect.

You can over-ride the glogin.sql settings by creating a login.sql, too. If it's in the directory where you launch SQL*Plus from, then login.sql takes precedence over glogin.sql.


To edit the buffer file afiedt.buf

 SQL> edit

To rerun the last command you entered which is the in the buffer file afiedt.buf

 SQL> / <return>

To run an SQL query that is in a file named myquery.sql

 SQL> start myquery
        (or)
 SQL> @ myquery.sql

To install a procedure named proc1 in the database from a file named mydbproc.sql (Make sure the first line of the file begins create or replace procedure proc1. Make sure the last line of the script contains a forward slash / on a line by itself with no spaces)

 SQL> start mydbproc 

To see compilation errors, at the SQL> prompt type show errors
If there were no errors, proc1 is now installed in the database and available to be run
To run proc1 which you just installed, at the SQL> prompt type exec proc1;

The SET command

You can control various features of SQLPLUS using the SET command at the SQL> prompt. These commands do not need a semicolon but SQLPLUS is kind enough to let you use one.

To repeat the column headers every 100 lines rather than every 14

 SQL> set pagesize 100 

To make the screen 100 characters wide rather than 80

 SQL> set linesize 100 

To show one screen (pagesize lines) at a time (shows you one screen (pagesize lines) at a time)

 SQL> set pause on 

To show the sql commands on the screen when they are executed from a file using the start command

 SQL> set echo 

To display XXX instead of blanks for a null field

 SQL> set null XXX 

To make DBMS_OUTPUT commands actually work

 SQL> set serveroutput on 

Other SQLPLUS Commands

To send a copy of the terminal activity to myfile.lst

 SQL> spool myfile.1st

To write the contents of file myfile.sql to SQL buffer

 SQL> Get myfile.sql 

To display the basic information about mytable's fields

 SQL> describe mytable  

To go out temporarily to Unix shell from sqlplus (To get back to SQLPLUS, type exit)

 SQL> !* (exclamation point)

To Shell out to the operating system, run the ls command and return to SQLPLUS

 SQL> !ls