博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
oracle实验6-8:关于null值,列的别名,去掉重复行
阅读量:5308 次
发布时间:2019-06-14

本文共 1547 字,大约阅读时间需要 5 分钟。

NULL值

实验6:关于null值得问题

SQL> select ename,sal,comm from emp;

ENAME             SAL       COMM                                               

---------- ---------- ----------                                               
SMITH              800                                                          
ALLEN             1600         300                                               
WARD             1250         500                                               
JONES             2975                                                          
MARTIN           1250        1400                                               
BLAKE            2850                                                          
CLARK            2450                                                          
KING              5000                                                          
TURNER          1500             0                                               
JAMES             950                                                          
FORD             3000                                                                                                          
MILLER           1300                                                          

已选择12行。

其中COMM列中有一些行没有值,是空值(null)。

  • null值不等于0,也不等于空格。
  • null值是未赋值的值。
  • null值是双银剑,使用好了提高性能。

别名

别名的使用原则

  • 区别同名列的名称
  • 非法的表达式合法化
  • 按照你的意愿显示列的名称
  • 特殊的别名要双引
  • 直接写列的后面
  • 使用as增加可读性

实验7:在列上起一个别名

SQL> select sal as salary , hiredate "上班日期",sal*12 total_salary from emp;

    SALARY 上班日期       TOTAL_SALARY                                         

---------- -------------- ------------                                         
       800 17-12月-80             9600                                         
      1600 20-2月 -81            19200                                         
      1250 22-2月 -81            15000                                         
      2975 02-4月 -81            35700                                         
      1250 28-9月 -81            15000                                         
      2850 01-5月 -81            34200                                         
      2450 09-6月 -81            29400                                         
      5000 17-11月-81            60000                                         
      1500 08-9月 -81            18000                                         
       950 03-12月-81            11400                                         
      3000 03-12月-81            36000                                                                                   
      1300 23-1月 -82            15600                                         

已选择12行。

SQL> select sal salary from emp;

    SALARY                                                                     

----------                                                                     
       800                                                                     
      1600                                                                     
      1250                                                                     
      2975                                                                     
      1250                                                                     
      2850                                                                     
      2450                                                                     
      5000                                                                     
      1500                                                                     
       950                                                                     
      3000                                                                                                                                            
      1300                                                                     

已选择12行。

SQL> select sal as salary , hiredate as 日期 from emp;

    SALARY 日期                                                                

---------- --------------                                                      
       800 17-12月-80                                                          
      1600 20-2月 -81                                                          
      1250 22-2月 -81                                                          
      2975 02-4月 -81                                                          
      1250 28-9月 -81                                                          
      2850 01-5月 -81                                                          
      2450 09-6月 -81                                                          
      5000 17-11月-81                                                          
      1500 08-9月 -81                                                          
       950 03-12月-81                                                          
      3000 03-12月-81                                                                                                                 
      1300 23-1月 -82                                                          

已选择12行。

重复的行

select语句显示重复的行,可以使用distinct语法去掉重复的行

SQL> select deptno from emp;

    DEPTNO                                                                     

----------                                                                     
        20                                                                     
        30                                                                     
        30                                                                     
        20                                                                     
        30                                                                     
        30                                                                     
        10                                                                     
        10                                                                     
        30                                                                     
        30                                                                     
        20                                                                                                                                          
        10                                                                     

已选择12行。

实验8:在显示的时候去掉重复的行

使用distinct关键字去掉重复的行

SQL> select distinct deptno from emp;

    DEPTNO                                                                     

----------                                                                     
        30                                                                     
        20                                                                     
        10     

在oracle10g前的版本需要排序才能去掉重复的行,在10g中不需要排序,所以输出也是无序的。

 

返回目录  

 

转载于:https://www.cnblogs.com/downpour/p/3139352.html

你可能感兴趣的文章
Android面试收集录15 Android Bitmap压缩策略
查看>>
PHP魔术方法之__call与__callStatic方法
查看>>
ubuntu 安装后的配置
查看>>
web前端之路,js的一些好书(摘自聂微东 )
查看>>
【模板】对拍程序
查看>>
【转】redo与undo
查看>>
解决升级系统导致的 curl: (48) An unknown option was passed in to libcurl
查看>>
Java Session 介绍;
查看>>
spoj TBATTLE 质因数分解+二分
查看>>
Django 模型层
查看>>
dedecms讲解-arc.listview.class.php分析,列表页展示
查看>>
Extjs6 经典版 combo下拉框数据的使用及动态传参
查看>>
【NodeJS】http-server.cmd
查看>>
研磨JavaScript系列(五):奇妙的对象
查看>>
面试题2
查看>>
selenium+java iframe定位
查看>>
P2P综述
查看>>
第五章 如何使用Burp Target
查看>>
Sprint阶段测试评分总结
查看>>
sqlite3经常使用命令&语法
查看>>