引用如下
Oracle SQL*Plus has a very useful new sub
By using the new_value parameter you can make your SQL*Plus script behave like a real programming language
The ability to store SQL*Plus variables and fill them with Oracle data is a very powerful feature and makes SQL*Plus scripts more efficient because database access is reduced
使用方法如下
#!/bin/sh
export ORACLE_SID=CMPR
export ORACLE_HOME=/app/oracle/product/
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus
conn / as sysdba
column inst_num new_value ninst_num format
column inst_name new_value ninst_name format a
column db_name new_value ndb_name format a
column dbid new_value ndbid format
select d
from v$database d
v$instance i;
prompt ###############Use new_value####################
select dbid
prompt ################Use variable###################
variable dbid number;
variable inst_num number;
begin
:dbid := &ndbid;
:inst_num := &ninst_num;
end;
/
select instance_name
select dbid
prompt ##############Use sql file#####################
@cs
Exit
EOF
[/app/oracle/utils/scripts]$ cat cs
select dbid
variable dbid number;
variable inst_num number;
begin
:dbid := &
:inst_num := &
end;
/
select instance_name
select dbid
variable dbid number;
variable inst_num number;
begin
:dbid := &ndbid;
:inst_num := &ninst_num;
end;
/
select instance_name
select dbid
From:http://tw.wingwit.com/Article/program/Oracle/201311/18174.html