Oracle视图拼接字符串

CREATE OR REPLACE VIEW VW_SXGL_SXPZZXQKCX AS
SELECT
CONCAT(CONCAT(L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_SSDWBH),CONCAT(L.SXGLSXZXQK_SXJGBH,K.SXGLSXXY_SXBZBH)) as NM,
L.SXGLSXZXQK_PZBH AS PZBH,--品种编号
L.SXGLSXZXQK_PZMC AS PZMC,
L.SXGLSXZXQK_SSDWBH AS SSDWBH,
L.SXGLSXZXQK_SSDWMC AS SSDWMC,
L.SXGLSXZXQK_SXJGBH AS SXJGBH,
L.SXGLSXZXQK_SXJGMC AS SXJGMC,
K.SXGLSXXY_SXBZBH AS BZBH,
K.SXGLSXXY_SXBZMC AS BZMC,
WM_CONCAT(distinct(K.SXGLSXXY_SSDWBH)) AS XYSSDWBH,                      GROUP_CONCAT(distinct(K.SXGLSXXY_SSDWBH)) AS XYSSDWBH,      
SUM(L.SXGLSXZXQK_SXED) AS SXED,
SUM(L.SXGLSXZXQK_ZYED) AS ZYED,
SUM(L.SXGLSXZXQK_ZXED) AS ZXED,
SUM(L.SXGLSXZXQK_SFED) AS SFED
FROM SXGLSXZXQK L
LEFT JOIN SXGLSXXY K ON L.SXGLSXZXQK_XYBH=K.SXGLSXXY_XYBH
GROUP BY L.SXGLSXZXQK_PZBH,L.SXGLSXZXQK_PZMC,K.SXGLSXXY_SXBZBH,L.SXGLSXZXQK_SSDWBH,L.SXGLSXZXQK_SSDWMC,L.SXGLSXZXQK_SXJGBH,L.SXGLSXZXQK_SXJGMC,K.SXGLSXXY_SXBZMC;

 

 replace(WM_CONCAT(K.SXGLSXXY_SSDWBH),',','|')      将连接符,变成|

 

 

oracle WM_CONCAT(K.SXGLSXXY_SSDWBH) AS XYSSDWBH, 

others GROUP_CONCAT(K.SXGLSXXY_SSDWBH) AS XYSSDWBH,  

一定给命名  AS 必须

distinct用来去重

 

posted @ 2020-07-08 14:08  泉城余文乐  Views(429)  Comments(0Edit  收藏  举报