ITPub博客

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

[20231103]sqlplus column new_value old_value.txt

原创 Oracle 作者:lfree 时间:2023-11-05 19:24:22 0 删除 编辑

[20231103]sqlplus column new_value old_value.txt

--//链接: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都可以使用。
--//我看了半天没看明白。似乎两者在脚本中是一样的。
--//上面我一直不理解怎么意思。实际上OLD_VALUE 和. NEW_VALUE仅仅在TTITLE和BTITLE有用。

--//并不像我以前理解的如下:
column xxxx new_value x2 old_value x1
--//new_value 保存新值在X2中。保存原来的旧值在X1中,实际上并不是这个意思,我理解错误。

--//自己做一个例子:
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

SCOTT@test01p> set pagesize 10
SCOTT@test01p> column dname new_value v_name1 old_value v_name2
SCOTT@test01p> ttitle left 'First department: ' v_name1
SCOTT@test01p> btitle left 'Last department : ' v_name2
SCOTT@test01p> select * from dept ;

First department: ACCOUNTING
    DEPTNO DNAME                LOC
---------- -------------------- -------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON
Last department : OPERATIONS

SCOTT@test01p> define v_name1
DEFINE V_NAME1         = "OPERATIONS" (CHAR)
SCOTT@test01p> define v_name2
DEFINE V_NAME2         = "OPERATIONS" (CHAR)
--//最后都是"OPERATIONS".
--//语法都很奇怪,没有前面引用的&.标题头使用new_value,标题尾使用old_value.
--//如果这样写错误:
SCOTT@test01p> column dname new_value v_name2 old_value v_name1
SCOTT@test01p> select * from dept ;

First department: OPERATIONS
    DEPTNO DNAME                LOC
---------- -------------------- -------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON

Last department : OPERATIONS

--//没有怎么用处.使用完最好清除设置.自己打入select * from emp;就明白为什么.

SCOTT@test01p> set pagesize 20
SCOTT@test01p> column dname new_value v_name1 old_value v_name2
SCOTT@test01p> select * from dept ;
....
SCOTT@test01p> select * from emp ;
First department: OPERATIONS
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1600        300         30
      7521 WARD       SALESMAN        7698 1981-02-22 00:00:00       1250        500         30
      7566 JONES      MANAGER         7839 1981-04-02 00:00:00       2975                    20
      7654 MARTIN     SALESMAN        7698 1981-09-28 00:00:00       1250       1400         30
      7698 BLAKE      MANAGER         7839 1981-05-01 00:00:00       2850                    30
      7782 CLARK      MANAGER         7839 1981-06-09 00:00:00       2450                    10
      7788 SCOTT      ANALYST         7566 1987-04-19 00:00:00       3000                    20
      7839 KING       PRESIDENT            1981-11-17 00:00:00       5000                    10
      7844 TURNER     SALESMAN        7698 1981-09-08 00:00:00       1500          0         30
      7876 ADAMS      CLERK           7788 1987-05-23 00:00:00       1100                    20
      7900 JAMES      CLERK           7698 1981-12-03 00:00:00        950                    30
      7902 FORD       ANALYST         7566 1981-12-03 00:00:00       3000                    20
      7934 MILLER     CLERK           7782 1982-01-23 00:00:00       1300                    10
Last department : OPERATIONS
14 rows selected.

SCOTT@test01p> ttitle off
SCOTT@test01p> btitle off
SCOTT@test01p> select * from dept;

    DEPTNO DNAME                LOC
---------- -------------------- -------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO
        40 OPERATIONS           BOSTON


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

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

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7970380