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. Linux设备驱动之semaphore机制【转】

    转自:http://blog.csdn.net/xiao229404041/article/details/7031776 Linux设备驱动之semaphore机制在Linux系统中,信号号是一种重 ...

  2. oracle日期函数2!

    1.日期时间间隔操作  当前时间减去7分钟的时间 select sysdate,sysdate - interval '7' MINUTE from dual 当前时间减去7小时的时间 ...

  3. ImageLoader 图片加裁

    // String picurl = article.cateLogo;// ImageLoader.getInstance().displayImage(picurl, holder.cate_Lo ...

  4. Mootools插件-闪烁的标题

    转自:http://www.cnblogs.com/see7di/archive/2012/10/09/2716024.html 回想起来,我已经好久没有写点啥了,尤其是关于Mootools方面的东西 ...

  5. mysql聚集索引的优缺点

    聚簇索引并不是一种单独的索引类型,而是一种数据存储方式(不是数据结构,而是存储结构),具体细节依赖于其实现方式,但innodb的聚簇索引实际上是在同一个结构中保存了btree索引和数据行. 当表有索引 ...

  6. 20145227 《Java程序设计》实验五实验报告

    20145227 <Java程序设计>实验五实验报告 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验过程 1.先运行TCP代码,一人服务 ...

  7. android 数据库操作

    做android的数据库方面用的很少,所以用的时候记录下来,下次碰到直接copy,一下代码是最基本的实现: 首先是继承helper类: package com.create.rycreateim.db ...

  8. Android 5.1 - 状态栏充电标志问题

    Android 5.1 Ubuntu14.04  SourceInsigh 电量已满,插着USB头,观察Settings - Battery,电量为100%,状态为full,但仍有充电图标rust 之 ...

  9. YTU 2924: 文件操作--二进制文件读入

    2924: 文件操作--二进制文件读入 时间限制: 1 Sec  内存限制: 128 MB 提交: 58  解决: 20 题目描述 现有100名学生的姓名(name).学号(num).英语(Engli ...

  10. poj1222 EXTENDED LIGHTS OUT

    设输入矩阵为A,输出矩阵为B,目标矩阵为C(零矩阵). 方便起见,矩阵行列下标均从1开始. 考虑A矩阵元素a(i,j),B矩阵中与其相邻的元素 b(i,j),b(i - 1, j),b(i + 1,j ...