IT开放社区

SQL*Plus编辑命令(二)

save  保存缓存文件中的SQL,不指定则保存在sqlplus登录时的路径;

start (或@)默认的文件名后缀为.sql;

SCOTT@itkaifang> SELECT empno,ename,sal FROM emp WHERE deptno=10;
     EMPNO ENAME             SAL
---------- ---------- ----------
      7782 CLARK            2450
      7839 KING             5000
      7934 MILLER           1300
SCOTT@itkaifang> L
  1* SELECT empno,ename,sal FROM emp WHERE deptno=10
SCOTT@PROD> SAVE s1
Created file s1.sql
SCOTT@itkaifang> ! ls
afiedt.buf  oradiag_oracle  s1.sql
SCOTT@itkaifang> start s1
     EMPNO ENAME             SAL
---------- ---------- ----------
      7782 CLARK            2450
      7839 KING             5000
      7934 MILLER           1300
SCOTT@itkaifang> @ s1
     EMPNO ENAME             SAL
---------- ---------- ----------
      7782 CLARK            2450
      7839 KING             5000
      7934 MILLER           1300
SCOTT@itkaifang>

get 在sqlplus中显示文件中的内容,默认后缀为.sql;

SCOTT@itkaifang> get s1
  1* SELECT empno,ename,sal FROM emp WHERE deptno=10
SCOTT@itkaifang>

input (可简写为i) text  执行若干行,分号结束;

SCOTT@itkaifang> L
  1* SELECT empno,ename,sal FROM emp WHERE deptno=10
SCOTT@itkaifang> i OR deptno=20;
SCOTT@itkaifang> RUN
  1  SELECT empno,ename,sal FROM emp WHERE deptno=10
  2* OR deptno=20
     EMPNO ENAME             SAL
---------- ---------- ----------
      7369 SMITH             800
      7566 JONES            2975
      7782 CLARK            2450
      7788 SCOTT            3000
      7839 KING             5000
      7876 ADAMS            1100
      7902 FORD             3000
      7934 MILLER           1300
8 rows selected.
SCOTT@itkaifang>

edit (可简写为ed)

edit 用编辑器打开缓冲区中的内容到afiedt.buf文件中,

edit 文件名   用编辑器打开或新建一个文件;

SCOTT@itkaifang> define_editor=vim
SCOTT@itkaifang> L
  1  SELECT empno,ename,sal FROM emp WHERE deptno=10
  2* OR deptno=20
SCOTT@itkaifang> ED
Wrote file afiedt.buf
SELECT empno,ename,sal FROM emp WHERE deptno=10
/
~
SCOTT@itkaifang> RUN
  1* SELECT empno,ename,sal FROM emp WHERE deptno=10
     EMPNO ENAME             SAL
---------- ---------- ----------
      7782 CLARK            2450
      7839 KING             5000
      7934 MILLER           1300
SCOTT@itkaifang>

spool (可简写为spo)【 文件名 |  OFF  |OUT 】

保存所有操作及结果到一个文件中,OFF关闭改文件,OUT关闭文件并发送到打印机;

SCOTT@itkaifang> SPOOL /home/oracle/spool1.sql
SCOTT@itkaifang> SELECT empno,ename FROM emp;
     EMPNO ENAME
---------- ----------
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
      7900 JAMES
      7902 FORD
      7934 MILLER
14 rows selected.
SCOTT@itkaifang> SPOOL OFF
SCOTT@itkaifang> ! cat /home/oracle/spool1.sql
  SCOTT@PROD> SELECT empno,ename FROM emp;
     EMPNO ENAME                                                                                                            ---------- ----------                                                                                                             7369 SMITH                                                                                                                  7499 ALLEN                                                                                                                  7521 WARD                                                                                                                   7566 JONES                                                                                                                  7654 MARTIN                                                                                                                 7698 BLAKE                                                                                                                  7782 CLARK                                                                                                                  7788 SCOTT                                                                                                                  7839 KING                                                                                                                   7844 TURNER                                                                                
      7876 ADAMS                                                                                 
      7900 JAMES                                                                                 
      7902 FORD                                                                                  
      7934 MILLER                                                                                                         
   14 rows selected.
  SCOTT@itkaifang> SPOOL OFF
SCOTT@itkaifang>

 情况sqlplus缓冲区   clear buffer

SCOTT@itkaifang> L
  1* SELECT empno,ename FROM emp
SCOTT@itkaifang> CLEAR BUFFER
buffer cleared
SCOTT@itkaifang> L
SP2-0223: No lines in SQL buffer.
SCOTT@itkaifang>


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

网站分类
最新文章
    随机文章
      站点信息
      • 文章总数:113
      • 页面总数:2
      • 分类总数:3
      • 标签总数:0
      • 评论总数:0
      • 浏览总数:36173
      左邻右舍

      BlogPowerBy Z-BlogPHP 1.5 Zero ;Theme By 爱墙纸

      IT开放社区:京ICP备13044647号.初创于Oracle DBA实战班.邮箱:admin@itkaifang.com

      分享:

      支付宝

      微信