`
flashsnow
  • 浏览: 29159 次
  • 性别: Icon_minigender_1
  • 来自: 太原
社区版块
存档分类
最新评论

Oracle常用函数

阅读更多

1. 查询先后顺序
    a. 执行from
    b. 执行where
    c. 执行select
   所以,from 表名 as 表别名 可以在where中使用,而且通常也这么做
    但是select 列名 as 列别名 不可以在where中使用,如果必须使用列别名,需要嵌套一个内联视图

 

2. 使用concat函数连接来自多个列的值

    在DB2、Oracle中,用“||”是concat的简写

    在SQL Server 中“+” 是concat的简写

 

3. CASE

        WHEN ... THEN ...

        WHEN ... THEN ...

        ELSE ...

    AS 列别名

 

    如果没有ELSE,对不满足条件的行,CASE表达式返回NULL

 

4. 随即返回N条记录

      SELECT * from ( select * from emp order by dbms_random.value() ) where rownum < N

 

5. 将空值转为实际值

        nvl('空值','实际值')

        coalesce('...','...','...') 返回第一个不是null的值,如果全部为null则返回null

 

6. replace('str', 'search_str'  [,'replace_str'] )表示在str中查到的search_str全部(整体)用replace_str替换,如果str中不包含search_str,则原样输出str,如果不指定replace_str、replace_str为null、‘空’,则将str 中的search_str子串删除

 

 

7. translate('str','sub','re')的参数个数必须为3个

    如: translate('abcd', 'ab' , '12' )    -->  12cd

            translate('abcd', 'ab' , '123' )    --> 12cd

           translate('abcd', 'a' , '123' )    -->  1bcd

          translate('abcd', 'abc' , '12' )    --> 12d

          translate('abcd', '' , '12' )    --> 没有

          translate('abcd', 'ab' , '' )    --> 没有

 

8. 字段排序的时,默认null为最大,可以在(单个)排序字段之后使用null last或者null first ,指定null的排序位置

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics