依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-oox…
先看示例代码: with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nation ,'New York' city from dual unio…
实现目标   1.聚合文本   2.聚合文本(去重)   3.聚合文本(去重),按照指定字段排序   4.聚合文本(去重),按照指定字段排序,替换默认逗号分隔符 MySQL: group_concat Oracle: wm_concat(11g), listagg(12c) SQL Server: for XML PATH PostgreSQL: string_agg 数据 MySQL Oracle Sql Server…
--行转列的函数-- CREATE OR REPLACE FUNCTION Calvin( col IN VARCHAR2,dw IN VARCHAR2) RETURN VARCHAR2 IS retval ); Sel_sql ); ---//SQL语句声明 BEGIN Sel_sql:='select '||col||' from TB5001 where dwdm='''|| dw||''''; execute immediate Sel_sql into retval ;--执行orac…
--Oracle列转行函数LISTAGG() with tb_temp as( select 'China' 国家,'Wuhan' 城市 from dual union all select 'China' 国家,'Dongjing' 城市 from dual union all select 'China' 国家,'Xijing' 城市 from dual union all select 'Germany' 国家,'Berlin' 城市 from dual union all select…
简单的Oracle列转行函数Listagg示例: CREATE TABLE tbl_test (catalog VARCHAR(1),product VARCHAR(2),amount NUMBER); INSERT INTO tbl_test VALUES('A','A1',1); INSERT INTO tbl_test VALUES('A','A1',2); INSERT INTO tbl_test VALUES('B','B1',3); INSERT INTO tbl_test VALU…
多行转字符串 这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from app_user 字符串转多列 实际上就是拆分字符串的问题,可以使用 substr.instr.regexp_substr函数方式 字符串转多行 使用union all函数等方式 wm_concat函数 首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以",&qu…
业务场景 本博客记录一下Oracle列转行函数在Oracle11的一些不兼容问题,vm_concat在一些业务场景是必须的.不过这个函数使用要谨慎,底层实现应该也是group by等等实现的,性能并不是特别好.这个函数在Oracle12是没有的,在Oracle11是不太兼容的,Oracle10可以正常使用.最近遇到这个问题,网上博客很多都写到了自定义列转行函数的办法去解决.但是这种办法并不一定适用所有的业务场景.我并没有采用.不过有些场景还是可以使用的. 网上优秀例子 下面是网络记录比较详细的例…
本文转自:http://www.cnblogs.com/ycdx2001/p/3502495.html with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select…
一.业务场景 今天需要实现一个table,有一列的效果是:用户姓名A(账号a),用户姓名B(账号b)...这种格式.这就想到oracle的列转行函数vm_concat. 可以用类似这种格式wm_concat(a || '(' || b || ')'),a表示用户名字段,b表示账号字段. 例子: <select id="listAllocatedHandlerInfo" resultType="AllocationHandlerInfoVo"> selec…