• 按字符分割计算列数


    ---计算按,分割列数
    
    SQL> select * from v;
    
    STR
    ----------------
    10,CLARK,MANAGER
    
    SQL> select LENGTH(translate(translate(trim(str),'a0123456789','a'),'#ABCDEFGHIJKLMNOPQRSTUVWXYZ','#'))+1  from v;
    
    LENGTH(TRANSLATE(TRANSLATE(TRIM(STR),'A0123456789','A'),'#ABCDEFGHIJKLMNOPQRSTUVWXYZ','#'))+1
    ---------------------------------------------------------------------------------------------
                                                                                                3
    
    --如果按$#分割:
    
    CREATE OR REPLACE VIEW v AS
    SELECT '10$#CLARK$#MANAGER' AS str FROM dual;
    
    SQL> select * from v;
    
    STR
    ------------------
    10$#CLARK$#MANAGER
    
    
    SQL> select length(translate(translate(trim(str),'a0123456789','a'),'@ABCDEFGHIJKLMNOPQRSTUVWXYZ','@'))/length('$#') +1  from v;
    
    LENGTH(TRANSLATE(TRANSLATE(TRIM(STR),'A0123456789','A'),'@ABCDEFGHIJKLMNOPQRSTUVWXYZ','@'))/LENGTH('$#')+1
    ----------------------------------------------------------------------------------------------------------
                                                                                                         3

  • 相关阅读:
    豆豆
    艺术家
    姐姐
    书名与歌名
    MySQL
    杂文
    武侠
    青年诗人
    那些歌
    传世
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352147.html
Copyright © 2020-2023  润新知