[20181203]bash here $.txt
--//有时候使用bash编程调用sqlplus的here.如果脚本里面sql语句存在$,要转义一下.
--//如果很多处理起来会比较麻烦.通过例子说明问题:
$ sqlplus -s -l scott/book <
> set numw 12
> select current_scn from v$database ;
> EOF
select current_scn from v
*
ERROR at line 1:
ORA-04044: procedure, function, package, or type is not allowed here
--//v$database 中$database被bash解析为变量.一般常规的做法是转义一下.
$ sqlplus -s -l scott/book <
> set numw 12
> select current_scn from v\$database ;
> EOF
CURRENT_SCN
------------
13815329111
--//一种做法建立脚本:
$ cat a.txt
set numw 12
select current_scn from v$database ;
quit
$ sqlplus -s -l scott/book @a.txt
CURRENT_SCN
------------
13815329331
$ sqlplus -s -l scott/book <
> $(cat a.txt)
> EOF
CURRENT_SCN
------------
13815329287
--//实际上还有另外的做法就是给EOF加入引号,这样里面$就不需要转义.
$ sqlplus -s -l scott/book <
> set numw 12
> select current_scn from v$database ;
> EOF
CURRENT_SCN
------------
13815329741
--//注意后面的EOF不需要引号.
$ sqlplus -s -l scott/book <
> set numw 12
> select current_scn from v$database ;
> EOF
CURRENT_SCN
------------
13815329823