zeng
作者zeng·2012-02-10 21:04
数据仓库工程师·福建富士通信息软件有限公司

详解sql*plus spool命令

字数 2824阅读 3590评论 0赞 0
详解sql*plus spool命令

    spool允许你把一句或者多句sql语句输出保存为,操作系统文件。
SQL> spool emp_salary.lst    //指定输出的文件名
SQL> select first_name,last_name,salary
  2  from employees;
SQL> spool off //结束输出
SQL> !
[oracle@zeng ~]$ ll
total 360
-rw-r--r--. 1 oracle oinstall     29 Feb  6 13:12 afiedt.buf
-rw-r--r--. 1 oracle oinstall  15635 Feb  5 20:43 db.rsp
drwxr-xr-x. 3 oracle oinstall   4096 Feb  6 11:06 Desktop
drwxr-xr-x. 2 oracle oinstall   4096 Feb  5 17:12 Documents
drwxr-xr-x. 2 oracle oinstall   4096 Feb  5 20:29 Downloads
-rw-r--r--. 1 oracle oinstall   9099 Feb 10 20:24 emp_salary.lst
如果在spool后面的输出文件名那一栏不指定路径的话,默认在登录用户的home目录下,可以使用相应的命令查看文件中的内容。

SQL> spool /tmp/sgainfo.lst //指定路径与文件名
SQL> select * from V$sgainfo;
SQL> spool out
lpr: Error - no default destination available.
当没有默认打印机的时候,使用off输出也会保存,但是会跳出上面的提示。
[oracle@zeng tmp]$ more sgainfo.lst     //回到操作系统中查看spool文件的内容。
SQL> select * from V$sgainfo;
NAME                                  BYTES RES
-------------------------------- ---------- ---
Fixed SGA Size                      1336120 No
Redo Buffers                        6373376 No
Buffer Cache Size                 159383552 Yes
Shared Pool Size                   96468992 Yes
Large Pool Size                    29360128 Yes
Java Pool Size                     12582912 Yes
Streams Pool Size                         0 Yes
Shared IO Pool Size                       0 Yes
Granule Size                        4194304 No
Maximum SGA Size                  305508352 No
Startup overhead in Shared Pool    62914560 No

NAME                                  BYTES RES
-------------------------------- ---------- ---
Free SGA Memory Available                 0
12 rows selected.
SQL> spool out

spool的语法格式:
spool { file_name[.ext] [create|replace|append]| off | out }
file_name:指定输出的文件名。默认的文件扩展名是.lst。
create:创建一个新的文件。
replace:默认使用该项.覆盖原有文件中的内容,如果原文件不存在则,新建一个输出文件。
append:把输出内容追加到指定的文件中。
off:停止输出。
out:停止输出,并发送到默认的打印机,该命令在有些操作系统上面不可用。

使用spool输出不困难,重要与有意思的是,输出文件的用途:
用作错误的分析。
打印输出结果。
用于sql*load加载到其他表。
简单用作某些信息的存档。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广