十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
Oracle是支持For語法的,只是跟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)營銷網(wǎng)站建設(shè)要多少錢,請找那個(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;
寫循環(huán)的操作方法和步驟如下:
1、第一步,編寫存儲(chǔ)過程的整體結(jié)構(gòu),然后定義變量,見下圖。
2、其次,完成上述步驟后,在定義變量后定義游標(biāo),begin,select sysdate into v_date from dual,end test_proc,如下圖所示。
3、接著,完成上述步驟后,寫一個(gè)for循環(huán),游標(biāo)開始for循環(huán),為臨時(shí)變量名任意起個(gè)名,輸出一個(gè)字段,使用變量名.列名就好了,最后游標(biāo)for循環(huán)就結(jié)束了,如下圖所示。
4、最后,完成上述步驟后,試運(yùn)行,單擊“
DBMS Output”選項(xiàng)卡進(jìn)行檢查,運(yùn)行成功,見下圖。這樣,問題就解決了。
寫大了我這也沒事啊,剛測試了一下
create table orders (id int);
CREATE SEQUENCE seq_orders
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10;
存儲(chǔ)過程就是你的那個(gè),是不是你序列建的有問題啊
--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;
語法是這樣的,具體字段自己改一下,看你要做什么樣的操作了但如果是這種插入到一張表邏輯過于簡單,可以直接用等值連接。