2018年06月23日
评论数(0)
背景:查询结果其中一列多行的值,通过一行来展示。同一客户,不同商品在不同的仓库配送,每个仓库的配送周期不一样,如何在查询这个客户档案时,将客户所有仓库的周期等一起显示出来。方便订单操作人员查询、检查、分析
案例:客户档案,其中列数据要有,客户仓库的配送周期,客户各仓库的最小配送金额
方案:两种可以借鉴。
第一种
---一、定义函授
/*
create or replace package PkFor is
\*
ps_sql 是一个sql查询语句,返回一个结果列。
函数返回 以ps_separator为分隔符,ps_len为长度限制,连接结果列为字符串,并return。
ps_len小于10时默认为10,所以return返回值最小长度10。
*\
FUNCTION linkColBySth(ps_sql VARCHAR2,
ps_separator VARCHAR2 DEFAULT ',', --逗号
ps_len INTEGER DEFAULT 20)
RETURN VARCHAR2;
end PkForCary;
*/
---二、使用函数
/*
select PkFor.linkColBySth('select ''a'' as aa from dual
union all
select ''b'' as aa from dual
union all
select ''c'' as aa from dual
union all
select ''c'' as aa from dual
union all
select ''c'' as aa from dual
union all
select ''c'' as aa from dual
union all
select ''c'' as aa from dual')
from dual
*/
第二种: to_char(WM_CONCAT(''*****''))
/*
create or replace view v_cvs_zqpursallist_view as
select custoprorgcode,dataorgid,custoprorgid,
to_char(WM_CONCAT(DisWhOrgCode || ':' || senumvaluename || ':' ||
(case senumvalue || custordday when '01' then '1-单日'
when '02' then '2-双日'
else custordday end))) as custordday,
to_char(WM_CONCAT(DisWhOrgCode || ':' || OrdMinTotal)) as OrdMinTotal
from
(select b.custoprorgcode,a.dataorgid,b.custoprorgid,
a.DisWhOrgCode,c.senumvaluename,c.senumvalue,b.custordday,
b.OrdMinTotal
from tCobPurSalList a,
tCobPurSalListCust b,
tFraEnumValue c
where a.pursallistid = b.pursallistid
and b.custOrdMode = c.senumvalue
and c.senumtype = 'COB003'
and a.PurOrDisType = 0 --0-配货清单 ,1-进货清单
and a.DisType = 0 --0-普通, 1-直送
order by b.custoprorgcode,a.diswhorgcode)
group by custoprorgcode,dataorgid,custoprorgid
with read only
;
*/