举个例子吧 你试着照猫画虎一下 呵呵 SQL> select * from t1; ID NAME ---------- ---------- 1 wh 1 wp 1 wj 2 ha SQL> select ltrim(sys_connect_by_path(name,','),',') names 2 from 3 ( 4 select id,name, 5 row_number() over(partition by id order by id) rn, 6 count(*) over (partition by id) cnt 7 from t1 8 ) 9 where id=1 and level=cnt 10 start with rn=1 11 connect by prior rn=rn-1 and prior id=id;NAMES -------------------- wh,wp,wj
SQL> select name 2 from t1 3 where id=1;NAME ---------- wh wp wj
是insert的话,在插入“张三,李四,王五,赵六”后,人员表的其他字段如何操作?
你最好能把两个表结构和数据都贴些出来。
工号 姓名 部门
01 张三 车间
02 李四 车间
03 王五 车间
04 赵六 车间人员表:
人数 到班人员 日期
3 张三,李四,王五,赵六 2009-12-6
我如何才能得到第二个表的结果?
from yhb where bm='车间';oracle 啥版本?
你只有用SYS_CONNECT_BY_PATH把“张三,李四,王五,赵六”拼在一列。
具体用法你网上搜搜。
在9i 中好象没有这个函数呀?
你试着照猫画虎一下 呵呵
SQL> select * from t1; ID NAME
---------- ----------
1 wh
1 wp
1 wj
2 ha
SQL> select ltrim(sys_connect_by_path(name,','),',') names
2 from
3 (
4 select id,name,
5 row_number() over(partition by id order by id) rn,
6 count(*) over (partition by id) cnt
7 from t1
8 )
9 where id=1 and level=cnt
10 start with rn=1
11 connect by prior rn=rn-1 and prior id=id;NAMES
--------------------
wh,wp,wj
2 from t1
3 where id=1;NAME
----------
wh
wp
wj
我这个表中大概有1万多条记录呀.