从Sql Plus Promt中的解码查询中删除空格

时间:2016-06-09 10:40:15

标签: sql oracle

我编写了一个带解码功能的脚本来显示一些数据。但是,当显示数据时,我可以在解码查询的输出中看到最后的白色空格。

这是查询

while [ 1 -eq 1 ]; do
sqlplus -s $USER_PASS <<EOF
set trimspool on
set trimout on
set lines 420
set pagesize 1000
column column_name format a10
SELECT m.mbp_no_of_sell_orders OFFER_TOTAL,m.mbp_sell_qty
OFFER_SIZE,decode(mbp_buy_price,99999999999,'MP',mbp_buy_price) 
PRICE ,m.mbp_buy_qty BID_SIZE,m.mbp_no_of_buy_orders BID_TOTAL  , 
abs(mbp_no_of_sell_orders-mbp_no_of_buy_orders) QTY_GAP FROM  
mkt_by_price_full m where MBP_ESMM_SEM_EXCH_SECURITY_ID = rtrim('$ExchCode')
order by MBP_BUY_PRICE desc;
exit;
EOF

查询的输出有点像这样:

OFFER_TOTAL OFFER_SIZE          PRICE              BID_SIZE  BID_TOTAL   QTY_GAP
----------- ---------- ------------------------ ---------- ---------- ----------
          0        470 MP                              140          0          0
       5940          2 66000                             0        140       5800
       5938       1090 65000                             0        140       5798
       4848        900 63000                             0        140       4708
       3948        319 62000                             0        140       3808
       3629        680 60000                             0        140       3489
       2949        833 59000                             3        143       2806
       2116        989 58000                             5        148       1968
       1127        657 57000                           270        418        709
        470          0 56000                          1016       1434        964
        470          0 55000                          6678       8112       7642
        470          0 54000                           206       8318       7848
        470          0 52000                           126       8444       7974
        470          0 51000                            15       8459       7989
        470          0 50000                           589       9048       8578

15 rows selected.

1 个答案:

答案 0 :(得分:1)

使用column命令指定列的格式:

SQL> with data (mbp_buy_price) as
  2  ( select 12.34 from dual
  3    union all
  4    select 99999999999 from dual
  5    union all
  6    select 3000.00 from dual
  7  )
  8  select decode(mbp_buy_price,99999999999,'MP',mbp_buy_price) price
  9  from data;

PRICE
----------------------------------------
12.34
MP
3000

SQL> column price format a12
SQL> /

PRICE
------------
12.34
MP
3000