zoukankan      html  css  js  c++  java
  • OraCle 记录 实现 sql中的 for xml path ('')

    select  * from qx_role where N_role_id in ( 1,2,3)

    运行结果:

    select to_char(wm_concat(c_role_name)) from qx_role
    where N_role_id in ( SELECT REGEXP_SUBSTR ( '1,2,3', '[^,]+', 1,rownum)
    from dual connect by rownum<=LENGTH ( '1,2,3') - LENGTH (regexp_replace( '1,2,3', ',', ''))+1)
    实现sql

    运行结果:

      wm_concat(col) 方法 可当做 sum 等函数 可配合group By 使用  此方法可以将每一行的  col 值 以逗号的形式 拼接成一个值 与  sql server 中的for xml path('') 相似;

     SELECT REGEXP_SUBSTR ( '1,2,3', '[^,]+', 1,rownum)
    from dual connect by rownum<=LENGTH ( '1,2,3') - LENGTH (regexp_replace( '1,2,3', ',', ''))+1

    效果:

     这条 sql 主要 是实现了 把  字符串 “1,2,3” 转换成表结构  相当于 前面 sql 里面的表值函数 s_split() 

    初接触oracle  做记录  关于 connect by 的用法 可参考收藏博客  start with connect by prior 递归查询用法

    select t.c_user_id,
                   to_char(wm_concat(t.c_situation_use_month)
                           over(partition by c_user_id order by
                                t.c_situation_use_month)) qfyf,
                   t.n_amount qfje,
                   t.c_situation_use_month qfy
              from yx_situation t
             where t.n_calculation_way = 0
               and t.n_charge_state = 0
    运用

    运行效果:

     查询语句中配合 over() 函数开窗;

  • 相关阅读:
    java注解
    Mac窗口管理管理软件SizeUp
    mac下8080端口到80端口的转发
    mac svn的替代品CornerStone
    模板模式讲解二
    数组和集合List的相互转化
    fastjson使用示例
    模板模式讲解一
    mybatis-generator-core自动生成do、mapping、dao 代码
    maven依赖传递关系
  • 原文地址:https://www.cnblogs.com/pyf97/p/13098032.html
Copyright © 2011-2022 走看看