如何实现类似于冒泡排序的函数
发布网友
发布时间:2022-07-15 17:32
我来回答
共1个回答
热心网友
时间:2024-12-04 05:28
DECLARE
type type_tt is varray(1000) of varchar2(100);
var type_tt := type_tt('b','a','c','c','a');
temp varchar2(100);
flag boolean;
BEGIN
<<outer_scope>>
for i in 1 .. var.count-1 loop
flag := false;
for j in reverse i .. var.count-1 loop
if var(j+1) < var(j) then
temp := var(j+1);
var(j+1) := var(j);
var(j) := temp;
flag := true;
end if;
end loop;
if (not flag) then
exit outer_scope;
end if;
end loop;
for i in var.first .. var.last loop
dbms_output.put_line(var(i));
end loop;
END;
/