###使用游標修改資料
####定義乙個游標,游標名稱為 mycursor
#####更新scott使用者中emp表中empno為7369的銷售額
-- created on 2015/11/30 by zhanw
declare
he emp%rowtype;
cursor mycursor(pid integer)is
select
*from emp where empno = pid for
update
;begin
open mycursor(
7369);
while
(true
)loop
fetch mycursor into he;
exit
when mycursor%notfound;
update emp set sal =
1111
where
current
of mycursor;
endloop
;end
;
-- created on 2015/11/30 by zhanw
declare
he emp%rowtype;
cursor mycursor(pid integer)is
select
*from emp where empno = pid for
update
;begin
open mycursor(
7369);
while
(true
)loop
fetch mycursor into he;
exit
when mycursor%notfound;
delete
from emp where
current
of mycursor;
endloop
;end
;
###注意:
delete語句一定要寫在exit後面,不然可能會報錯。####優化:
在定義游標時,可以在for update 後面新增 of 字段或者nowait。
Oracle使用游標批量更新表資料
oracle使用游標批量更新表資料 begin for jsc in select js.from sf jmmjjs t js,sf ebzcb t cb,sf jmyh t yh where js.yhbh cb.yhbh and js.mjbh cb.mjbh and js.cnq cb.cn...
Oracle使用游標
了解一下訪問資料庫的ddl和tcl語句 一。plsql中使用select語句,應該與into字句連用,查詢出的返回值賦予into子句中的變數 變數的宣告是在delcare中 二。type屬性 在plsql中可以將變數和常量宣告為內建或使用者定義的資料型別,以引用乙個列名,同時繼承他的資料型別和大小。...
Oracle中使用游標
游標 目的 為了處理select語句返回多行資料 使用步驟 1 定義游標 cursor cursor name is select statement 2 開啟游標 open cursor name 3 提取資料 fetch cursor name into variable1,提取一行資料 或fe...