sqlplus 之缓存中sql的显示、清除、执行

1、编辑、运行sql语句命令

注:这里所指的sql语句包括:sql语句,pl/sql块。

      sql语句执行完后,都会保存在一个叫做sql缓冲区的地方。并且sql缓冲区只保存一条最近执行的sql语句。

      sql*plus有自己的命令行编辑器, 允许在sql*plus中编辑保存在sql缓冲区中的sql语句。

 

 1) L[IST] 或者 L[IST] n 或只输入n 或者L[IST] m n 或者L[IST] * ----显示sql缓冲区中的内容

SQL> select * from student;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> l
  1* select * from student
SQL> list
  1* select * from student
SQL> select *
  2  from student;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> l 1
  1* select *
SQL> l 2
  2* from student
SQL> list 1
  1* select *
SQL> list 2
  2* from student
SQL> list 1 2
  1  select *
  2* from student
SQL> list *
  2* from student

  2) A[PPEND] text 或者 I[NPUT] text   --将text添加到当前行的结尾或者 在当前行后面追加一个新的行,内容为text

 

SQL> select *
  2  from student
  3  ;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> l 2
  2* from student
SQL> append  where code = 97001
  2* from student where code = 97001
SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80     

SQL> select *
  2  from student;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> l
  1  select *
  2* from student
SQL> i where code = 97001;
SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80  

 3) C[HANGE]/old/new/ 或者 C[HANGE]/text  -----将当前行中的old替换成new或者 从当前行删除text

SQL> select *
  2  from student;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> c /student/student t/
  2* from student t
SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> c t
SP2-0025: 无效的更改字符串
SQL> c/t
  2* from sudent t
SQL> c/ t
  2* from sudent
SQL> c /sudent/student/
  2* from student
SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55   

 4) CL[EAR] BUFF[ER] 或者 DEL n 或者 DEL 或者 DEL n LAST   -----清除缓冲区中的所有行 | 删除第n行 | 删除当前行 | 删除第n行到最后一行

SQL> clear buffer
buffer 已清除
SQL> l
SP2-0223: SQL 缓冲区中不存在行。
SQL> select *
  2  from
  3  student
  4  ;

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> del 4
SQL> l
  1  select *
  2  from
  3* student
SQL> del 3 last
SQL> l
  1  select *
  2* from
SQL> i student
SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55 

 5) R[UN] 或者 "/"  ----运行sql缓冲区中的内容

SQL> /

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55                                                                   

SQL> r
  1  select *
  2  from
  3* student

      CODE CLASS           SCORE                                                                   
---------- ---------- ----------                                                                   
     97001 数学               80                                                                   
     97002 计算机             59                                                                   
     97003 计算机             60                                                                   
     97004 数学               55   

 

 

你可能感兴趣的:(oracle)