• + 0 comments

    SET SERVEROUTPUT ON; DECLARE prime_ls SYS.ODCIVARCHAR2LIST := SYS.ODCIVARCHAR2LIST(); is_prime BOOLEAN; rst_str VARCHAR2(4000) := ''; BEGIN FOR i IN 2..1000 LOOP is_prime := TRUE; FOR J IN 2..FLOOR(SQRT(i)) LOOP IF MOD(i, j) = 0 THEN is_prime := false; exit; END IF; END LOOP; IF is_prime THEN prime_ls.EXTEND; prime_ls(prime_ls.LAST) := TO_CHAR(i); END IF; END LOOP; FOR idx in 1..prime_ls.COUNT LOOP IF idx > 1 THEN rst_str := rst_str || '&'; END IF; rst_str := rst_str || prime_ls(idx); END LOOP; DBMS_OUTPUT.PUT_LINE(rst_str); END; /