當前位置:首頁 » 存儲配置 » oracle存儲過程循環插入

oracle存儲過程循環插入

發布時間: 2022-11-26 23:22:50

⑴ oracle存儲過程用fetch循環實現向一張表中插入不同數據

創建測試表

sql">createtabletest
(touch_idvarchar2(20),
party_idvarchar2(20));

執行過程

declare
v_idint;
begin
v_id:=1;
whilev_id<=10--這個10設置為插入的次數
loop
insertintotestvalues('張三'||v_id,'partyid'||v_id);
v_id:=v_id+1;
endloop;
commit;
end;

結果

⑵ 寫一段創建oracle存儲過程的代碼,並將1至10個數循環插入表A(ID,NAME)的NAME欄位

v_name integer;
begin
v_name:=1;
while v_name<=10 loop
begin
insert into table(id,name) values(seq.nextval,v_name);
v_name=v_name+1;
end;
end loop;
===========
主題程序就是這樣。

⑶ oracle循環存儲過程方法怎麼寫,每條數據不一樣

方法1:用游標可以解決呀!給你個例子。
FOR c IN (SELECT DISTINCT wdd.organization_id,
wdd.ship_from_location_id,
wdd.ship_to_location_id,
wdd.customer_id,
wdd.freight_terms_code,
wdd.fob_code,
wdd.source_header_id,
wdd.source_header_type_id
FROM wsh_delivery_details wdd
WHERE wdd.released_status IN ('R', 'B')
AND wdd.inventory_item_id IN
(SELECT DISTINCT mln.inventory_item_id
FROM bs_edi_shipment_ge bes,
mtl_lot_numbers_all_v mln
WHERE mln.lot_number = bes.lot_number
AND bes.header_id = l_header_id)) LOOP
INSERT INTO Document VALUES(c.organization_id,
c.ship_from_location_id,
c.ship_to_location_id,
c.customer_id,
c.freight_terms_code,
c.fob_code,
c.source_header_id,
c.source_header_type_id);
END LOOP;
將游標裡面的數據一條一條的插入到你想插入到的表。

方法2:還有一種方法,定義一個表類型的記錄,將所有數據插入到這個表類型記錄集中,然後再一次性插入到表中。

⑷ oracle 存儲過程循環插入數據不定時出現卡死,求高手指點,循環過程如下:

感覺對日期的處理問題,你將日期類型轉換為字元串類型再比較,這里不建議轉,直接比較吧。

⑸ oracle存儲過程游標問題,多層循環游標,插入中間表

以hr用戶下的employees、departments、locations這三張表為列,sin1得到的是雇員的全名和對應的部門id,並將該部門的id作為sin2查詢時的條件,sin2得到的是該部門id所對應的部門名和對應的位置id,並將該位置id作為sin3查詢使得條件,最後sin3得到的就是該位置id所應得城市,並且在sin3這個循環里將sin1里雇員的全名,sin2里的部門名以及sin3里的city作為一條記錄插入到sin_insert表裡.
附上代碼:
first:
create table sin_insert(full_name varchar2(50),department_name varchar2(30),city
varchar2(30));

then:
create or replace procere testloop
as
begin
for sin1 in (select first_name||last_name full_name,department_id from
employees) loop
for sin2 in (select department_name,location_id from departments where
department_id=sin1.department_id) loop
for sin3 in (select city from locations where
location_id=sin2.location_id) loop
insert into sin_insert values
(sin1.full_name,sin2.department_name,sin3.city);
end loop;
end loop;
end loop;
end;

⑹ oracle存儲過程循環插數據

有以下幾個步驟。
在表account中循環插入數據,id從1001到1005。createor
replace
procere
test
is--存儲過程,名稱為test。v_id
int;
--聲明變數。begin。v_id
:=1001;
--ACCOUNT_ID從1001插到1005。while
v_id
<=1005--設置插入的次數。loop。

⑺ oracle存儲過程循環執行SQL語句

實現方式錯了,批量移動數據應該使用Cursor,而不是像分頁那樣每次都查詢。
每次都查詢可能會導致重復數據。
正確方式應該是打開一個Cursor,循環Cursor來插入,使用計數器來控制每次COMMIT的行數:
declare
TYPE R_CURSOR IS REF CURSOR;
i number;
a1_cursor R_CURSOR;
a1_row A1%ROWTYPE;
begin
open a1_cursor FOR
select ID, NAME from A1;
i := 0;
loop
fetch a1_cursor
into a1_row;
exit when a1_cursor%notfound;
INSERT INTO A2 VALUES a1_row;
i := i + 1;
if i >= 5 then
commit;
i := 0;
end if;
end loop;
close a1_cursor;
commit;
end;

⑻ oracle 用存儲過程向表插入數據的問題

實際上存儲過程向表中插入數據和sql執行的區別是不大的,只不過是存儲過程是用loop等循環插入,之後順序執行sql語句,不用命令行執行。

_data_4_pressure_3
is

--Result1VARCHAR2(50);
VAR_numnumber;
begin
VAR_num:=1;

while
VAR_num<1000000
LOOP
insertintorp_trans_log_day
(trans_time,
trans_province,
trans_type,
score_range,
rule_name,
trans_num)
selectto_date('2013/10/29','yyyy-mm-dd'),
round(dbms_random.value(1,300))||'省',
round(dbms_random.value(1,800))||'類型',
round(dbms_random.value(1,100))||'風險分值',
round(dbms_random.value(1,300))||'規則名稱',
'1'
fromal;
commit;
VAR_num:=VAR_num+1;
<ahref="https://www..com/s?wd=end&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"target="_blank"class="-highlight">end</a>loop;

<ahref="https://www..com/s?wd=end&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"target="_blank"class="-highlight">end</a>insert_data_4_pressure_3;

⑼ oracle存儲過程中循環for in是如何使用的

1、首先編寫存儲過程的整體結構,如下圖所示定義變數。

⑽ oracle存儲過程循環怎麼寫

Oracle中有三種循環(For、While、Loop):
1、loop循環:

createorreplaceprocerepro_test_loopis
inumber;
begin
i:=0;
loop
i:=i+1;
dbms_output.put_line(i);
ifi>5then
exit;
endif;
endloop;
endpro_test_loop;


2、while循環:

createorreplaceprocerepro_test_loopis
inumber;
begin
i:=0;
whilei<5loop
i:=i+1;
dbms_output.put_line(i);
endloop;
endpro_test_loop;


3、for循環1:

createorreplaceprocerepro_test_foris
inumber;
begin
i:=0;
foriin1..5loop
dbms_output.put_line(i);
endloop;
endpro_test_for;

4、for循環2:

createorreplaceprocerepro_test_cursoris
userRowt_user%rowtype;
cursoruserRowsis
select*fromt_user;
begin
foruserRowinuserRowsloop
dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);
endloop;
endpro_test_cursor;
熱點內容
如何進入安卓的強制系統 發布:2025-07-27 21:04:08 瀏覽:259
壓縮狀羽絨 發布:2025-07-27 20:54:10 瀏覽:510
手機為什麼設置了密碼會自動解鎖 發布:2025-07-27 20:36:24 瀏覽:642
看自己家wifi密碼是多少錢 發布:2025-07-27 20:33:21 瀏覽:81
最大公約數的演算法 發布:2025-07-27 20:31:19 瀏覽:162
下載時有上傳速度 發布:2025-07-27 20:25:26 瀏覽:726
編程無邏輯 發布:2025-07-27 20:24:51 瀏覽:358
python字元串替換正則 發布:2025-07-27 20:19:45 瀏覽:305
linux如何編譯安裝程序 發布:2025-07-27 20:17:55 瀏覽:435
安卓如何打開nc格式文件 發布:2025-07-27 19:47:45 瀏覽:356