返回列表 回复 发帖

请教一个SQL语句

比如我有一个SQL:select Head_number from TB
得到结果为:
0001
0002
0003
0004

如何将上面的结果并起来得到:0001000200030004

谢谢!
[php]
SQL> create table tb( a varchar2(4));

表已创建。

SQL> begin
  2  insert into tb values('0001');
  3  insert into tb values('0002');
  4  insert into tb values('0003');
  5  insert into tb values('0004');
  6  end;
  7  /

PL/SQL 过程已成功完成。

SQL> select * from tb;

A
----
0001
0002
0003
0004

SQL> Select replace(Substr(Sys_Connect_By_Path(a, ','), 2), ',', '')
  2    From (Select Rownum Rid, Rownum + 1 Next_Rid, a From tb)
  3   Where Rid = (Select Count(*) From tb)
  4   Start With Rid = 1
  5  Connect By Prior Next_Rid = Rid;

REPLACE(SUBSTR(SYS_CONNECT_BY_PATH(A,','),2),',','')
--------------------------------------------------------------------------------
0001000200030004

SQL>
[/php]
很不错
不过这个应该不是发在这个栏目里
----    吃得苦中苦,方为人上人!
----    不想当将军的士兵不是个好兵!
搞定
--------------------------------------------------------------------
create or replace function fff
          is
          v_id    varchar2(100);
         begin
          for c1 in (select id from table ) loop
              v_id:=v_id||c1.id;
          end loop;
        end;
2楼的SQL真强大!
Yeah,2楼的SQL我都没见过 >"<
有机会研究研究,得加把劲儿喽
刚刚去查,9i之后的有Sys_connect_by_path功能了 ^_^
wow ... thanks for sharing skills
返回列表