在SQL语句中查询多条记录并把多条记录同一字段的值连接成一个字符并返回的写法...

xiaoxiao2026-09-12  15

在SQL语句中查询多条记录并把多条记录同一字段的值连接成一个字符并返回的写法: 实现1.游标并循环拼凑sql语句 实现2: 用select语句:

select substr(sys_connect_by_path(fcsg_consign_id, '/'), 2) from (select rownum rn, fcsg_consign_id from fconsign where rownum <= 5) connect by rn = rownum start with rn = 1

如果需要查最长的那条并且获取你需要的字符串,还需要函数处理下:

select substr(max(sys_connect_by_path(fcsg_consign_id, '/')), 2) from (select rownum rn, fcsg_consign_id from fconsign where rownum <= 5) connect by rn = rownum start with rn = 1

注意函数:

substr

sys_connect_by_path

转载请注明原文地址: https://www.6miu.com/read-5052562.html

最新回复(0)