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. java技术用ssh从linux服务器下载数据

    通常需要从linux服务器获取数据文件,而通常能有的访问方式只有ssh,所以就可以用ssh进行数据下载. java连接远程主机的方式有多种,这里和大家分享的是通过ssh方式连接远程主机,使用的是jsc ...

  2. 【Pro ASP.NET MVC 3 Framework】.学习笔记.12.ASP.NET MVC3的细节:URLs,Routing和Areas

    Adam Applied ASP.NET 4 in Context 1 介绍Routing系统 在引入MVC之前,ASP.NET假定被请求的URLs和服务器硬盘上的文件之间有着直接关系.服务器的任务是 ...

  3. weblogic从应用服务器找不到主应用服务器

    报错信息: weblogic.cluster.replication.ApplicationUnavailableException: WebApp with contextPath: not fou ...

  4. java map 遍历

    转自http://rain-2372.iteye.com/blog/1615615 package com.spring.test_B11_aop1; import java.util.HashMap ...

  5. maven手动安装jar到本地仓库

    比如oracle驱动ojdbc5.jar 1,安装MAVEN,并配置系统环境变量 2,将jar文件复制到d: 3,打开cmd窗口,cd到d: 4,执行命令:mvn install:install-fi ...

  6. master-slave(主/从)模式

    主从模式 一般来说用在数据库集群比较多,主要是实现读写分离.对于数据库应用而言基本上是读大于写,因此由 Master 服务器负责增.删.改操作,由 Slave 负责读操作(也就是 SELECT),Ma ...

  7. JavaEE基础(六)

    1.面向对象(面向对象思想概述) A:面向过程思想概述 第一步 第二步 B:面向对象思想概述 找对象(第一步,第二步) C:举例 买煎饼果子 洗衣服 D:面向对象思想特点 a:是一种更符合我们思想习惯 ...

  8. 【转】SVN建库方法

    转载地址:http://blog.csdn.net/winonatong/article/details/5791919 SVN全名Subversion,即版本控制系统.SVN与CVS一样,是一个跨平 ...

  9. WebView的返回功能

    WebView 实现返回到最后一个 在退出 import android.app.Activity; import android.os.Bundle; import android.view.Key ...

  10. MySQL常用操作总结

    MySQL常用操作 前提条件:已安装MySQL. 学习目标:用一条sql语句写出A和B的剩余数量 AA表 BB表 以上为一道面试题,接下来由这道面试题来回顾一些数据库的基本操作. 登录MySQL su ...