Oracle是支持For語(yǔ)法的,只是跟java里面的有點(diǎn)差異 while 改為 FOr

會(huì)同網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,會(huì)同網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為會(huì)同成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè)要多少錢(qián),請(qǐng)找那個(gè)售后服務(wù)好的會(huì)同做網(wǎng)站的公司定做!
for i in 1..10 loop
for i in 1..10 loop
dbms_output.put_line(to_char(i)||to_char(n));
end loop;
end loop;
寫(xiě)循環(huán)的操作方法和步驟如下:
1、第一步,編寫(xiě)存儲(chǔ)過(guò)程的整體結(jié)構(gòu),然后定義變量,見(jiàn)下圖。
2、其次,完成上述步驟后,在定義變量后定義游標(biāo),begin,select sysdate into v_date from dual,end test_proc,如下圖所示。
3、接著,完成上述步驟后,寫(xiě)一個(gè)for循環(huán),游標(biāo)開(kāi)始for循環(huán),為臨時(shí)變量名任意起個(gè)名,輸出一個(gè)字段,使用變量名.列名就好了,最后游標(biāo)for循環(huán)就結(jié)束了,如下圖所示。
4、最后,完成上述步驟后,試運(yùn)行,單擊“
DBMS Output”選項(xiàng)卡進(jìn)行檢查,運(yùn)行成功,見(jiàn)下圖。這樣,問(wèn)題就解決了。
寫(xiě)大了我這也沒(méi)事啊,剛測(cè)試了一下
create table orders (id int);
CREATE SEQUENCE seq_orders
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10;
存儲(chǔ)過(guò)程就是你的那個(gè),是不是你序列建的有問(wèn)題啊
--while循環(huán)
procedure loop_while
(
start_value in number,
end_value in number
)
is
current_value number := start_value;
begin
while current_value =end_value
loop
dbms_output.put_line('now number:' || current_value);
current_value:=current_value+1;
end loop;
end loop_while;
create?or?replace?procedure?test_procedure?is
--a表游標(biāo)定義
cursor?a_cursor?is
select?id?from?a;
--b表游標(biāo)定義
cursor?b_cursor(aid?number)?is
select?id?from?b?where?b.id?=?aid;
begin
for?a_cur?in?a_cursor?loop
for?b_cur?in?b_cursor(a_cur.id)?loop
--這里是你要執(zhí)行的操作,比如insert到c
insert?into?c?values?(b_cur.id);
commit;
end?loop;
end?loop;
語(yǔ)法是這樣的,具體字段自己改一下,看你要做什么樣的操作了但如果是這種插入到一張表邏輯過(guò)于簡(jiǎn)單,可以直接用等值連接。
當(dāng)前文章:oracle如何雙層循環(huán),oracle存儲(chǔ)過(guò)程雙層循環(huán)
本文URL:http://chinadenli.net/article27/dsedocj.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開(kāi)發(fā)、關(guān)鍵詞優(yōu)化、用戶(hù)體驗(yàn)、網(wǎng)站改版、商城網(wǎng)站、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)