zoukankan      html  css  js  c++  java
  • oracle 函数笔记

    substr()与substrb()
    区别在于对汉字的截取,一个汉字可能会占2个或3个字符,substr()截取的长度是指字符串的长度,substrb()截取的长度是指字符串所占字符的长度。
    例子如下:
    select substr('哈哈哈哈哈哈',1,6) from dual;
    哈哈哈哈哈哈
    select substrb('哈哈哈哈哈',1,6) from dual; --使用的库一个汉字是占3个字符,UTF-16
    哈哈
    select substr('123abc!@#$%^&*()',1,16) from dual;
    123abc!@#$%^&*()
    select substrb('123abc!@#$%^&*()',1,16) from dual;
    123abc!@#$%^&*()
     
     
     
    decode()
    格式为decode(expr,v_1,value_1,v_2,value_2,...,v_n,value_n,default),如果expr的值为v_1,则返回value_1;值为v_2,则返回value_2;如果在列表中没有与expr匹配上的值,则返回default。在这里,null值与null值视为等价。
    select decode(mod(10,3),1,'余1',2,'余2','整除') res from dual; --余1
    select decode(mod(11,3),1,'余1',2,'余2','整除') res from dual; --余2
    select decode(mod(12,3),1,'余1',2,'余2','整除') res from dual; --整除
     
     
     
    instr(str1,str2,i,j)
    返回str2在str1中第几次出现的位置,i表示搜索起始位置,i,j默认为1
    select instr('Moisossoppo','o') res1,instr('Moisossoppo','o',1,1) res2 from dual --i,j默认值为1
    2 2
    --i为负数时,表示从右向左搜索
    select instr('Moisossoppo','o',3,3) res1,instr('Moisossoppo','o',-2,3) res2,instr('Moisossoppo','o',-1,3) res3 from dual
    11 2 5
  • 相关阅读:
    BZOJ2219数论之神——BSGS+中国剩余定理+原根与指标+欧拉定理+exgcd
    Luogu 3690 Link Cut Tree
    CF1009F Dominant Indices
    CF600E Lomsat gelral
    bzoj 4303 数列
    CF1114F Please, another Queries on Array?
    CF1114B Yet Another Array Partitioning Task
    bzoj 1858 序列操作
    bzoj 4852 炸弹攻击
    bzoj 3564 信号增幅仪
  • 原文地址:https://www.cnblogs.com/simon-chan/p/3935664.html
Copyright © 2011-2022 走看看