我需要帮助创建一个存储过程,该过程允许用户输入随机数列表,然后使用冒泡排序算法对它们进行排序。我对编程和 PL/SQL 都很陌生。任何帮助将非常感激。
以下是我到目前为止的代码行:
CREATE OR REPLACE PROCEDURE test_BubbleSort (i_number IN number) AS
type l_array_type IS TABLE OF NUMBER(10);
l_temp NUMBER;
l_array l_array_type := l_array_type();
BEGIN
--Loop through numbers and re-arrange their order using bubble sort---
FOR i in 1 .. l_array.Count - 1 LOOP
FOR j IN 2 .. l_array.Count LOOP
IF l_array(j) > l_array(j - 1) THEN
l_temp := l_array(j - 1);
l_array(j - 1) := l_array(j);
l_array(j) := l_temp;
END IF;
END LOOP;
END LOOP;
--Print the newly sorted numbers user inputs
FOR i in REVERSE 1 .. l_array.COUNT LOOP
dbms_output.put_line('The new sorted numbers are: ' || l_array(i));
END LOOP;
END;