[20131119]sqlplus顏色輸出.txt

lfree發表於2013-11-19
[20131119]sqlplus顏色輸出.txt

昨天別人問一個sqlplus色彩輸出的問題,實際上以前我自己寫過一個指令碼,檢查rman備份的情況:

內容如下:

column status format a16
column input_type format a11
column elapsed_seconds format 99999 head "ELAPSED|SECONDS"
column compression_ratio format 99.99999 head "COMPRESSION|RATIO"
column inputb format a12 head "INPUT BYTES| DISPLAY"
column outputb format a12 head "OUTPUT BYTES| DISPLAY"
column input format a12 head "INPUT BYTES|PER_SEC DISPLAY"
column output format a12 head "OUTPUT BYTES|PER_SEC DISPLAY"
column time format a10
column ok format a14
set linesize 200
SELECT start_time, end_time, elapsed_seconds,TRIM (time_taken_display) TIME, status, input_type,
       compression_ratio, TRIM (input_bytes_display) inputb,
       TRIM (output_bytes_display) outputb,
       TRIM (input_bytes_per_sec_display) input,
       TRIM (output_bytes_per_sec_display) output,
       DECODE (status,
               'COMPLETED', CHR (27) || '[1;32m' || 'V',
               CHR (27) || '[1;31m' || 'X'
              )||CHR (27) || '[0m' ok
  FROM v$rman_backup_job_details
 WHERE start_time > TRUNC (SYSDATE) - 12
 order by start_time desc ;
quit

輸出的例子:
                                        ELAPSED                                         COMPRESSION INPUT BYTES  OUTPUT BYTES INPUT BYTES  OUTPUT BYTES
START_TIME          END_TIME            SECONDS TIME       STATUS           INPUT_TYPE        RATIO  DISPLAY      DISPLAY     PER_SEC DISP PER_SEC DISP OK
------------------- ------------------- ------- ---------- ---------------- ----------- ----------- ------------ ------------ ------------ ------------ ----------
2013-11-19 00:20:18 2013-11-19 00:21:32      74 00:01:14   COMPLETED        ARCHIVELOG      1.45321 749.02M      515.42M      10.12M       6.97M        V
2013-11-18 00:20:23 2013-11-18 00:21:55      92 00:01:32   COMPLETED        ARCHIVELOG      1.52757 839.37M      549.48M      9.12M        5.97M        V
2013-11-17 00:20:09 2013-11-17 08:23:02   28973 08:02:53   FAILED           DB FULL         3.56265 1.39T        400.65G      50.45M       14.16M       X
2013-11-16 00:20:17 2013-11-16 00:21:45      88 00:01:28   COMPLETED        ARCHIVELOG      1.41245 1.01G        731.91M      11.75M       8.32M        V
2013-11-15 00:20:17 2013-11-15 01:01:11    2454 00:40:54   COMPLETED        ARCHIVELOG      1.30648 46.58G       35.65G       19.44M       14.88M       V
2013-11-14 00:20:33 2013-11-14 01:16:27    3354 00:55:54   COMPLETED        ARCHIVELOG      1.30929 60.71G       46.37G       18.54M       14.16M       V
2013-11-13 11:23:35 2013-11-13 11:24:37      62 00:01:02   COMPLETED        SPFILE          1.00000 48.13M       48.28M       794.84K      797.42K      V
2013-11-13 00:20:18 2013-11-13 00:26:53     395 00:06:35   COMPLETED        ARCHIVELOG      1.30114 6.37G        4.90G        16.52M       12.70M       V
2013-11-12 00:20:15 2013-11-12 00:21:26      71 00:01:11   COMPLETED        ARCHIVELOG      1.57829 603.80M      382.57M      8.50M        5.39M        V
2013-11-11 00:20:16 2013-11-11 00:21:18      62 00:01:02   COMPLETED        ARCHIVELOG      1.54423 393.68M      254.94M      6.35M        4.11M        V
2013-11-10 00:20:10 2013-11-10 06:55:54   23744 06:35:44   COMPLETED        DB FULL         3.25490 1.18T        372.46G      52.28M       16.06M       V
2013-11-09 00:20:18 2013-11-09 00:22:02     104 00:01:44   COMPLETED        ARCHIVELOG      1.39767 912.69M      653.01M      8.78M        6.28M        V
2013-11-08 00:20:16 2013-11-08 00:21:38      82 00:01:22   COMPLETED        ARCHIVELOG      1.44176 753.84M      522.86M      9.19M        6.38M        V
2013-11-07 00:20:16 2013-11-07 00:21:42      86 00:01:26   COMPLETED        ARCHIVELOG      1.41592 1020.24M     720.55M      11.86M       8.38M        V

14 rows selected.


--實際上這個指令碼僅僅在linux下使用,如果在windows依舊無法使用,當然解決方法很簡單,就是使用rlwrap呼叫sqlplus,這樣就可以了。
--rlwap的windows版本比較難找,我寫過一篇"如何提高命令列的工作效率增強版"的文章,連結如下,裡面有rlwrap的windows版本的下載。

http://www.itpub.net/forum.php?mod=viewthread&tid=1155109

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-776903/,如需轉載,請註明出處,否則將追究法律責任。

相關文章