zoukankan      html  css  js  c++  java
  • 常用Oracle函数记录

    1. Oraclereplace函数与translate函数

    replace函数是在字符串级别的代替,对应字符串一一替换

    SQL> SELECT REPLACE('accd','cd','ef') from dual;
     
    REPLACE('ACCD','CD','EF')
    -------------------------
    acef

    translate函数是在字符级别的代替,对应字符一一替换   translate(expr,from_string,to_string) 

    SQL> select translate('acdd','cd','ef') from dual;
     
    TRANSLATE('ACDD','CD','EF')
    ---------------------------
    aeff

    translate函数在to_string位置为空,则返回值为空

    SQL> select translate('acdd','cd','') from dual;
     
    TRANSLATE('ACDD','CD','')
    -------------------------
     

    translate中有#的特殊用法,以#开头的表示所有字符

    SQL> select translate('liyan4h123ui','#liyanhui','#') from dual;
     
    TRANSLATE('LIYAN4H123UI','#LIY
    ------------------------------
    4123
     
    SQL> select translate('liyan4h123ui','#liyanhui','#z') from dual;
     
    TRANSLATE('LIYAN4H123UI','#LIY
    ------------------------------
    z4123
     
    SQL> select translate('liyan4h123ui','#liyanhui','#zx') from dual; 
     
    TRANSLATE('LIYAN4H123UI','#LIY
    ------------------------------
    zx4123x
     
    SQL> select translate('asadad434323', '#0123456789','#') from dual; 
     
    TRANSLATE('ASADAD434323','#012
    ------------------------------
    asadad

    2. Oracle的nvl函数与coalesce函数

      nvl函数与coalesce函数都是处理null值的函数

      不同是nvl函数只支持两个参数,coalesce函数可以支持多个参数,效率更高

      他们都是返回第一个不为null的值

    SQL> select nvl('beijing','shanghai') from dual;
     
    NVL('BEIJING','SHANGHAI')
    -------------------------
    beijing
     
    SQL> select nvl(null,'shanghai') from dual;
     
    NVL(NULL,'SHANGHAI')
    --------------------
    shanghai
     
    SQL> select coalesce('beijing','shanghai','shandong') from dual;
     
    COALESCE('BEIJING','SHANGHAI',
    ------------------------------
    beijing 
     
    SQL> select coalesce(null,null,'shandong') from dual;
     
    COALESCE(NULL,NULL,'SHANDONG')
    ------------------------------
    shandong

    ------待续

  • 相关阅读:
    Frameworks.Entity.Core 5 EntityValidation
    Frameworks.Entity.Core 4
    大叔 Frameworks.Entity.Core 3 Predicate
    大叔 Frameworks.Entity.Core 2 PageList
    Frameworks.Entity.Core 1
    大叔 EF 来分析 EntityFrameworks.Data.Core 2
    大叔 EF 来分析 EntityFrameworks.Data.Core 1
    基于 Lind.DDD 的 权限管理系统
    HttpApplication IHttpAsyncHandler, IHttpHandler, IComponent, IDisposable ps url System.Web.dll
    MVC 记录
  • 原文地址:https://www.cnblogs.com/myrunning/p/4600172.html
Copyright © 2011-2022 走看看