DECLARE
   TYPE num_tt IS TABLE OF INT;
   num_t num_tt:=num_tt();
   PROCEDURE quick_sort(arr_t IN OUT num_tt, i IN INT, j IN INT)
   AS
      tmp_i INT := i;
      tmp_j INT := j;
      fir_num INT;
   BEGIN
      IF(i < j) THEN
       fir_num := arr_t(tmp_i);
       WHILE(tmp_i < tmp_j) LOOP
          WHILE(tmp_i < tmp_j AND fir_num < arr_t(tmp_j)) LOOP
             tmp_j := tmp_j - 1;
          END LOOP;
         
          arr_t(tmp_i) := arr_t(tmp_j);
          WHILE(tmp_i < tmp_j AND fir_num > arr_t(tmp_i)) LOOP
              tmp_i := tmp_i + 1;
          END LOOP;
          arr_t(tmp_j) := arr_t(tmp_i);
       END LOOP;
       arr_t(tmp_i) := fir_num; 
       quick_sort(arr_t, i, tmp_i-1);
       quick_sort(arr_t, tmp_i+1, j);
     END IF;
   END quick_sort;
BEGIN
   num_t.extend(20);
   FOR i IN 1..20 LOOP
     num_t(i) := trunc(dbms_random.value(200,100000));
   END LOOP;
   dbms_output.put_line('before sort:');
   FOR i IN 1..num_t.count LOOP
     dbms_output.put_line(num_t(i)||',');
   END LOOP;
   quick_sort(num_t, 1, num_t.count);
   dbms_output.put_line('after sort:');
   FOR i IN 1..num_t.count LOOP
     dbms_output.put_line(num_t(i)||',');
   END LOOP;
END;