如:
1 A
2 B
3 C
4 D
5 E
拼成
A,B,C,D,E 
请用简单的SQL语句实现,不用PL/sql,可以吗?

解决方案 »

  1.   

    select (select col from tbname where id=1)||','
    (select col from tbname where id=2)||','
    (select col from tbname where id=3)||','
    (select col from tbname where id=4)||','
    (select col from tbname where id=5) from dual;
      

  2.   

    假设记录是不定的呢?除了用cursor 还有其他办法啊?
      

  3.   

    create function get_value
    return varchar2
    as
    cursor t_sor is
    select col_name from tab1;
    str varchar2(100);
    num number:=0;
    begin
    for v_sor in t_sor loop
    if num=0 then
    str:=v_sor.col_name;
    num:=num+1;
    else
    str:=str||','||v_sor.col_name;
    end if;
    end loop;
    return str;
    end;
    /
    select get_value from dual;