SQL中用new_value把查询结果传给变量_SQL SERVER数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

SQL中用new_value把查询结果传给变量

作者:黑客防线网安SQL维护基地 来源:黑客防线网安SQL维护基地 浏览次数:0

本篇关键词:变量结果查询dbid
黑客防线网安网讯:    SQLPLUS中new_value的作用还是挺大的。利用这个倒是能解决挺多问题的。 引用这么段话: Oracle SQL*Plus has a very useful new sub-parameter to the column parameter called new_val...

    SQLPLUS中new_value的作用还是挺大的利用这个倒是能解决挺多问题的
引用这么段话:

Oracle SQL*Plus has a very useful new sub-parameter to the column parameter called new_value.

The new_value directive allows data that has been retrieved from an Oracle table to be stored as a

variable inside the SQL*Plus script.

By using the new_value parameter you can make your SQL*Plus script behave like a real

programming language, storing and addressing program variables, just like in PL/SQL.

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=CMPR1

export ORACLE_HOME=/app/oracle/product/9205

export PATH=$ORACLE_HOME/bin:$PATH

sqlplus -s/nolog <

conn / as sysdba

column inst_num new_value ninst_num format 99999;

column inst_name new_value ninst_name format a12;

column db_name new_value ndb_name format a12;

column dbid new_value ndbid format 9999999999;


select d.dbid dbid

, d.name db_name

, i.instance_number inst_num

, i.instance_name inst_name

from v$database d,

v$instance i;

prompt ###############Use new_value####################

select dbid,name from v$database where name=’&ndb_name’;


prompt ################Use variable###################

variable dbid number;

variable inst_num number;

begin

:dbid := &ndbid;

:inst_num := &ninst_num;

end;

/


select instance_name,instance_number from v$instance where instance_number=:inst_num;

select dbid,name from v$database where dbid=:dbid;


prompt ##############Use sql file#####################

@cs.sql &ndb_name &ndbid &ninst_num

Exit

EOF


[/app/oracle/utils/scripts]$ cat cs.sql

select dbid,name from v$database where name=’&1’;


variable dbid number;

variable inst_num number;

begin

:dbid := &2;

:inst_num := &3;

end;

/

select instance_name,instance_number from v$instance where instance_number=:inst_num;

select dbid,name from v$database where dbid=:dbid;


variable dbid number;

variable inst_num number;

begin

:dbid := &ndbid;

:inst_num := &ninst_num;

end;

/

select instance_name,instance_number from v$instance where instance_number=:inst_num;

select dbid,name from v$database where dbid=:dbid;

 

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-11288-1.html
网站维护教程更新时间:2012-03-21 03:19:34  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer