在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