我想用PL / SQL计算素数。我从以前的帖子修改过 Get Prime Number records in Oracle using ROWNUM
这是我的代码:
CREATE OR REPLACE PROCEDURE FindBP(pHigh NUMBER) IS
non BOOLEAN;
Begin
FOR p IN 2..pHigh
LOOP non := true;
with t as(select level l from dual connect by level <= pHigh)
if(
p in
(select l from (select * from t
model
dimension by (l dim)
measures (l,2 temp)
rules iterate (1000000)
until (power(temp[1],2)>100)
(l[DIM>TEMP[1]]=decode(mod(l[CV()],temp[1]),0,null,l[CV()]),
temp[1]=min(l)[dim>temp[1]])
) where l is not NULL)
then non := FALSE; end if;
IF (NOT non)
THEN INSERT INTO N VALUES (p);
END IF;
END LOOP;
END;
但是,我发现with_clause可能不起作用,所以我尝试使用下面的sql:
CREATE OR REPLACE PROCEDURE FindBP(pHigh NUMBER) IS
non BOOLEAN;
Begin
FOR p IN 2..pHigh
LOOP non := true;
If( p in (select * from (select level l from dual connect by level<=pHigh) t
model
dimension by (l dim)
measures (l,2 temp)
rules iterate (1000000) until (power(temp[1],2)>100)
(l[DIM>TEMP[1]]=decode(mod(l[CV()],temp[1]),0,null,l[CV()]),
temp[1]=min(l)[dim>temp[1]])
) then non := FALSE; end if;
IF (NOT non)
THEN INSERT INTO N VALUES (p);
END IF;
END LOOP;
END;
他们都没有通过编译。有什么好主意吗? 对于第一个,我收到了错误
error(7,1): PL/SQL: SQL Statement ignored
对于第二个,我得到了
error(8,8): PLS-00103: "MODEL" , with group having intersect minus start union where connect