将以下sql语句中wm_concat 改成listagg SELECT t1.*, t2.P_USER_NAME CREATE_NAME, t3.r_id FROM ( SELECT P_ID, ORG_ID, P_USER_NAME, LOGIN_ID, LOGIN_PWD, P_USER_TYPE, CREATE_ID, DEL_FLAG, CREATE_TIME, MODIFY_ID, MODIFY_TIME, school_rs_id FROM T_XT_ORG_USER WHERE p_id = #{userId} ) t1 LEFT JOIN T_XT_ORG_USER t2 ON t1.p_id = t2.p_id LEFT JOIN ( SELECT p_id, wm_concat (r_id) AS r_id FROM t_xt_role_users t3 GROUP BY p_id ) t3 ON t1.p_id = t3.p_id
时间: 2023-08-05 07:02:13 浏览: 195
可以使用Oracle官方支持的LISTAGG函数来替换wm_concat函数。LISTAGG函数与wm_concat函数类似,也可以将多个行连接成一个字符串,但是它是Oracle官方支持的函数,使用更加稳定可靠。将上述的SQL语句中的wm_concat函数替换为LISTAGG函数,可以这样写:
```
SELECT t1.*, t2.P_USER_NAME CREATE_NAME, t3.r_id
FROM
(
SELECT P_ID, ORG_ID, P_USER_NAME, LOGIN_ID, LOGIN_PWD, P_USER_TYPE,
CREATE_ID, DEL_FLAG, CREATE_TIME, MODIFY_ID, MODIFY_TIME, school_rs_id
FROM T_XT_ORG_USER
WHERE p_id = #{userId}
) t1
LEFT JOIN T_XT_ORG_USER t2 ON t1.p_id = t2.p_id
LEFT JOIN
(
SELECT p_id, LISTAGG(r_id, ',') WITHIN GROUP (ORDER BY r_id) AS r_id
FROM t_xt_role_users t3
GROUP BY p_id
) t3 ON t1.p_id = t3.p_id
```
这里使用了LISTAGG函数来替换了wm_concat函数,同时使用了WITHIN GROUP子句指定了连接多个值时使用的分隔符。注意,使用LISTAGG函数时需要指定WITHIN GROUP子句,否则会报错。
阅读全文