2008年12月23日星期二

prime number in PL/SQL pipelined functions

create or replace type ton is table of number
/
create or replace function divisors(p number)
return ton pipelined as begin
  for i in 2..p-1 loop
    if mod(p,i)=0 then pipe row(i); end if;
  end loop;
end;
/
create or replace function seq(p number)
return ton pipelined as begin
  for i in 1..p loop pipe row(i); end loop;
end;
/
select * from table(seq(10)) --序列
/
select * from table(divisors(10)) --求商
/
select * from table(seq(10)) where
  not exists (
    select * from table(divisors(column_value)) --没有商
  )
  and column_value!=1 --不是质数
/

没有评论: