oracle中的数组排序Sql代码
CREATE OR REPLACE TYPE typ_arr AS TABLE OF INTEGER;
DECLARE
v_arr typ_arr := typ_arr(10, 12, 6, 9, 15, 15, 8, 14, 8, 6, 7, 19, 10);
v_arr_sort typ_arr;
kk integer := 0;
tt integer := 9;
tmp integer := 0;
BEGIN
select cast(multiset(
select * from table(v_arr)
order by 1) as typ_arr)
into v_arr_sort from dual;
for i_idx in v_arr_sort.first..v_arr_sort.last
loop
tmp := v_arr_sort.last - i_idx + 1;
if tt=v_arr_sort(tmp) then
dbms_output.put_line(kk+1);
return;
end if;
if i_idx >= v_arr_sort.last then
return;
end if;
kk := kk+1;
if v_arr_sort(tmp) = v_arr_sort(tmp-1) then
kk := kk-1;
end if;
end loop;
END;
/