首页 > 代码库 > [20170617]vim中调用sqlplus.txt
[20170617]vim中调用sqlplus.txt
[20170617]vim中调用sqlplus.txt
--//以前写过一篇emacs下调用sqlplus的文章,一直想学emacs,受限制自己掌握vim,对学习它没有兴趣,原链接如下:
--//http://blog.itpub.net/267265/viewspace-1309032/
--//实际上vim也有插件连接数据库,我觉得不好用,一直没这样用.
--//今天在整理vim相关设置时,发现我自己以前也定义一些方法,自己也拿出来分享:
noremap <Leader>q1 Yp!!sqlplus -s scott/btbtms@test01p<CR>
noremap <Leader>q2 Yp!!sqlplus -s sys/btbtms@test01p as sysdba<CR>
vnoremap ;q1 "ay<ESC>gv!sqlplus -s scott/btbtms@test01p<CR>
vnoremap ;q2 "by<ESC>gv!sqlplus -s sys/btbtms@test01p 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