有一个表t_org(id int primary key,
m1 int,
m2 int,
m3 int,
m4 int,
m5 int);
另外一个临时表t_temp与t_org结构一致。
现在要比较输出t_org表中两两记录之间列相同个数(id除外),比如3个相同的记录。
t_org表中初始数据如下:
(001,1,2,3,4,5);
(002,2,2,3,4,5);
(003,1,3,3,4,6);
(004,1,4,7,8,5);
(005,5,3,3,4,5);
从第一条记录开始遍历,将两两之间列(id除外)相同的记录插入t_temp,并将每两个相同记录隔开,得到如下记录:
(001,1,2,3,4,5);
(002,2,2,3,4,5);
(888,null,null,null,null,null);--一律用此记录分隔
(001,1,2,3,4,5);
(003,1,3,3,4,6);
(888,null,null,null,null,null);
(002,2,2,3,4,5);
(005,5,3,3,4,5);
(888,null,null,null,null,null);
(003,1,3,3,4,6);
(005,5,3,3,4,5);
(888,null,null,null,null,null);
再用Sys_Refcursor取结果集,但取的结果集并不是严格按照比较插入的顺序输出的。
若要达到理想输出结果,怎样排序?
欢迎前来解惑,甚谢!
|