本人来自转载,最开始是英文文档,某人加了注释
SQL*PLUS中new_value的作用还是挺大的,多次在写脚本时用到它。使用new_value,可以方便的保存从Oracle表中选择出的数据,存为变量使用。
小结了三种使用方法,只是用到的地方不同,调用new_value的方法还是相同的:
#!/bin/sh
export ORACLE_SID=CMPR1
export ORACLE_HOME=/app/oracle/product/9205
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus -s/nolog< <EOF
conn / as sysdba
prompt ###############定义new_value###############
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 ###############方法一:直接作为变量调用###############
select dbid,name from v$database where name='&ndb_name';
prompt ###############方法二:传到其它变量中调用###############
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 ###############方法三:作为SQL脚本的变量调用###############
@cs.sql &ndb_name &ndbid &ninst_num
Exit
EOF
[/app/oracle/utils/scripts]$ cat cs.sql
----------可以数字1、2、3,表示调用变量的顺序
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;
----------也可以直接用new_value
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;
这里需要注意的是,new_value只能保存一个变量值,如果选择出来的数据大于一行,则只保存最后一个: SQL> column a new_value a_value
SQL> select a from t;
A
----------
1
3
2
4
5
6
7
8
9
9 rows selected.
SQL> create table t1(b number);
Table created.
SQL> insert into t1 values (&a_value); --返回值多于一行,最后一个值传到变量中
old 1: insert into t1 values (&a_value)
new 1: insert into t1 values ( 9)
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t where a=&a_value;
old 1: select * from t where a=&a_value
new 1: select * from t where a= 9
A
----------
9
SQL> select * from t1;
B
----------
9
SQL>
|
分享到:
相关推荐
§15.4 在 PL/SQL 中使用 sqlcode,sqlerrm 273 第十六章 存储过程和函数 276 §16.1 引言 276 §16.2 存储过程 276 §16.2.1 创建过程 276 §16.2.2 使用过程 278 §16.2.3 开发存储过程步骤 279 §16.2.3.1 编辑...
功能: 1、 允许/限制对表的修改 2、 自动生成派生列,比如自增字段 3、 ...id on employees referencing old as old_value new as new_value for each row when (new_value.department_id<>80 ) begin :new_value
Alter table table_name add (new_colum_name datatype [default value] [not null]) 修改列类型 Alter table…modify Alter table table_name modify column_name new_datatype 修改列名 Alter table…rename Alter...
例子一,获取三小时前的记录 public static DataTable ... OracleParameter[] parameters = {new OracleParameter(":gxsj", OracleType.VarChar, 10)}; parameters[0].Value = DateTime.Now.AddHours(-3).ToStrin
Alter table table_name add (new_colum_name datatype [default value] [not null]) 修改列类型 Alter table…modify Alter table table_name modify column_name new_datatype 修改列名 Alter table…rename Alter...
其一、就业面广:全球前100强企业99家都在使用ORACLE相关技术,中国政府机构,大中型企事业单位都能有ORACLE技术的工程师岗位。 其二、技术层次深:如果期望进入IT服务或者产品公司(类似毕博、DELL、IBM等),...
例如,我们可以通过这段代码输出当前时间点的时间戳 代码如下:[removed] [removed](new Date().valueOf());[removed]那么何为时间戳呢? 时间戳就是从1970年1月1日0时0分0秒到当前时间点的所有秒数。1970.1.1 0:0:0...
Expert Oracle Exadata, 2nd Edition opens up the internals of Oracle's Exadata platform so that you can fully benefit from the most performant and scalable database hardware appliance capable of ...
20.oracle8中扩充了group by rollup和cube的操作。有时候省了你好多功夫的。 下面的语句可以进行总计 select region_code,count(*) from aicbs.acc_woff_notify group by rollup(region_code); <2> 对第1个字段...
column db_block_size new_value blksz noprint select value db_block_size from v$parameter where name=\'db_block_size\'; column tablespace_name format a16; column file_name format a60; set linesize ...
ab_Inline in Boolean Default False --True将文本内容直接在邮件内容显示出来,并出现在附件中,False不显示只出现在附件中 ); -----------------自动签名的生成,签名生成显示后还出现此签名文件为附件...
Anyone developing new applications or converting existing applications to run in the Oracle database version 7 environment will benefit from reading this guide. Written especially for programmers, ...
If you're new to Exadata, you'll soon learn that it embodies a change in how you think about and manage relational databases. A key part of that change lies in the concept of offloading SQL ...
* Compiler Hints added for unused declarations, unused value assignments, comparison with NULL, function without return, and to_date without format * Code Assistant can now use original case for ...
ORACLE OSB开发指南,英文版。 目录: Part I IDE Help for Oracle Service Bus 1 Introduction to Oracle Service Bus 2 Tasks Working with Projects, Folders, Resources, and Configurations .....................
操作oracle数据库的记录集 Dim rst As ADODB.Recordset CommonDialog1.ShowOpen extend_str = Right(CommonDialog1.FileName, 3) If (extend_str = "xls") Then execl_cnn.Open "Provider=Microsoft.Jet.OLE...
REFERENCING 子句说明相关名称,在行触发器的PL/SQL块和WHEN 子句中可以使用相关名称参照当前的新、旧列值,默认的相关名称分别为OLD和NEW。触发器的PL/SQL块中应用相关名称时,必须在它们之前加冒号(:),但在WHEN...
OracleParameter parameter = new OracleParameter(":", oracleType); parameter.SourceColumn = columnInfo.PropertyName; parameter.Value = DBNull.Value; return parameter; } private OracleType ...
A:create table tab_new like tab_old (使用旧表创建新表) B:create table tab_new as select col1,col2… from tab_old definition only 5、说明:删除新表 drop table tabname 6、说明:增加一个列 Alter table...
“The value of Oracle Solaris 11 is that it maintains all the enterprise-class features expected with a mission-critical OS, while bringing in new, innovative technologies. Forsythe has a long and ...