列出1 100的所有質數的兩種方法

2022-08-24 16:18:14 字數 1734 閱讀 4672

方法一

用dbms_output.put_line 列印出來

--

-列印1-100以內的質數(素數)

declare

v_number

number

; v_temp

number

;begin

for v_number in

1 .. 100

loop

v_temp :=1

; while v_temp <

v_number loop

v_temp :

= v_temp +

1;  --加1放在這裡才能保證不被後面exit剔除哦

if v_temp = v_number then      

dbms_output.put_line(v_number); --只有沒有被任何數整除才會來到這一步

endif

;

if mod(v_number, v_temp) =

0then --如被比自身小的數整除,則不是質數(素數),退出迴圈,否則,繼續走到等於本身

exit

;

endif

;

endloop;

endloop;

end ;

方法二建立**,出入表中

create

table

t_table

( prime

number

)tablespace system --不指定表空間則自動使用這個表空間

pctfree

10pctused

40initrans

1maxtrans

255storage

( initial 64k

next

1m minextents

1maxextents unlimited

);

create

orreplace

procedure p_prime is

--integer整數型別

begin

delete

from

t_table;

delete

from

t_temp_table;

commit;

for a in

1 .. 100

loop

insert

into t_temp_table (temp_prime) values

(a);

endloop;

insert

into

t_table

select

*from

t_temp_table t

where

notexists (select

*from

t_temp_table t1, t_temp_table t2

where t1.temp_prime * t2.temp_prime =

t.temp_prime

and t1.temp_prime <>

1and t2.temp_prime <>1)

and t.temp_prime !=1;

commit

;end p_prime;

兩種獲取Oracle Sequence的方法

前提 create table booking id integer not null,date made date,reserved until timestamp,price decimal 15,2 not null,purchase id integer,primary key id cre...

兩種禁止USB autosuspend的方法

在有些情況下,由於低功耗情況下,usb硬體的bug或者提高usb resume的速度,我們需要禁止usb的 autosuspend,下面是兩種方法。1 在bootloader的bootargs裡加上 usbcore.autosuspend 1 2 檔案系統起來後,執行如下命令,disable掉run...

fabric ca server的兩種啟動方式

一 本地啟動 fabric ca server start b admin adminpw b選項為管理員提供註冊id和密碼 如果未使用 ldap.enabled 設定啟用ldap,則必須執行此操作。在本地目錄中會建立名為fabric ca server config.yaml的預設配置檔案,該檔案...