Shut down a database SHUTDOWN [ ABORT | IMMEDIATE | NORMAL | ... ]
Log out of SQL*Plus { EXIT | QUIT }
[ SUCCESS | FAILURE | WARNING | ... ]
[ COMMIT | ROLLBACK ]
Disconnect from a
database
DISCONNECT
Execute commands stored
in the SQL buffer
/
List and execute
commands stored in the
SQL buffer
RUN
Execute a single PL/SQL
statement or run a stored
procedure
EXECUTE statement
Add new lines following
current line in the SQL
buffer
INPUT [ text ]
DELETE DELETE [ hint ]
[ FROM ]
{ dml_table_expression_clause
| ONLY (dml_table_expression_clause)
}
[ t_alias ]
[ where_clause ]
[ returning_clause ] ;
DISASSOCIATE STATISTICS DISASSOCIATE STATISTICS FROM
{ COLUMNS [ schema. ]table.column
[, [ schema. ]table.column ]...
| FUNCTIONS [ schema. ]function
[, [ schema. ]function ]...
| PACKAGES [ schema. ]package
[, [ schema. ]package ]...
| TYPES [ schema. ]type
[, [ schema. ]type ]...
| INDEXES [ schema. ]index
[, [ schema. ]index ]...
| INDEXTYPES [ schema. ]indextype
[, [ schema. ]indextype ]...
}
[ FORCE ] ;
DROP CLUSTER DROP CLUSTER [ schema. ]cluster
[ INCLUDING TABLES [ CASCADE CONSTRAINTS ] ] ;
DROP CONTEXT DROP CONTEXT namespace ;
DROP DATABASE DROP DATABASE ;
DROP DATABASE LINK DROP [ PUBLIC ] DATABASE LINK dblink ;
DROP DIMENSION DROP DIMENSION [ schema. ]dimension ;
DROP DIRECTORY DROP DIRECTORY directory_name ;
DROP DISKGROUP DROP DISKGROUP diskgroup_name
[ { INCLUDING | EXCLUDING }
CONTENTS
] ;
DROP FUNCTION DROP FUNCTION [ schema. ]function_name ;
DROP INDEX DROP INDEX [ schema. ]index [ FORCE ] ;
DROP INDEXTYPE DROP INDEXTYPE [ schema. ]indextype [ FORCE ] ;
DROP JAVA DROP JAVA
{ SOURCE | CLASS | RESOURCE }
[ schema. ]object_name ;
DROP LIBRARY DROP LIBRARY library_name ;
DROP MATERIALIZED VIEW DROP MATERIALIZED VIEW
[ schema. ]materialized_view
[ PRESERVE TABLE ] ;
DROP MATERIALIZED VIEW LOG DROP MATERIALIZED VIEW LOG
ON [ schema. ]table ;
DROP OPERATOR DROP OPERATOR [ schema. ]operator [ FORCE ] ;
DROP OUTLINE DROP OUTLINE outline ;
DROP PACKAGE DROP PACKAGE [ BODY ] [ schema. ]package ;
DROP PROCEDURE DROP PROCEDURE [ schema. ]procedure ;
DROP PROFILE DROP PROFILE profile [ CASCADE ] ;
DROP ROLE DROP ROLE role ;
DROP ROLLBACK SEGMENT DROP ROLLBACK SEGMENT rollback_segment ;
DROP SEQUENCE DROP SEQUENCE [ schema. ]sequence_name ;
DROP SYNONYM DROP [ PUBLIC ] SYNONYM [ schema. ]synonym
[ FORCE ] ;
DROP TABLE DROP TABLE [ schema. ]table
[ CASCADE CONSTRAINTS ]
[ PURGE ] ;
DROP TABLESPACE DROP TABLESPACE tablespace
[ INCLUDING CONTENTS [ AND DATAFILES ]
[ CASCADE CONSTRAINTS ]
] ;
DROP TRIGGER DROP TRIGGER [ schema. ]trigger ;
DROP TYPE DROP TYPE [ schema. ]type_name
[ FORCE | VALIDATE ] ;
DROP TYPE BODY DROP TYPE BODY [ schema. ]type_name ;
DROP USER DROP USER user [ CASCADE ] ;
DROP VIEW DROP VIEW [ schema. ] view
[ CASCADE CONSTRAINTS ] ;
EXPLAIN PLAN EXPLAIN PLAN
[ SET STATEMENT_ID = 'text' ]
[ INTO [ schema. ]table [ @ dblink ] ]
FOR statement ;
FLASHBACK DATABASE FLASHBACK [ STANDBY ] DATABASE [ database ]
{ TO { SCN | TIMESTAMP } expr
| TO BEFORE { SCN | TIMESTAMP } expr
};
FLASHBACK TABLE FLASHBACK TABLE
[ schema. ]table
[, [ schema. ]table ]...
TO { { SCN | TIMESTAMP } expr
[ { ENABLE | DISABLE } TRIGGERS ]
| BEFORE DROP [ RENAME TO table ]
} ;
GRANT GRANT { grant_system_privileges
| grant_object_privileges
} ;
INSERT INSERT [ hint ]
{ single_table_insert | multi_table_insert } ;
LOCK TABLE LOCK TABLE
[ schema. ] { table | view }
[ { PARTITION (partition)
| SUBPARTITION (subpartition)
}
| @ dblink
]
[, [ schema. ] { table | view }
[ { PARTITION (partition)
| SUBPARTITION (subpartition)
}
| @ dblink
]
]...
IN lockmode MODE
[ NOWAIT ] ;
MERGE MERGE [ hint ]
INTO [ schema. ]table [ t_alias ]
USING [ schema. ] { table | view | subquery }
[ t_alias ]
ON ( condition )
[ merge_update_clause ]
[ merge_insert_clause ] ;
NOAUDIT NOAUDIT
{ sql_statement_clause
[, sql_statement_clause ]...
| schema_object_clause
[, schema_object_clause ]...
}
[ WHENEVER [ NOT ] SUCCESSFUL ] ;
PURGE PURGE
{ { TABLE table
| INDEX index
}
| { RECYCLEBIN | DBA_RECYCLEBIN }
| TABLESPACE tablespace
[ USER user ]
} ;
RENAME RENAME old_name
TO new_name ;
REVOKE REVOKE { revoke_system_privileges
| revoke_object_privileges
} ;
ROLLBACK ROLLBACK [ WORK ]
[ TO [ SAVEPOINT ] savepoint
| FORCE 'text'
] ;
SAVEPOINT SAVEPOINT savepoint ;
SELECT subquery [ for_update_clause ] ;
SET CONSTRAINT[S] SET { CONSTRAINT | CONSTRAINTS }
{ constraint [, constraint ]...
| ALL
}
{ IMMEDIATE | DEFERRED } ;
SET ROLE SET ROLE
{ role [ IDENTIFIED BY password ]
[, role [ IDENTIFIED BY password ] ]...
| ALL [ EXCEPT role [, role ]... ]
| NONE
} ;
SET TRANSACTION SET TRANSACTION
{ { READ { ONLY | WRITE }
| ISOLATION LEVEL
{ SERIALIZABLE | READ COMMITTED }
| USE ROLLBACK SEGMENT rollback_segment
}
[ NAME 'text' ]
| NAME 'text'
} ;
TRUNCATE TRUNCATE
{ TABLE [ schema. ]table
[ { PRESERVE | PURGE } MATERIALIZED VIEW LOG ]
| CLUSTER [ schema. ]cluster
}
[ { DROP | REUSE } STORAGE ] ;
UPDATE UPDATE [ hint ]
{ dml_table_expression_clause
| ONLY (dml_table_expression_clause)
}
[ t_alias ]
update_set_clause
[ where_clause ]
[ returning_clause ] ;
From Oracle 10g SQL*Plus will attempt to execute glogin.sql and login.sql after each successful connection. This is handy if you want to change the sqlprompt to include the current user. Here is an example (g)login.sql file:
The following example scripts can be used to include the connected username and database name into the prompt:
set sqlprompt "
_USER'@'_CONNECT_IDENTIFIER _PRIVILEGE> "
SQL*Plus tries to format data from the database into a human friendly format. This formatting can be disabled by issuing the following SET commands:
SET ECHO OFF
SET NEWPAGE 0
SET SPACE 0
SET PAGESIZE 0
SET FEEDBACK OFF
SET HEADING OFF
SET TRIMSPOOL ON
SET TAB OFF
The SQL*Plus COPY command is one of the fastest ways of copying data between databases and schemas. This is also one of the few methods that will handle LONG columns correctly. Look at this example:
One can generate static HTML pages from SQL*Plus (8.1.6 and above) by setting the MARKUP option to HTML ON. This can be done by specifying -MARKUP "HTML ON" from command line, or with the "SET MARKUP HTML ON" command. Look at this example SQL Script:
set markup HTML on
spool index.html
select * from tab;
spool off
set markup HTML off
AFIEDT.BUF is the SQL*Plus default edit save file. When you issue the command "ed" or "edit" without arguments, the last SQL or PL/SQL command will be saved to a file called AFIEDT.BUF and opened in the default editor.
In the prehistoric days when SQL*Plus was called UFI (User Friendly Interface) this file was named "ufiedt.buf", short for UFI editing buffer. When new features were added to UFI, it was the initially named Advanced UFI and the filename was changed to "aufiedt.buf" and then to "afiedt.buf". They presumably needed to keep the name short for compatibility with some of the odd operating systems that Oracle supported in those days. The name "Advanced UFI" was never used officially, as the name was changed to SQL*Plus before this version was released.
You can overwrite the default edit save file's name like this:
SET EDITFILE "afiedt.buf"
Here is a list of some of the most frequently used SQL*Plus commands:
ACCEPT - Get input from the user
DEFINE - Declare a variable (short: DEF)
DESCRIBE - Lists the attributes of tables and other objects (short: DESC)
EDIT - Places you in an editor so you can edit a SQL command (short: ED)
EXIT or QUIT - Disconnect from the database and terminate SQL*Plus
GET - Retrieves a SQL file and places it into the SQL buffer
HOST - Issue an operating system command (short: !)
LIST - Displays the last command executed/ command in the SQL buffer (short: L)
PROMPT - Display a text string on the screen. Eg prompt Hello World!!!
RUN - List and Run the command stored in the SQL buffer (short: /)
SAVE - Saves command in the SQL buffer to a file. Eg "save x" will create a script file called x.sql
SET - Modify the SQL*Plus environment eg. SET PAGESIZE 23
SHOW - Show environment settings (short: SHO). Eg SHOW ALL, SHO PAGESIZE etc.
SPOOL - Send output to a file. Eg "spool x" will save STDOUT to a file called x.lst
START - Run a SQL script file (short: @)
One can pass operating system variables to sqlplus using this syntax:
sqlplus username/password @cmdfile.sql var1 var2 var3
Parameter var1 will be mapped to SQL*Plus variable &1, var2 to &2, etc. Look at this example:
sqlplus scott/tiger @x.sql '"test parameter"' dual
Where x.sql consists of:
select '&1' from &2;
exit 5;
Info received from Tim Kessler:
Since I occasionally get useful info from your side I felt it is appropriate to add the following:
Example passing the Windows User's Temp Path Location to sqlplus:
sqlplus username/password @cmdfile.sql %TEMP%
within @cmdfile.sql -
SPOOL &1\myscript.log
-- Your script commands
SPOOL OFF