PL / SQL到PostgreSQL的转换

时间:2016-04-26 15:28:05

标签: postgresql plsql

请帮我把这个PL / SQL转换成PostgreSQL。非常感谢你。

Prime数字

CREATE TABLE n (n NUMBER);<br/>
CREATE OR REPLACE PROCEDURE prime_number (n NUMBER)<br/> 
IS <br/>
prime_count   NUMBER       := 0;<br/>
y             VARCHAR2 (1) := 'N';<br/>
BEGIN<br/>
IF n >= 1
THEN
  prime_count := 1;

  INSERT INTO n
       VALUES (2);
END IF;

IF n >= 2
THEN
  prime_count := 2;

  INSERT INTO n
       VALUES (2);
END IF;

IF n >= 3
THEN
  FOR i IN 4 .. n * n * n
  LOOP
     y := 'N';

     FOR j IN 2 .. CEIL (SQRT (i))
     LOOP
        IF (MOD (i, j) = 0)
        THEN
           y := 'Y';
           EXIT;
        END IF;
     END LOOP;

     IF (y = 'N')
     THEN
        INSERT INTO n
             VALUES (i);

        COMMIT;
        prime_count := prime_count + 1;
        EXIT WHEN prime_count = n;
     END IF;
  END LOOP;
END IF;<br/>
END;


BEGIN<br/>
   prime_number (1000000);<br/>
END;

0 个答案:

没有答案