SQL> --查询一下当前登录的用户名
SQL> show user;
USER 为 "SCOTT"
SQL> --查询当前用户下有哪些表
SQL> select * from tab;

TNAME                                                        TABTYPE           
------------------------------------------------------------ --------------    
 CLUSTERID                                                                     
----------                                                                     
DEPT                                                         TABLE             
                                                                               
                                                                               
EMP                                                          TABLE             
                                                                               
                                                                               
BONUS                                                        TABLE

TNAME                                                        TABTYPE           
------------------------------------------------------------ --------------    
 CLUSTERID                                                                     
----------                                                                     
SALGRADE                                                     TABLE

SQL> --如果出来的结果不好看 你可以自己去设置和调整
SQL> --查询当前一行显示多少个字符
SQL> show linesize;
linesize 80
SQL> set linesize 120;
SQL> show linesize;
linesize 120
SQL> select * from tab;

TNAME                                                        TABTYPE         CLUSTERID                                 
------------------------------------------------------------ -------------- ----------                                 
DEPT                                                         TABLE                                                     
EMP                                                          TABLE                                                     
BONUS                                                        TABLE                                                     
SALGRADE                                                     TABLE

SQL> --设置某一个字段的宽度
SQL> col tname for a8;
SQL> select * from tab;

TNAME    TABTYPE         CLUSTERID                                                                                     
-------- -------------- ----------                                                                                     
DEPT     TABLE                                                                                                         
EMP      TABLE                                                                                                         
BONUS    TABLE                                                                                                         
SALGRADE TABLE

SQL> --dept 部门表emp 员工表
SQL> -- 查询所有的员工信息
SQL> select * from emp;

EMPNO ENAME                JOB                       MGR HIREDATE              SAL       COMM     DEPTNO          
---------- -------------------- ------------------ ---------- -------------- ---------- ---------- ----------          
      7369 SMITH                CLERK                    7902 17-12月-80            800                    20          
      7499 ALLEN                SALESMAN                 7698 20-2月 -81           1600        300         30          
      7521 WARD                 SALESMAN                 7698 22-2月 -81           1250        500         30          
      7566 JONES                MANAGER                  7839 02-4月 -81           2975                    20          
      7654 MARTIN               SALESMAN                 7698 28-9月 -81           1250       1400         30          
      7698 BLAKE                MANAGER                  7839 01-5月 -81           2850                    30          
      7782 CLARK                MANAGER                  7839 09-6月 -81           2450                    10          
      7788 SCOTT                ANALYST                  7566 19-4月 -87           3000                    20          
      7839 KING                 PRESIDENT                     17-11月-81           5000                    10          
      7844 TURNER               SALESMAN                 7698 08-9月 -81           1500          0         30          
      7876 ADAMS                CLERK                    7788 23-5月 -87           1100                    20

EMPNO ENAME                JOB                       MGR HIREDATE              SAL       COMM     DEPTNO          
---------- -------------------- ------------------ ---------- -------------- ---------- ---------- ----------          
      7900 JAMES                CLERK                    7698 03-12月-81            950                    30          
      7902 FORD                 ANALYST                  7566 03-12月-81           3000                    20          
      7934 MILLER               CLERK                    7782 23-1月 -82           1300                    10

已选择14行。

SQL> --查询所有的部门信息
SQL> select * from dept;

DEPTNO DNAME                        LOC                                                                            
---------- ---------------------------- --------------------------                                                     
        10 ACCOUNTING                   NEW YORK                                                                       
        20 RESEARCH                     DALLAS                                                                         
        30 SALES                        CHICAGO                                                                        
        40 OPERATIONS                   BOSTON

SQL> col deptno for 99;
SQL> select * from dept;

DEPTNO DNAME                        LOC                                                                                
------ ---------------------------- --------------------------                                                         
    10 ACCOUNTING                   NEW YORK                                                                           
    20 RESEARCH                     DALLAS                                                                             
    30 SALES                        CHICAGO                                                                            
    40 OPERATIONS                   BOSTON

SQL> --查看表的结构
SQL> desc dept;
 名称                                                              是否为空? 类型
 ----------------------------------------------------------------- -------- --------------------------------------------
 DEPTNO                                                            NOT NULL NUMBER(2)
 DNAME                                                                      VARCHAR2(14)
 LOC                                                                        VARCHAR2(13)

SQL> desc emp;
 名称                                                              是否为空? 类型
 ----------------------------------------------------------------- -------- --------------------------------------------
 EMPNO                                                             NOT NULL NUMBER(4)
 ENAME                                                                      VARCHAR2(10)
 JOB                                                                        VARCHAR2(9)
 MGR                                                                        NUMBER(4)
 HIREDATE                                                                   DATE
 SAL                                                                        NUMBER(7,2)
 COMM                                                                       NUMBER(7,2)
 DEPTNO                                                                     NUMBER(2)

SQL> col deptno for 9999999;
SQL> select * from dept;

DEPTNO DNAME                        LOC                                                                              
-------- ---------------------------- --------------------------                                                       
      10 ACCOUNTING                   NEW YORK                                                                         
      20 RESEARCH                     DALLAS                                                                           
      30 SALES                        CHICAGO                                                                          
      40 OPERATIONS                   BOSTON

SQL> col deptno for 99999999;
SQL> select * from dept;

DEPTNO DNAME                        LOC                                                                             
-----
 ---------------------------- --------------------------                                                      
       10 ACCOUNTING                   NEW YORK                                                                        
       20 RESEARCH                     DALLAS                                                                          
       30 SALES                        CHICAGO                                                                         
       40 OPERATIONS                   BOSTON

SQL> col ename for a8;
SQL> select * from dept;

DEPTNO DNAME                        LOC                                                                             
--------- ---------------------------- --------------------------                                                      
       10 ACCOUNTING                   NEW YORK                                                                        
       20 RESEARCH                     DALLAS                                                                          
       30 SALES                        CHICAGO                                                                         
       40 OPERATIONS                   BOSTON

SQL> col dname for a20;
SQL> select * from dept;

DEPTNO DNAME                LOC                                                                                     
--------- -------------------- --------------------------                                                              
       10 ACCOUNTING           NEW YORK                                                                                
       20 RESEARCH             DALLAS                                                                                  
       30 SALES                CHICAGO                                                                                 
       40 OPERATIONS           BOSTON

SQL> --查询所有的另一种形式
SQL> select deptno,dname,loc from dept;

DEPTNO DNAME                LOC                                                                                     
--------- -------------------- --------------------------                                                              
       10 ACCOUNTING           NEW YORK                                                                                
       20 RESEARCH             DALLAS                                                                                  
       30 SALES                CHICAGO                                                                                 
       40 OPERATIONS           BOSTON

SQL> /*
SQL> SQL 优化的第一点: 如果再有查询所有的操作优先采用列出所有列明的方法查询,尽量少用* 代替所有。
SQL> */
SQL> --投影:查询一个大表里面的部分数据(列为单位)
SQL> --查询部门表里面的部门ID
SQL> select deptno from dept;

DEPTNO                                                                                                              
---------                                                                                                              
       10                                                                                                              
       20                                                                                                              
       30                                                                                                              
       40

SQL> select deptno,dname from dept;

DEPTNO DNAME                                                                                                        
--------- --------------------                                                                                         
       10 ACCOUNTING                                                                                                   
       20 RESEARCH                                                                                                     
       30 SALES                                                                                                        
       40 OPERATIONS

SQL> --查询 所有员工的 ID NAME SAL COMM 年薪
SQL> desc emp;
 名称                                                              是否为空? 类型
 ----------------------------------------------------------------- -------- --------------------------------------------
 EMPNO                                                             NOT NULL NUMBER(4)
 ENAME                                                                      VARCHAR2(10)
 JOB                                                                        VARCHAR2(9)
 MGR                                                                        NUMBER(4)
 HIREDATE                                                                   DATE
 SAL                                                                        NUMBER(7,2)
 COMM                                                                       NUMBER(7,2)
 DEPTNO                                                                     NUMBER(2)

SQL> select empno,ename,sal,comm,sal*12 + comm
  2  form emp;
form emp
     *
第 2 行出现错误:
ORA-00923: 未找到要求的 FROM 关键字

SQL> 2
  2* form emp
SQL> c /form/from;
  2* from emp
SQL> /

EMPNO ENAME           SAL       COMM SAL*12+COMM                                                                  
---------- -------- ---------- ---------- -----------                                                                  
      7369 SMITH           800                                                                                         
      7499 ALLEN          1600        300       19500                                                                  
      7521 WARD           1250        500       15500                                                                  
      7566 JONES          2975                                                                                         
      7654 MARTIN         1250       1400       16400                                                                  
      7698 BLAKE          2850                                                                                         
      7782 CLARK          2450                                                                                         
      7788 SCOTT          3000                                                                                         
      7839 KING           5000                                                                                         
      7844 TURNER         1500          0       18000                                                                  
      7876 ADAMS          1100

EMPNO ENAME           SAL       COMM SAL*12+COMM                                                                  
---------- -------- ---------- ---------- -----------                                                                  
      7900 JAMES           950                                                                                         
      7902 FORD           3000                                                                                         
      7934 MILLER         1300

已选择14行。

SQL> -- 总结c(change)命令 首先定位到你错误的哪一行(直接输入错误的行号回车), c空格/错误的单词/正确的单词
SQL> --/可以用来运行上一条sql语句
SQL> /*
SQL> 如果你在做算术运算的时候,某一个字段为空(null),那么他的到的结果就是null
SQL> 在oracle中null 永远不等于null
SQL> */
SQL> --如果你要解决null的问题你需要用到一个oracle的虑空函数
SQL> select empno,ename,sal,comm, sal*12 + nvl(comm,0)
  2  from emp;

EMPNO ENAME           SAL       COMM SAL*12+NVL(COMM,0)                                                           
---------- -------- ---------- ---------- ------------------                                                           
      7369 SMITH           800                          9600                                                           
      7499 ALLEN          1600        300              19500                                                           
      7521 WARD           1250        500              15500                                                           
      7566 JONES          2975                         35700                                                           
      7654 MARTIN         1250       1400              16400                                                           
      7698 BLAKE          2850                         34200                                                           
      7782 CLARK          2450                         29400                                                           
      7788 SCOTT          3000                         36000                                                           
      7839 KING           5000                         60000                                                           
      7844 TURNER         1500          0              18000                                                           
      7876 ADAMS          1100                         13200

EMPNO ENAME           SAL       COMM SAL*12+NVL(COMM,0)                                                           
---------- -------- ---------- ---------- ------------------                                                           
      7900 JAMES           950                         11400                                                           
      7902 FORD           3000                         36000                                                           
      7934 MILLER         1300                         15600

已选择14行。

SQL> --查询comm为null的员工信息
SQL> select *
  2  from emp
  3  where comm = null;

未选定行

SQL> select *
  2  from emp
  3  where comm is null;

EMPNO ENAME    JOB                       MGR HIREDATE              SAL       COMM    DEPTNO                       
---------- -------- ------------------ ---------- -------------- ---------- ---------- ---------                       
      7369 SMITH    CLERK                    7902 17-12月-80            800                   20                       
      7566 JONES    MANAGER                  7839 02-4月 -81           2975                   20                       
      7698 BLAKE    MANAGER                  7839 01-5月 -81           2850                   30                       
      7782 CLARK    MANAGER                  7839 09-6月 -81           2450                   10                       
      7788 SCOTT    ANALYST                  7566 19-4月 -87           3000                   20                       
      7839 KING     PRESIDENT                     17-11月-81           5000                   10                       
      7876 ADAMS    CLERK                    7788 23-5月 -87           1100                   20                       
      7900 JAMES    CLERK                    7698 03-12月-81            950                   30                       
      7902 FORD     ANALYST                  7566 03-12月-81           3000                   20                       
      7934 MILLER   CLERK                    7782 23-1月 -82           1300                   10

已选择10行。

SQL> spool off;

oracle的基本查询~上的更多相关文章

  1. Oracle中分页查询语句

    Oracle分页查询语句使我们最常用的语句之一,下面就为您介绍的Oracle分页查询语句的用法,如果您对此方面感兴趣的话,不妨一看. Oracle分页查询语句基本上可以按照本文给出的格式来进行套用.O ...

  2. oracle数据库常用查询一

    oracle数据库常用查询一 sqlplus / as sysdba; 或sqlplus sys/密码 as sysdba;两者都是以sys登录.conn scott/tiger@orcl; conn ...

  3. Oracle的分页查询语句优化

    Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. (一)   分页查询格式: SELECT * FROM  ( SELECT A.*, ROWNUM RN  FROM (SELECT ...

  4. Oracle 的分页查询 SQL 语句

    Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. 分页查询格式: SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM T ...

  5. Oracle锁表查询和解锁方法

    数据库操作语句的分类 DDL:数据库模式定义语言,关键字:create DML:数据操纵语言,关键字:Insert.delete.update DCL:数据库控制语言 ,关键字:grant.remov ...

  6. oracle锁表查询

    ORACLE EBS操作某一个FORM界面,或者后台数据库操作某一个表时发现一直出于"假死"状态,可能是该表被某一用户锁定,导致其他用户无法继续操作 复制代码代码如下: --锁表查 ...

  7. Oracle PL/SQL Developer 上传下载Excel

    接到需求,Oracle数据库对Excel数据进行上传和下载,百度后没有很全的方案,整理搜到的资料,以备不时之需. 一.下载Oracle数据到Excel中. 下载数据到Excel在MSSql中很简单,直 ...

  8. 08 Oracle表碎片查询以及整理(高水位线)

    Oracle表碎片查询以及整理(高水位线) 1.表碎片的来源 当针对一个表的删除操作很多时,表会产生大量碎片.删除操作释放的空间不会被插入操作立即重用,甚至永远也不会被重用. 2.怎样确定是否有表碎片 ...

  9. oracle里的查询转换

    oracle里的查询转换的作用 Oracle里的查询转换,有称为查询改写,指oracle在执行目标sql时可能会做等价改写,目的是为了更高效的执行目标sql 在10g及其以后的版本中,oracle会对 ...

随机推荐

  1. while DEMO

    while DEMO #!/bin/bash #author:xiluhua #since: let v_count= " ] do ] then sleep echo $v_count l ...

  2. MySQL start and stop

    一.本文说明 本实验主要是演示MySQL的四种启动方式,附带停止的操作. 二.mysqld mysqld is the MySQL server   mysqld reads options from ...

  3. IOS中用UIStoryBoard类初始化/跳转控制器

    1.空工程中通过创建storyboard文件加载页面   //获取Main.storyboardUIStoryboard *mainStory = [UIStoryboard storyboardWi ...

  4. C#:数据交互

    JS与Web交互:http://www.docin.com/p-76710976.html 一.WinForm的WebBrowser控件与JS交互数据: 1.C#类内的代码执行JS脚本函数: 给C#类 ...

  5. symfony中twig的模板变量与注释

    程序会传递给模板若干变量,你需要在模板里输出他们.例如输出$hello .1{{ hello }}.如果传递给模板的是对象或者数组,你可以使用点. 来输出对象的属性或者方法,或者数组的成员.或者你可以 ...

  6. Android关机闹钟实现

    Android关机闹钟实现 时间转换网站:http://tool.chinaz.com/Tools/unixtime.aspx 1.apk层 这个还是比较简单的,百度一下就可以看到apk的代码,我之前 ...

  7. 编写一个函数func(),将此函数的输入参数(int型)逆序输出显示,如54321 –> 12345,要求使用递归,并且函数体代码不超过8行

    public class Test{ //中间变量 private String res = "0"; //方法 public int func(int i){ if(i>0 ...

  8. SlickGrid example 7:鼠标事件

    响应鼠标事件,可以左键快捷选择切换选项,可右键弹出菜单栏.   代码: <!DOCTYPE HTML> <html> <head> <meta http-eq ...

  9. Javascript中最常用的经典技巧

    1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键<table border oncontextmenu= ...

  10. A Mathematical Curiosity 分类: HDU 2015-06-25 21:27 11人阅读 评论(0) 收藏

    A Mathematical Curiosity Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...