SQLPlus 常用命令

SQLPlus提供了很多常用的命令,以下是常用命令的使用方法及示例。

1-> SQLPlus的登陆与退出

sqlplus -H | -V -H 将显示sqlplus的版本及帮助信息,-V将显示其版本信息
登陆语法:
 
   
    
    
    is: (
    
    
     
     [/
     
     
      
      ][@
      
      
       
       ] | /)
              [AS SYSDBA | AS SYSOPER] | /NOLOG
              

       
       
        
        [/
        
        
          ]:登陆的用户名,密码 @ 
         
           :数据库的连接标识符,当未指定该参数,则连接到缺省的标识符 AS SYSDBA | AS SYSOPER:这两个参数描述使用数据库管理员的权限登陆 NOLOG:启动未连接到数据库的SQLPlus,在这之后可以使用conn登陆 下面是三种不同的登陆方式 [oracle@linux ~]$ sqlplus scott/tigger SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:06 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options [oracle@linux ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:45 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. SQL> conn scott Enter password: Connected. SQL> exit 
          /*使用exit或quit来退出*/ SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options [oracle@linux ~]$ sqlplus " 
          /as sysdba" SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:05:44 2010 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options 退出:使用使用exit或quit来退出,如例子中所演示的 
          
        
       
       
      
      
     
     
    
    
   
   
2->help  获得某一个命令的帮助信息
SQL> help desc

 DESCRIBE
 --------
 Lists the column definitions for a table, view, or synonym,
 or the specifications for a function or procedure.
 DESC[RIBE] {[schema.]object[@connect_identifier]
3->LIST [m][*] [n](简写L)显示缓冲区的所有内容。* 当前行,m 第m行,n 第n行,m n 同时出现,m到n行
SQL> l
  1  select * from emp
  2  where sal > 2000
  3* and deptno = 20
SQL> l 2 3
  2  where sal > 2000
  3* and deptno = 20
4->/ 执行缓冲区的内容
SQL> l
  1  select * from emp
  2  where sal > 2000
  3  and deptno = 20
  4* and ename = 'SCOTT'
SQL> /

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20  
5->n 设置当前行
SQL> 2
  2* where sal > 2000
SQL> 3
  3* and deptno = 20  
6->n text 用text内容替换第n行
SQL> l
  1  select * from emp
  2  where deptno = 20
  3* and sal > 2000
SQL> 2 where ename = 'SCOTT'
SQL> l
  1  select * from emp
  2  where ename = 'SCOTT'
  3* and sal > 2000
7->;  对于已输入完毕的SQL语句,输入;号表示该语句输入完毕。对于设置语句可以不使用分号,如上述的help desc
 

8->APPEND text(简写A text) 将text的内容追加到缓冲区尾部
SQL> l
  1* select * from emp
SQL> a where sal > 2000;
  1* select * from empwhere sal > 2000
9->CHANGE/old/new(简写C /old/new) 将当前行中的old替换为new
SQL> l
  1  select * from emp
  2  where sal > 2000
  3*    and deptno = 20
SQL> 3
  3*    and deptno = 20
SQL> c /20/10
  3*    and deptno = 10
SQL> l
  1  select * from emp
  2  where sal > 2000
  3*    and deptno = 10
10->CHANGE/text(C/text) 删除当前行中的text
SQL> l
  1  select * from emp
  2  where sal > 2000
  3*    and deptno = 10
SQL> 3
  3*    and deptno = 10
SQL> c /and deptno = 10
  3*
SQL> l
  1  select * from emp
  2  where sal > 2000
  3*
11->CLEAR BUFFER(CL BUFF)清除整个SQL缓冲区
SQL> cl buff
buffer cleared
SQL> l
SP2-0223: No lines in SQL buffer.
12->DEL 删除当前行
SQL> l
  1  select * from emp
  2* where sal > 2000
SQL> del 2
SQL> l
  1* select * from emp
13->show user 显示当前登陆的用户
SQL> show user  
USER is "SYS"
SQL> conn scott/tigger
Connected.
SQL> show user
USER is "SCOTT"
14->SAVE 保存当前缓冲区的内容到文件
SQL> l
  1  select *
  2  from emp
  3* where sal > 2000
SQL> save query.sql
Created file query.sql  
15->GET 把磁盘上的命令文件调入到当前缓冲区
SQL> cl buff
buffer cleared
SQL> get query.sql
  1  select *
  2  from emp
  3* where sal > 2000
16->START/@ filename 运行命令文件 
SQL> get query.sql
  1  select *
  2  from emp
  3* where sal > 2000
SQL> @query.sql
17->SET LINESIZE n 设置每行的字符数,默认80,如果一行的输出内容大于设置的一行可容纳的字符数,则折行显示。 
SQL> select * from scott.emp where ename = 'SCOTT'; /*以下是未设置的结果*/

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
---------- ---------- --------- ---------- --------- ---------- ----------
    DEPTNO
----------
      7788 SCOTT      ANALYST         7566 19-APR-87       3000
        20

SQL> set linesize 200
SQL> select * from scott.emp where ename = 'SCOTT';  /*以下是设置后的结果*/ 

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
18->dual 伪表的使用,注意Oracle与MSSQL的差异,下面的操作MSSQL无需伪表即可完成,几不需要from dual就可以完成一些特定的功能
SQL> select 3+2 from dual;

       3+2
----------
         5
19->spool    filename 将接下来屏幕上输入的所有内容输出到文件,包括输入的SQL语句
20->spool off 需要使用off后,才能将内容输出到文件
更多:Linux (RHEL 5.4)下安装Oracle 10g R2  使用Uniread实现SQLplus翻页功能
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值