将每行记录用与逗号拼接起来

oracle11g版本:
SQL:select wmsys.wm_concat(t.id) from test_yc t

通用版本:
declare
  cursor c_sql is
         select id from test_yc;
    v_id varchar2(50) default null;
    v_concat_id  varchar2(1000);
begin
  open c_sql;
    fetch c_sql into v_id;
    while c_sql%FOUND loop
        v_concat_id := v_concat_id || ',' || v_id;
       
        fetch c_sql into v_id;
    end loop;
   
    v_concat_id := substr(v_concat_id, 2, length(v_concat_id)-1);
    dbms_output.put_line(v_concat_id);
    close c_sql;
end;

结果:
id1,id2,id3,....

你可能感兴趣的:(sql,C++,c,C#)