转:Oracle 能否实现SQL Sever类似的功能
2010-04-15 15:29 Tracy. 阅读(250) 评论(0) 编辑 收藏 举报Oracle 能否实现SQL Sever类似的功能(见本贴)?
SQL Server 代码如下:
Select name from employee
执行结果:
name
--------------------
冯民
杨涛
陈云
曾小红
陈翠
declare @a varchar(2000)
set @a=''
Select @a=@a + name from employee
Select @a as name
执行结果:
name
----------------------------------------------------------------------------------------------------
冯民 杨涛 陈云 曾小红 陈翠
这样我@a 能得到所有employee的name字段的文本
当然, 用游标也可以, 但是这是最简洁的方式
Oracle里也能用简便的语句实现吗?
给你一个例子吧
scott@ORCL> select * from a;
A B C
---------- ---------- ----------
1 1 aaa
2 1 bbb
3 2 ccc
4 2 ddd
scott@ORCL> select b,substr(max(sys_connect_by_path(c,'/')),2,LENGTH(max(sys_connect_by_path(c,'/')))) path
2 from (select a,b,c,lead(a) over (partition by b order by a desc) d from a)
3 start with d is null
4 connect by prior a = d
5 group by b;
B PATH
---------- --------------------
1 aaa/bbb
2 ccc/ddd
本文来自博客园,作者:Tracy.,转载请注明原文链接:https://www.cnblogs.com/tracy/archive/2010/04/15/1712721.html