SQLPlus 常用命令

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

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/tiggerSQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:06 2010Copyright (c) 1982, 2005, Oracle.  All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options[oracle@linux ~]$ sqlplus /nologSQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 30 14:04:45 2010Copyright (c) 1982, 2005, Oracle.  All rights reserved.SQL> conn scott    Enter password: Connected.SQL> exit/*使用exit或quit来退出*/SQL> exitDisconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith 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 2010Copyright (c) 1982, 2005, Oracle.  All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith 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 procedureDESC[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 = 20SQL> 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 > 2000SQL> 3  3* and deptno = 20  
6->n text 用text内容替换第n行
 
   
SQL> l  1  select * from emp  2  where deptno = 20  3* and sal > 2000SQL> 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 empSQL> 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 = 20SQL> 3  3*    and deptno = 20SQL> c /20/10  3*    and deptno = 10SQL> 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 = 10SQL> 3  3*    and deptno = 10SQL> c /and deptno = 10  3*SQL> l  1  select * from emp  2  where sal > 2000  3*
11->CLEAR BUFFER(CL BUFF)清除整个SQL缓冲区
 
   
SQL> cl buffbuffer clearedSQL> lSP2-0223: No lines in SQL buffer.
 
12->DEL 删除当前行
 
   
SQL> l  1  select * from emp  2* where sal > 2000SQL> del 2SQL> l  1* select * from emp
 
13->show user 显示当前登陆的用户
 
   
SQL> show user  USER is "SYS"SQL> conn scott/tiggerConnected.SQL> show userUSER is "SCOTT"
 
14->SAVE 保存当前缓冲区的内容到文件
 
   
SQL> l  1  select *  2  from emp  3* where sal > 2000SQL> save query.sqlCreated file query.sql  
 
15->GET 把磁盘上的命令文件调入到当前缓冲区
 
SQL> cl buffbuffer clearedSQL> 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 > 2000SQL> @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        20SQL> set linesize 200SQL> 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翻页功能
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/fsfsdfsdw/article/details/83990267
今日推荐