sqlplus中常用的格式化命令

sqlplus中常用的格式化命令
column
sql*plus默认使用表中的列为查询输出的列名,或者表达式为查询输出的列名。
为了提高可读性,可以使用column改变输出显示的列的列名.
SQL> column amsal heading 'manager''s salary'
SQL> select amid,amsal
  2  from acctmanager;
AMID     manager's salary
-------- ----------------
0001                 7000
可以使用|让要显示的列名分成多行。
SQL> column amsal heading 'manager''s|salary'
SQL> select amid,amsal
  2  from acctmanager;
          manager's
AMID         salary
-------- ----------
0001           7000
SQL> column first_name format a12
SQL> column lastt_name format a12
SQL> select first_name,last_na
  2  from employees;
FIRST_NAME   LAST_NAME
------------ -----------------
Steven       King
Neena        Kochhar
Lex          De Haan
Alexander    Hunold
Bruce        Ernst
David        Austin
Valli        Pataballa
Diana        Lorentz
设置first_name,last_name栏输出的宽度。
SQL> column amsal format $99,990 //对数值的输出进行格式化
SQL> /
AMID        AMSAL
-------- --------
0001       $7,000
cloumn设置的列的标题会一直有效,直到更改该列的标题,或者退出sql*plus
与使用 column column_name clear命令清除设置。
也可以使用clear columns 清除所有列的标题设置。
SQL> clear columns
columns 已清除
numwidth:
输出类型域的长度,默认值是10
SQL> show numwidth
numwidth 10
SQL> set numwidth 5
SQL> select 4444 from dual;
 4444
-----
 4444
SQL> select 44445 from dual;
44445
-----
44445
SQL> select 444456 from dual; //numwidth长度不够将会显示的结果
444456
------
 #####   
SQL> select 55555578 from dual;
55555578
--------
 5.6E+07
当numwidth长度不够但是数值达到千万级的时候会使用科学计数法。
注意:当用column设置数值的显示以后,numwith的设置对该列就无效了。
SQL> show numwidth
numwidth 5
SQL> column amsal format $999
SQL> /
AMID     AMSAL
-------- -----
0001     #####
linesize:
默认值是80,设置一行显示的字符数。
SQL> show linesize
linesize 80
SQL> set linesize 400
SQL> select * from employees;
这样employees表中的所有的列都可以显示在同一行中。
pagesize:
一页显示多少行。默认值是14.该值设置为0将不会分页。
SQL> show pagesize
pagesize 14
SQL> set pagesize 0
underscore:
默认是'-',设置标题下面的下划线的样式。
SQL> show underline
underline "-" (hex 2d)
SQL> set underline *
SQL> select first_name,last_name,salary
  2  from employees;
FIRST_NAME                               LAST_NAME                                          SALARY
**************************************** ************************************************** ******
Steven                                   King                                                30000
Neena                                    Kochhar                                             17000
Lex                                      De Haan                                             17000
Alexander                                Hunold                                               9000
Bruce                                    Ernst                                                6000
David                                    Austin                                               4800
Valli                                    Pataballa                                            4800
Diana                                    Lorentz                                              4200
Nancy                                    Greenberg                                           12000
Daniel                                   Faviet                                               9000
John                                     Chen                                                 8200
SQL> set underline '-'   //改回默认值。
break:
设置格式改变的样式,以及出现的条件。
break on column_name
消除order by 子句中column_name中的重复值。
SQL> select department_id,employee_id,salary
  2  from employees
  3  where salary>15000
  4  order by department_id;
DEPARTMENT_ID EMPLOYEE_ID     SALARY
------------- ----------- ----------
           90         100      30000
           90         102      17000
           90         101      17000
SQL> break on department_id
SQL> /
DEPARTMENT_ID EMPLOYEE_ID     SALARY
------------- ----------- ----------  //重复值(90)消除了.
           90         100      30000
                      102      17000
                      101      17000
break on column_name skip n 
当column_name中的值改变的时候就插入n行空白行.并消除column_name
中的重复值。
SQL> break on department_id skip 1
SQL> select department_id,employee_id,salary
  2  from employees
  3  where salary>12000
  4  order by department_id;
DEPARTMENT_ID EMPLOYEE_ID     SALARY 
------------- ----------- ----------
           20         201      13000

           80         146      13500   
                      145      14000  

           90         101      17000
                      100      30000
                      102      17000                       
使用break命令列出当前的break定义,每一个新定义的break都会覆盖以前定义的
break。
SQL> break
break on department_id skip 1 nodup
SQL> clear break
breaks 已清除
清除当前的break定义

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

转载于:http://blog.itpub.net/26110315/viewspace-716204/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值