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. C#:将子Form加入父Form中

    实现的功能:已建立了多个子Form界面,在父Form界面左面,点击不同标题的链接文本,父Form界面右面显示不同的子界面内容. 具体如下: 1.加入split拆分器控件 2.在splitControl ...

  2. ecshop后台增加模块菜单详细教程(图)

    我们有时候针对ecshop如此开发,想在后台加一些菜单,最模板以前提供过教程,但是并非很系统,今天最模板抛砖引玉图文教程告诉大家:如何在ecshop后台增加模块菜单! 首先需要修改四个文件:inc_p ...

  3. JavaScript脚本语言基础(二)

    导读: JavaScript条件语句 JavaScript循环语句 JavaScript网页中错误捕获 JavaScript的Break和Continue命令 JavaScript的转义字符 1.Ja ...

  4. JS删除script标签

    可以试试以下方法 var deleteJs = document.getElementById('xxx'); var otherJs = document.getElementsByTagName( ...

  5. Android本机号码及Sim卡状态的获取

    SIM卡存储的数据可分为四类:第一类是固定存放的数据.这类数据在移动电话机被出售之前由SIM卡中心写入,包括国际移动用户识别号(IMSI).鉴权密钥(KI).鉴权和加密算法等等.第二类是暂时存放的有关 ...

  6. 发现数据库错误模式(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于发现数据库错误模式问题的.下面就把这块东西分享出来. 原创文章,转载请注明 --------------- ...

  7. Pots 分类: 搜索 POJ 2015-08-09 18:38 3人阅读 评论(0) 收藏

    Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11885 Accepted: 5025 Special Judge D ...

  8. 山东理工大学第七届ACM校赛-完美素数 分类: 比赛 2015-06-26 10:36 15人阅读 评论(0) 收藏

    完美素数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 我们定义:如果一个数为素数,且这个数中含有7或3,那么我们称这个数为完美 ...

  9. Educational Codeforces Round 16 C

    Description Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column ...

  10. Android开发之Theme、Style探索及源码浅析

    1 背景 前段时间群里有伙伴问到了关于Android开发中Theme与Style的问题,当然,这类东西在网上随便一搜一大把模板,所以关于怎么用的问题我想这里也就不做太多的说明了,我们这里把重点放在理解 ...