1 sav 命令使用
1.1 用 sav 命令保存文件内容
TYGER@ORCL>create table t as select * from user_tables;
Table created.
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql
Created file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ ls
sel_t.sql
[oracle@tyger ~]$ cat sel_t.sql
select count(*) from t
/
[oracle@tyger ~]$
1.2 覆盖内容 sav filename rep
TYGER@ORCL>l
1* select * from t order by 1
TYGER@ORCL>sav /home/oracle/sel_t.sql rep
Wrote file /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$
1.3 追加内容 sav filename app
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
[oracle@tyger ~]$ exit
exit
TYGER@ORCL>select count(*) from t;
COUNT(*)
----------
11
TYGER@ORCL>sav /home/oracle/sel_t.sql app
Appended file to /home/oracle/sel_t.sql
TYGER@ORCL>!
[oracle@tyger ~]$
[oracle@tyger ~]$ cat sel_t.sql
select * from t order by 1
/
select count(*) from t
/
[oracle@tyger ~]$
2. spool 命令使用
spool on 表示将缓存打开,不然只能保存最近执行的1条命令;
spool filename 表示将缓存中出现的命令以及结果输出到某个文件中;
spool off 表示关闭缓存,同时文件会自动保存;
[oracle@tyger ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jun 18 13:52:25 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SYS@ORCL>spool /home/oracle/sel_emp.sql
SYS@ORCL>conn scott/tiger;
Connected.
SCOTT@ORCL>select empno,ename from emp;
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER
EMPNO ENAME
---------- ----------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
---------- ----------
7900 JAMES
7902 FORD
7934 MILLER