ITPub博客

首页 > 数据库 > Oracle > [20230303]sqlplus column new_value old_value.txt

[20230303]sqlplus column new_value old_value.txt

原创 Oracle 作者:lfree 时间:2023-03-03 08:49:12 0 删除 编辑

[20230303]sqlplus column new_value old_value.txt

--//前几天在测试时遇到的问题,我以为定义列
column xxxx new_value x2 old_value x1
--//new_value 保存新值在X2中。保存原来的旧值在X1中,实际上并不是这个意思,我理解错误。
--//通过例子说明:

1.环境:
SCOTT@test01p> @ ver1

PORT_STRING                    VERSION        BANNER                                                                               CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0           12.2.0.1.0     Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production              0

--//链接:https://www.orafaq.com/node/515

OLD_VALUE vs. NEW_VALUE

OLD_VALUE acts very similarly to NEW_VALUE:

The difference between the two only really comes up when you're using them for their intended purpose, to help you put
page headers and footers on sql*plus reports. The current value of NEW_VALUE and OLD_VALUE can be displayed in report
headers(TTITLE, REPHEADER) and footers (BTITLE, REPFOOTER). NEW_VALUE variables hold data from the new row about to be
printed on the page; OLD_VALUE variables hold data from the old row that was most recently printed on the page. Thus,
NEW_VALUE is usefulfor the report header, OLD_VALUE for the report footer. When you're just using NEW_VALUE and
OLD_VALUE to get values from thedatabase into script variables, either NEW_VALUE or OLD_VALUE will do.

只有当你为其预期的目的使用它们时,这两者之间的区别才会真正显现出来,以帮助你将页眉和页脚放在sql*+报告上。NEW_VALUE和
OLD_VALUE的当前值可以显示在报表页头(TTITLE、重新页头)和页脚(BTITLE、重新页脚)中。NEW_VALUE变量保存即将打印在页面上的新
行中的数据;OLD_VALUE变量保存来自最近打印在页面上的旧行中的数据。因此,NEW_VALUE对于报表页头有用,OLD_VALUE对于报表页脚
有用。当您只是使用NEW_VALUE和OLD_VALUE从数据库中获取值到脚本变量时,NEW_VALUE或OLD_VALUE都可以使用。
--//我看了半天没看明白。似乎两者在脚本中是一样的。

When you're just using NEW_VALUE and OLD_VALUE to get values from the database into script variables, either NEW_VALUE
or OLD_VALUE will do.
--//自己很少使用sqlplus repoer类型,总之没有一个好的例子说明其用途。

2.测试:
SCOTT@test01p> column current_scn new_value v_scn2 old_value v_scn1
SCOTT@test01p> select current_scn from v$database;
CURRENT_SCN
-----------
   14430020

SCOTT@test01p> select &v_scn1 n1 ,&v_scn2  n2 from dual ;
        N1         N2
---------- ----------
  14430020   14430020

SCOTT@test01p> select current_scn from v$database;
CURRENT_SCN
-----------
   14430039

SCOTT@test01p> select &v_scn1 n1 ,&v_scn2  n2 from dual ;
        N1         N2
---------- ----------
  14430039   14430039

--//我开始的理解14430039保存在v_scn2,14430020保存在v_scn1.实际上情况根本不是这样!!

select current_scn from v$database
union all
select current_scn+1 current_scn from v$database;

CURRENT_SCN
-----------
   14430084
   14430086

SCOTT@test01p> select &v_scn1 n1 ,&v_scn2  n2 from dual ;
        N1         N2
---------- ----------
  14430086   14430086
   
--//还有一个特点,clear columns不会清除v_scn1,v_scn2。
SCOTT@test01p> clear columns
columns cleared
SCOTT@test01p> define v_scn1
DEFINE V_SCN1          =   14430086 (NUMBER)
SCOTT@test01p> define v_scn2
DEFINE V_SCN2          =   14430086 (NUMBER)

--//总之,不像我想象的那样使用。那位知道,给一个例子说明问题。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2937973/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7970344