某Q友问题—为何sqlplus中new_value后续的..到底为何含义

前言

   spool产生的输出文件如果用到&变量,其形式为spool &var..log,这2个.到底含义是什么呢?本文我们测试下这个


测试结论
1,new_value即把select from 中的查询结果可以传递给new_value指定的参数
2,&filedate为变量,此变量用于spool中,后面必须跟2个..,最终扩展中为log,显示出来才是文件名称.log
3,&filedate后面2个.  表示1个. ,而3个.表示2个.,其实就类似于转义字符
   而如果后跟1外.,直接就忽略了这个.
   

测试明细
通过new_value参数化filedate
SQL> col filedate new_value filedate

把系统日期存在到参数filedate
SQL> select to_char(sysdate,'yyyymmddhh24miss') filedate from dual;

FILEDATE
--------------
20150615082504

把上述参数filedate用于spool输出的文件名称中,注意后面是2个..
SQL> spool insert_after&filedate..log
SQL> select * from dual;

D
-
X

SQL> spool off;

产生的spool文件为insert_after加上系统日期.log
SQL> ! ls -ltr

-rw-r--r-- 1 oracle oinstall 286 06-15 08:25 insert_after20150615082504.log

再看下如果是1个.会如何
SQL> spool insert_after&filedate.log
SQL> select * from dual;

D
-
X

1个.则spool生成的文件名称为insert_after系统日期及log,且自动生成文件扩展名.lst
SQL> spool off;
SQL> ! ls -ltr

-rw-r--r-- 1 oracle oinstall 286 06-15 08:26 insert_after20150615082504log.lst


查阅官方手册,获取spool具体用法
SQL*Plus? User's Guide and Reference
Release 11.2

SPOOL

Syntax

SPO[OL] [file_name[.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT]

Stores query results in a file, or optionally sends the file to a printer.

Terms

file_name[.ext]

Represents the name of the file to which you wish to spool. SPOOL followed by file_name begins spooling displayed output to the named file. If you do not specify an extension, SPOOL uses a default extension (LST or LIS on most systems). The extension is not appended to system files such as /dev/null and /dev/stderr.

CRE[ATE]

Creates a new file with the name specified.

REP[LACE]

Replaces the contents of an existing file. If the file does not exist, REPLACE creates the file. This is the default behavior.

APP[END]

Adds the contents of the buffer to the end of the file you specify.

OFF

Stops spooling.

OUT

Stops spooling and sends the file to your computer's standard (default) printer. This option is not available on some operating systems.

Enter SPOOL with no clauses to list the current spooling status.

Usage

To spool output generated by commands in a script without displaying the output on the screen, use SET TERMOUT OFF. SET TERMOUT OFF does not affect output from commands that run interactively.

You must use quotes around file names containing white space.

To create a valid HTML file using SPOOL APPEND commands, you must use PROMPT or a similar command to create the HTML page header and footer. The SPOOL APPEND command does not parse HTML tags.


SET SQLPLUSCOMPAT[IBILITY] to 9.2 or earlier to disable the CREATE, APPEND and SAVE parameters. See SQL*Plus Compatibility Matrix to determine what functionality is controlled by the SET SQLPLUSCOMPAT[IBILITY] command.

主要看上述标色的手册部分,可知SPOOL默认的输出文件如不添加扩展名,默认为lst或者lis

SQL> spool off
SQL> !ls -lrt

-rw-r--r-- 1 oracle oinstall 291 06-15 08:32 onlytest.lst


SQL> host rm -rf *

SQL> !ls -rt

如果后面跟3个.,最终显示2个.,可见..表示1个.
SQL> spool insert_after&filedate...log
SQL> select 1 from dual;

1
----------
1

SQL> spool off
SQL> !ls -trt
insert_after20150615082504..log


个人简介

8年oracle从业经验,具备丰富的oracle技能,目前在国内北京某专业oracle服务公司从事高级技术顾问。
服务过的客户:
中国电信
中国移动
中国联通
中国电通
国家电网
四川达州商业银行
湖南老百姓大药房
山西省公安厅
中国邮政
北京302医院     
河北廊坊新奥集团公司

 项目经验:
中国电信3G项目AAA系统数据库部署及优化
中国联通CRM数据库性能优化
中国移动10086电商平台数据库部署及优化
湖南老百姓大药房ERR数据库sql优化项目
四川达州商业银行TCBS核心业务系统数据库模型设计和RAC部署及优化
四川达州商业银行TCBS核心业务系统后端批处理存储过程功能模块编写及优化
北京高铁信号监控系统RAC数据库部署及优化
河南宇通客车数据库性能优化
中国电信电商平台核心采购模块表模型设计及优化
中国邮政储蓄系统数据库性能优化及sql优化
北京302医院数据库迁移实施
河北廊坊新奥data guard部署及优化
山西公安厅身份证审计数据库系统故障评估
国家电网上海灾备项目4 node rac+adg 
          贵州移动crm及客服数据库性能优化项目
          贵州移动crm及客服务数据库sql审核项目
          深圳穆迪软件有限公司数据库性能优化项目
联系方式:
手机:18201115468
qq   :   305076427
qq微博: wisdomone1
新浪微博:wisdomone9
qq群:275813900    
itpub博客名称:wisdomone1     http://blog.itpub.net/9240380/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-1700500/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-1700500/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值