捷凌网安Oracle频道
中国IT教育
首页 入门基础 安装配置 体系架构 PLSQL 备份恢复 性能调优 开发技术 资讯动态 考试认证 讨论
 您现在的位置: 捷凌网安 >> Oracle >> 入门基础 >> 正文
如何使用new_value将查询结果传递给变量

作者:佚名 责任编辑:左决 点击数: 更新时间:2008-4-15 5:14:55

在实际应用中,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;

  • 上一篇文章:

  • 下一篇文章:
  •  
     最进更新
    普通文章如何获得Oracle DBA工作?05-11
    普通文章分别删除数据表记录的方法05-11
    普通文章实例讲解删除表空间时存在的05-11
    普通文章Oracle Wait Event:Data fil05-11
    普通文章重复利用这个外部表的表结构05-11
    普通文章Oracle 9i数据库的用户创建以05-11
    普通文章Oracle数据库应用程序中RAID05-11
    普通文章如何更改监听器设置05-11
    普通文章Oracle中SQL语句执行效率的查05-11
    普通文章掌握数据库链路的建立和使用05-11
     
     推荐文章
    推荐文章研究人员发现攻击Oracle数据04-30
    推荐文章研究人员找到新方法黑掉Orac04-30
    推荐文章数据库产业商业模式大猜想04-30
    推荐文章一种并发控制的精典案例04-30
    推荐文章讲解Oracle在Solaris下的性能04-30
    推荐文章Oracle中为什么会产生回滚与04-30
    推荐文章实例讲解sql_trace和access 04-30
    推荐文章Oracle数据库9i和10g环境下使04-30
    推荐文章Oracle数据库后台进程的具体04-30
    推荐文章Oracle数据库中Undo数据段的04-30
     
     热点文章
    普通文章PB内置Oracle数据库接口的使03-27
    普通文章用最简单的方法记录Oracle语03-27
    推荐文章教你快速掌握Oracle数据库的03-27
    推荐文章详细讲解"Oracle"数据库的“03-27
    普通文章深入讲解Oracle数据库的多栏03-27
    推荐文章教你快速掌握一个简单的Orac03-27
    推荐文章初学者应该如何理解Oracle的03-27
    普通文章怎样将"Oracle"的外部表汉字03-27
    推荐文章解决不同字符集数据库间的数03-27
    普通文章Oracle的window服务启动时并03-27

    | 设为首页 | 加入收藏 | 联系站长 | 广告服务 | 友情链接 | 版权申明 | 网站地图 |

    在线交流 捷凌网安主群:51649627
    Copyright 2007-2008 © 捷凌网安. All rights reserved.
    备案序号:蜀ICP备08001812号