[20170617]vim中調用sqlplus.txt

來源:互聯網
上載者:User

標籤:使用   設定   執行   語句   配置   let   自己   copy   寄存器   

[20170617]vim中調用sqlplus.txt

--//以前寫過一篇emacs下調用sqlplus的文章,一直想學emacs,受限制自己掌握vim,對學習它沒有興趣,原連結如下:
--//http://blog.itpub.net/267265/viewspace-1309032/

--//實際上vim也有外掛程式串連資料庫,我覺得不好用,一直沒這樣用.

--//今天在整理vim相關設定時,發現我自己以前也定義一些方法,自己也拿出來分享:

noremap  <Leader>q1 Yp!!sqlplus -s scott/[email protected]<CR>
noremap  <Leader>q2 Yp!!sqlplus -s sys/[email protected] as sysdba<CR>
vnoremap  ;q1       "ay<ESC>gv!sqlplus -s scott/[email protected]<CR>
vnoremap  ;q2       "by<ESC>gv!sqlplus -s sys/[email protected] as sysdba<CR>

--//將以上資訊放在vim設定檔中,注意打入命令一定要正確,後面要有分號.當然錯誤不執行就是了.
--//根據自己需要修改資料庫連接串以及使用者,口令資訊.當然這樣存在安全問題.^_^.

select * from dept;
--//移動到哪一行,打入\q1

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

@ checkpoint
--//打入q2

REDO:


                                                       檢查點隊列
  檢查點隊列                                           on disk rba                                        檢查點隊列
    髒塊數量                                           時間戳記              目前時間                       on disk rba scn    檢查點心跳
       CPDRT low_rba              on_disk_rba          CPODT               SYSDATE              DIFF_DATE CPODS                   CPHBT  CURRENT_SCN     DIFF_SCN         INDX
------------ -------------------- -------------------- ------------------- ------------------- ---------- ---------------- ------------ ------------ ------------ ------------
          32 1470.13787.0         1470.13971.0         2017-06-17 22:08:11 2017-06-17 22:08:28      17.00 25428734            946961434     25428740            6            0


REDO ( Hexadecimal ):

                                                       檢查點隊列
  檢查點隊列                                           on disk rba                                        檢查點隊列
    髒塊數量                                           時間戳記              目前時間                       on disk rba scn    檢查點心跳
       CPDRT low_rba16            on_disk_rba16        CPODT               SYSDATE              DIFF_DATE CPODS                   CPHBT  CURRENT_SCN     DIFF_SCN         INDX
------------ -------------------- -------------------- ------------------- ------------------- ---------- ---------------- ------------ ------------ ------------ ------------
          32 0x5be.35db.0         0x5be.3693.0         2017-06-17 22:08:11 2017-06-17 22:08:28      17.00 25428734            946961434     25428741            7            0


FULL CHECKPOINT:

rtckp_rba            RTCKP_SCN         CURRENT_SCN     DIFF_SCN RTCKP_TIM           SYSDATE              DIFF_DATE
-------------------- ---------------- ------------ ------------ ------------------- ------------------- ----------
1470.2.16            25426654             25428742         2088 2017-06-17 21:39:53 2017-06-17 22:08:28    1715.00


v$instance_recovery:

     INST_ID ACTUAL_REDO_BLKS TARGET_REDO_BLKS     90%_blks TIMEOUT_BLKS  TARGET_MTTR ESTIMATED_MTTR
------------ ---------------- ---------------- ------------ ------------ ------------ --------------
           1              183            30962       165888        30962            0             63


--//這種方式的缺點就是必須將sql語句寫一行內.
--//也可以這樣操作,按v或者V,選中文本,進入v模式,然後打入;q1.
--//提醒一下,如果使用shift+方向鍵選擇的進入的是"選擇模式",按ctrl+g就可以切換為"可視模式"

select
*
from
dept;

--//這樣顯示,缺點就是打入的sql語句消失了.你可以先copy 2份再執行.

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

--//另外我還把內容放在寄存器a,b,可以使用"ap ,"bp取出.

--//提醒注意一點執行的語句不要是dml語句,比如insert,update,delete語句,還有truncate語句.因為預設就是退出就是commit.存在一定的風險.
--//執行select語句一般問題不大.作為測試學習也應該避免dml語句,不然把這種習慣帶到生產庫出問題就麻煩了.
--//補充1點,還可以適當設定大一點linesize,這樣避免出現折行想象.當然還有致命的缺點,每次執行都要開啟與關閉資料庫的串連.而且串連串是寫死的.

--//附上checkpoint.sql指令碼
$ cat checkpoint.sql
column low_rba format a20
column low_rba16 format a20
column on_disk_rba format a20
column on_disk_rba16 format a20
column rtckp_rba format a20
column diff_date format 999999.99
column CPOSD_ono_disk_rba_scn format 99999999999999999999999999999999
column cpdrt heading "檢查點隊列|髒塊數量|CPDRT"
column cpodt_on_disk_rba heading "檢查點隊列|on disk rba|時間戳記|CPODT"
column cpods heading "檢查點隊列|on disk rba scn|CPODS"
column cphbt heading "檢查點心跳|CPHBT"
column current_sysdate heading "目前時間|SYSDATE"
set num 12
PROMPT
PROMPT REDO:
PROMPT
SELECT cpdrt ,
       cplrba_seq || ‘.‘ || cplrba_bno || ‘.‘ || cplrba_bof "low_rba",
       cpodr_seq || ‘.‘ || cpodr_bno || ‘.‘ || cpodr_bof "on_disk_rba",
       TO_DATE (CPODT, ‘MM-DD-YYYY HH24:MI:SS‘) cpodt_on_disk_rba,
       SYSDATE current_sysdate,
       ROUND ( (SYSDATE - TO_DATE (CPODT, ‘MM-DD-YYYY HH24:MI:SS‘)) * 86400,
              2)
          diff_date,
       CPODS ,
           CPHBT,
       current_scn,
       current_scn - cpods diff_scn,
       indx
  FROM x$kcccp, v$database
 WHERE CPLRBA_SEQ <> 0;

PROMPT
PROMPT REDO ( Hexadecimal ):
PROMPT

SELECT cpdrt ,
       ‘0x‘||to_char(cplrba_seq,‘FMxxxxxxxx‘) || ‘.‘ || to_char(cplrba_bno,‘FMxxxxxxxx‘)|| ‘.‘ || to_char(cplrba_bof,‘FMxxxx‘) "low_rba16",
       ‘0x‘||to_char(cpodr_seq,‘FMxxxxxxxx‘) || ‘.‘ || to_char(cpodr_bno,‘FMxxxxxxxx‘) || ‘.‘ || to_char(cpodr_bof,‘FMxxxx‘) "on_disk_rba16",
       TO_DATE (CPODT, ‘MM-DD-YYYY HH24:MI:SS‘) cpodt_on_disk_rba,
       SYSDATE current_sysdate,
       ROUND ( (SYSDATE - TO_DATE (CPODT, ‘MM-DD-YYYY HH24:MI:SS‘)) * 86400,
              2)
          diff_date,
       CPODS ,
           CPHBT,
       current_scn,
       current_scn - cpods diff_scn,
       indx
  FROM x$kcccp, v$database
 WHERE CPLRBA_SEQ <> 0;

PROMPT
PROMPT FULL CHECKPOINT:
PROMPT
SELECT rtckp_rba_seq || ‘.‘ || rtckp_rba_bno || ‘.‘ || rtckp_rba_bof
          "rtckp_rba",
       rtckp_scn,
       current_scn,
       current_scn - rtckp_scn diff_scn,
       TO_DATE (rtckp_tim, ‘MM-DD-YYYY HH24:MI:SS‘) rtckp_tim,
       SYSDATE,
       ROUND (
          (SYSDATE - TO_DATE (rtckp_tim, ‘MM-DD-YYYY HH24:MI:SS‘)) * 86400,
          2) diff_date
  FROM x$kccrt, v$database;


PROMPT
PROMPT v$instance_recovery:
PROMPT
SELECT inst_id,
       actual_redo_blks,
       target_redo_blks,
       LOG_FILE_SIZE_REDO_BLKS AS "90%_blks",
       LOG_CHKPT_TIMEOUT_REDO_BLKS AS timeout_blks,
       target_mttr,
       estimated_mttr
  FROM gv$instance_recovery;

[20170617]vim中調用sqlplus.txt

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.