zoukankan      html  css  js  c++  java
  • Oracle字符串函数-Translate()总结

    Oracle的Translate(expr,from_string,to_string)是字符串操作函数,实现from_string,to_string字符的一 一替换

    1)典型示例:

    select translate('abcdef','abc','123') from dual;

    输出:

    TRANSLATE('ABCDEF','ABC','123'

    --------------------------------------------

    123def

    实现:将字符串‘abcdef’中的‘abc’替换为‘123’对应字符一 一替换(实现from_string与to_string以字符为单位,对应字符一 一替换),其它保持不变。

    2)一 一替换示例:from_string对应to_string位置没有对应字符

    select translate('abcdef','abc','12') from dual;

    输出:

    TRANSLATE('ABCDEF','ABC','12')

    -------------------------------------------

    12def

    3)一 一替换示例:from_string比to_string字符少

    select translate('abcdef','ab','123') from dual;

    输出:

    TRANSLATE('ABCDEF','AB','123')

    -------------------------------------------

    12cdef

    4)一 一替换示例:from_string比to_string字符少

    select translate('abcdef','#ab','123') from dual;

    输出:

    TRANSLATE('ABCDEF','#AB','123')

    -------------------------------------------

    23cdef

    5)一 一替换示例:to_string为''串

    select translate('abcdef','#ab','') from dual;

    输出:

    TRANSLATE('ABCDEF','#AB','')

    -------------------------------------------

    总之from_string,to_string对应字符替换,没有则不用替换,熟悉了上面的几个例子,就知道translate(expr,from_string,to_string)的正确用法了。

  • 相关阅读:
    python 基础类与对象函数实例
    python 练习之炮台
    python练习之银行模拟系统
    python练习之析构函数(进阶)
    python练习之__str__
    「JLOI2011」飞行路线
    「国家集训队」Crash的数字表格
    斐波那契公约数的相关证明
    「JSOI2010」满汉全席
    动态规划
  • 原文地址:https://www.cnblogs.com/handhead/p/11580645.html
Copyright © 2011-2022 走看看