sqlplus常用操作命令2

常用编辑命令:
A[ppend] text 将text附加到当前行之后
C[hange] /old /new 将当前行中的old替换为new
CLear] buff[er] 清除缓冲区中的所有行
DEL 删除当前行
DEL x 删除第x行
L[ist] 列出缓冲区中所有行
L[ist] x 列出缓冲区中第x行
R[un]或/ 运行缓冲区中保存的语句
x 将第x行作为当前行

SQL> select product_id,name

  2  from

  3  products;



PRODUCT_ID NAME

---------- ------------------------------

         1 Modern Science

         2 Chemistry

         3 Supernova

         4 Tank War

         5 Z Files

         6 2412: The Return

         7 Space Force 9

         8 From Another Planet

         9 Classical Music

        10 Pop 3

        11 Creative Yell

        12 My Front Line



12 rows selected.



SQL> 1    --输入1显示第1行

  1* select product_id,name

SQL> append ,price  --在第1行增加列,price

  1* select product_id,name,price

SQL> list  --列出缓冲区中所有行

  1  select product_id,name,price

  2  from

  3* products

SQL> 1  --指定要修改的行             

  1* select product_id,name,price

SQL> change /price / description  --将列price替换为description

SP2-0023: String not found.

SQL> change /price /description

  1* select product_id,name,description

SQL> list

  1  select product_id,name,description

  2  from

  3* products

SQL> /    --执行缓冲区中保存的语句



PRODUCT_ID NAME                           DESCRIPTION

---------- ------------------------------ --------------------------------------------------

         1 Modern Science                 A description of modern science

         2 Chemistry                      Introduction to Chemistry

         3 Supernova                      A star explodes

         4 Tank War                       Action movie about a future war

         5 Z Files                        Series on mysterious activities

         6 2412: The Return               Aliens return

         7 Space Force 9                  Adventures of heroes

         8 From Another Planet            Alien from another planet lands on Earth

         9 Classical Music                The best classical music

        10 Pop 3                          The best popular music

        11 Creative Yell                  Debut album

        12 My Front Line                  Their greatest hits



12 rows selected.





SQL> run   --同上,执行缓冲区中保存的语句

  1  select product_id,name,description

  2  from

  3* products



PRODUCT_ID NAME                           DESCRIPTION

---------- ------------------------------ --------------------------------------------------

         1 Modern Science                 A description of modern science

         2 Chemistry                      Introduction to Chemistry

         3 Supernova                      A star explodes

         4 Tank War                       Action movie about a future war

         5 Z Files                        Series on mysterious activities

         6 2412: The Return               Aliens return

         7 Space Force 9                  Adventures of heroes

         8 From Another Planet            Alien from another planet lands on Earth

         9 Classical Music                The best classical music

        10 Pop 3                          The best popular music

        11 Creative Yell                  Debut album

        12 My Front Line                  Their greatest hits



12 rows selected.



SQL> 

二、保存、检索并运行文件

SQL> list  --列出缓冲区中的内容

  1  select product_id,name,description

  2  from

  3* products



SQL> save /home/oracle/test_save.sql  --保存缓冲区中的内容到指定路径指定的文件中

Created file /home/oracle/test_save.sql

SQL> get test_save.sql

  1  select product_id,name,description

  2  from

  3* products

SQL> start test_save.sql     --将保存的文件内容读入缓冲区并执行



PRODUCT_ID NAME                           DESCRIPTION

---------- ------------------------------ --------------------------------------------------

         1 Modern Science                 A description of modern science

         2 Chemistry                      Introduction to Chemistry

         3 Supernova                      A star explodes

         4 Tank War                       Action movie about a future war

         5 Z Files                        Series on mysterious activities

         6 2412: The Return               Aliens return

         7 Space Force 9                  Adventures of heroes

         8 From Another Planet            Alien from another planet lands on Earth

         9 Classical Music                The best classical music

        10 Pop 3                          The best popular music

        11 Creative Yell                  Debut album

        12 My Front Line                  Their greatest hits



12 rows selected.



SQL> @test_save.sql    --同start



PRODUCT_ID NAME                           DESCRIPTION

---------- ------------------------------ --------------------------------------------------

         1 Modern Science                 A description of modern science

         2 Chemistry                      Introduction to Chemistry

         3 Supernova                      A star explodes

         4 Tank War                       Action movie about a future war

         5 Z Files                        Series on mysterious activities

         6 2412: The Return               Aliens return

         7 Space Force 9                  Adventures of heroes

         8 From Another Planet            Alien from another planet lands on Earth

         9 Classical Music                The best classical music

        10 Pop 3                          The best popular music

        11 Creative Yell                  Debut album

        12 My Front Line                  Their greatest hits



12 rows selected.

 SQL> spool /home/oracle/select.txt   --将以下输出的结果保存到指定文件中

SQL> /



PRODUCT_ID NAME                           DESCRIPTION

---------- ------------------------------ --------------------------------------------------

         1 Modern Science                 A description of modern science

         2 Chemistry                      Introduction to Chemistry

         3 Supernova                      A star explodes

         4 Tank War                       Action movie about a future war

         5 Z Files                        Series on mysterious activities

         6 2412: The Return               Aliens return

         7 Space Force 9                  Adventures of heroes

         8 From Another Planet            Alien from another planet lands on Earth

         9 Classical Music                The best classical music

        10 Pop 3                          The best popular music

        11 Creative Yell                  Debut album

        12 My Front Line                  Their greatest hits



12 rows selected.



SQL> spool off     --停止输出结果,并关闭该文件,如果不spoo off,则后面输入的所有结果都会写入到上面的select.txt文件

SQL> 

[root@rhel201 oracle]# ls

afiedt.buf  oradiag_oracle  select.txt  testbak  test_save.sql  test.sql

[root@rhel201 oracle]# cat test_save.sql 

select product_id,name,description

from

products

/

[root@rhel201 oracle]# cat select.txt 

SQL> /



PRODUCT_ID NAME                           DESCRIPTION                                                                                                                                                   

---------- ------------------------------ --------------------------------------------------                                                                                                            

         1 Modern Science                 A description of modern science                                                                                                                               

         2 Chemistry                      Introduction to Chemistry                                                                                                                                     

         3 Supernova                      A star explodes                                                                                                                                               

         4 Tank War                       Action movie about a future war                                                                                                                               

         5 Z Files                        Series on mysterious activities                                                                                                                               

         6 2412: The Return               Aliens return                                                                                                                                                 

         7 Space Force 9                  Adventures of heroes                                                                                                                                          

         8 From Another Planet            Alien from another planet lands on Earth                                                                                                                      

         9 Classical Music                The best classical music                                                                                                                                      

        10 Pop 3                          The best popular music                                                                                                                                        

        11 Creative Yell                  Debut album                                                                                                                                                   

        12 My Front Line                  Their greatest hits                                                                                                                                           



12 rows selected.



SQL> spool off

[root@rhel201 oracle]# 

三、格式化列

SQL> /



PRODUCT_ID PRODUCT_TYPE_ID NAME                           DESCRIPTION                                             PRICE

---------- --------------- ------------------------------ -------------------------------------------------- ----------

         1               1 Modern Science                 A description of modern science                         19.95

         2               1 Chemistry                      Introduction to Chemistry                                  30

         3               2 Supernova                      A star explodes                                         25.99

         4               2 Tank War                       Action movie about a future war                         13.95

         5               2 Z Files                        Series on mysterious activities                         49.99

         6               2 2412: The Return               Aliens return                                           14.95

         7               3 Space Force 9                  Adventures of heroes                                    13.49

         8               3 From Another Planet            Alien from another planet lands on Earth                12.99

         9               4 Classical Music                The best classical music                                10.99

        10               4 Pop 3                          The best popular music                                  15.99

        11               4 Creative Yell                  Debut album                                             14.99

        12                 My Front Line                  Their greatest hits                                     13.49



12 rows selected.





SQL> col product_id format 99  --两位数字

SQL> col name heading product_name format a13 word_wrapped   --将列name显示为product_name,13个字符串,自动换行

SQL> col descripton format a20 word_wrapped   --20个字符串,自动换行

SQL> col proce format $99.99   --以该格式显示price列内容

SQL> /



PRODUCT_ID PRODUCT_TYPE_ID product_name  DESCRIPTION                                             PRICE

---------- --------------- ------------- -------------------------------------------------- ----------

         1               1 Modern        A description of modern science                         19.95

                           Science



         2               1 Chemistry     Introduction to Chemistry                                  30

         3               2 Supernova     A star explodes                                         25.99

         4               2 Tank War      Action movie about a future war                         13.95

         5               2 Z Files       Series on mysterious activities                         49.99

         6               2 2412: The     Aliens return                                           14.95

                           Return



         7               3 Space Force 9 Adventures of heroes                                    13.49

         8               3 From Another  Alien from another planet lands on Earth                12.99

                           Planet



         9               4 Classical     The best classical music                                10.99

                           Music



        10               4 Pop 3         The best popular music                                  15.99

        11               4 Creative Yell Debut album                                             14.99

        12                 My Front Line Their greatest hits                                     13.49



12 rows selected.



SQL> 



-----------

SQL> show linesize 

linesize 200

SQL> show pagesize

pagesize 50

SQL> set linesize 150

SQL> set pagesize 80

SQL> 



SQL> set verify on --启用old行和new行的输出

SQL> /  

Enter value for test: 1

old   1: select * from products where product_type_id=&test

new   1: select * from products where product_type_id=1



PRODUCT_ID PRODUCT_TYPE_ID product_name  DESCRIPTION                                             PRICE

---------- --------------- ------------- -------------------------------------------------- ----------

         1               1 Modern        A description of modern science                         19.95

                           Science



         2               1 Chemistry     Introduction to Chemistry                                  30



SQL> set verify off   --禁用old和new

SQL> /

Enter value for test: 2



PRODUCT_ID PRODUCT_TYPE_ID product_name  DESCRIPTION                                             PRICE

---------- --------------- ------------- -------------------------------------------------- ----------

         3               2 Supernova     A star explodes                                         25.99

         4               2 Tank War      Action movie about a future war                         13.95

         5               2 Z Files       Series on mysterious activities                         49.99

         6               2 2412: The     Aliens return                                           14.95

                           Return





SQL> 

说明:
save filename 保存内容,保存时加上路径
save filename replace/apend 保存并替换/追加
get filename 打开filename文件
start filename 打开filename文件并执行
@filename 同上
edit filename 使用记事本或vi打开filename文件进行编辑,如果不指定filename,则打开当前缓冲区中的内容
define _edit='editor'或define _edit='vi'定义默认编辑器
spool filename 将输出结果保存到指定文件
spool off 结束结果输出

 

你可能感兴趣的:(sqlplus)