PLSQL里的sql语句问题
我在PLSQL里有一张表,表里有很多条记录,有字段A,B,C.举一个例子,有两条记录m和n,如果记录m.A=n.A,m.B>n.B,m.C<n.C则返回记录n,主要是循环...
我在PLSQL里有一张表,表里有很多条记录,有字段A,B,C. 举一个例子,有两条记录m和n, 如果记录m.A=n.A, m.B>n.B, m.C<n.C则返回记录n, 主要是循环比较,每条记录都要比较,怎么办
用排序把记录按B的大小排好,所有的记录都跟第一条相比,怎么实现 展开
用排序把记录按B的大小排好,所有的记录都跟第一条相比,怎么实现 展开
1个回答
展开全部
用排序把记录按B的大小排好,所有的记录都跟第一条相比,怎么实现
例子不是举得很好 可以看看 原理就是这样
drop table test;
create table test(
a number(5),
b number(5),
c number(5));
insert into test (A, B, C) values (14, 22, 55);
insert into test (A, B, C) values (14, 23, 11);
insert into test (A, B, C) values (14, 22, 12);
insert into test (A, B, C) values (14, 54, 12);
insert into test (A, B, C) values (14, 66, 21);
commit;
declare
min_a number(5);
min_b number(5);
min_c number(5);
cursor cur is select rowid rowadd
from test
where rowid<>(select rowid
from (select rowid
from test
order by b asc)
where rownum=1);
begin
select * into min_a,min_b,min_c
from (select * from test order by b asc)
where rownum=1;
for rec in cur loop
update test set a=min_a,b=min_b,c=min_c
where rowid=rec.rowadd and a=min_a and b>min_b and c<min_c;
commit;
end loop;
end;
/
例子不是举得很好 可以看看 原理就是这样
drop table test;
create table test(
a number(5),
b number(5),
c number(5));
insert into test (A, B, C) values (14, 22, 55);
insert into test (A, B, C) values (14, 23, 11);
insert into test (A, B, C) values (14, 22, 12);
insert into test (A, B, C) values (14, 54, 12);
insert into test (A, B, C) values (14, 66, 21);
commit;
declare
min_a number(5);
min_b number(5);
min_c number(5);
cursor cur is select rowid rowadd
from test
where rowid<>(select rowid
from (select rowid
from test
order by b asc)
where rownum=1);
begin
select * into min_a,min_b,min_c
from (select * from test order by b asc)
where rownum=1;
for rec in cur loop
update test set a=min_a,b=min_b,c=min_c
where rowid=rec.rowadd and a=min_a and b>min_b and c<min_c;
commit;
end loop;
end;
/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询