zoukankan      html  css  js  c++  java
  • Oracle:分割字符串

    oracle数据库,表数据如下:

    ids                           id

    3,4,5                        7

    13,14,15,16             17

    想要使用sql,实现将ids按照逗号分割后查询到如下记录:

    ids                           id

    3                              7

    4                              7

    5                              7

    13                            17

    14                            17

    15                            17

    16                            17 

    在Oracle9i以上版本中,可以使用regexp_substr实现。具体sql语句如下:

    select id,ids from(

      select regexp_substr(ids, '[^,]+',1,lvl) ids, lvl, id from tbl,

      (select level lvl from dual connect by

      level < =(select max(length(regexp_replace(ids,'[^,]','')))+1 max_tokens from tbl))

    ) where ids is not null order by lvl

  • 相关阅读:
    mysql调优
    面试、。。。。
    StringBuffer 和 StringBuilder 的 3 个区别
    msql查询指定日期
    Windows 路由跟踪
    Xdebug配置
    ONVIF流媒体播放流程
    Windows 8 SP1 安装StockTrader 6.1
    使用log4c问题
    xcode插件安装
  • 原文地址:https://www.cnblogs.com/MyFavorite/p/2745561.html
Copyright © 2011-2022 走看看