oracle 怎么写Function从A表的取出某列的值集从大到小 更新到B表中的某一列
A表 字段 Id ,Name,CSN
1 WO 1111
2 WO 1112
3 WO 1113
4 WO 1114
B表 ID SN SN_CSN
1 C1
2 C2
3 C3
4 C4
两张表的记录条数是一样的,怎么样把A表的CSN 从小到大的更新到B表的SN_CSN 栏位,与B表的SN从小到大对应,请大侠们帮忙,初学oracle,不是很了解
结果:B表 ID SN SN_CSN
1 C1 1111
2 C2 1112
3 C3 1113
4 C4 1114
------解决方案--------------------create table a
(
Id varchar(10),
Name varchar(10),
CSN varchar(10)
)
create table b
(
ID varchar(10),
SN varchar(10),
SN_CSN varchar(10)
)
insert into a values ('1','WO ','1111');
insert into a values ('2','WO ','1112');
insert into a values ('3','WO ','1113');
insert into a values ('4','WO ','1114');
insert into b (id,sn) values ('1', 'C1');
insert into b (id,sn) values ('2', 'C2');
insert into b (id,sn) values ('3', 'C3');
insert into b (id,sn) values ('4', 'C4');
select * from a;
select * from b;
update b set SN_CSN=(select aaa.csn from
(select aa.csn,bb.sn from
(select CSN,row_number() over (order by CSN asc) st from a) aa
,
(select sn,row_number() over (order by sn asc) st from b) bb
where aa.st=bb.st) aaa where aaa.sn=b.sn
)