游標修改和刪除操作

2021-12-30 02:45:05 字數 1008 閱讀 2201

游標修改和刪除操作是指在游標定位下,修改或刪除表中指定的資料行。這時,要求游標查詢語句中必須使用for update選項,以便在開啟游標時鎖定游標結果集合在表中對應資料行的所有列和部分列。

為了對正在處理(查詢)的行不被另外的使用者改動,oracle 提供乙個 for update 子句來對所選擇的行進行鎖住。該需求迫使oracle鎖定游標結果集合的行,可以防止其他事務處理更新或刪除相同的行,直到您的事務處理提交或回退為止。

語法:select . . . from … for update [of column[, column]…] [nowait]

如果另乙個會話已對活動集中的行加了鎖,那麼select for update操作一直等待到其它的會話釋放這些鎖後才繼續自己的操作,對於這種情況,當加上nowait子句時,如果這些行真的被另乙個會話鎖定,則open立即返回並給出:

ora-0054 :resource busy and acquire with nowait specified.

如果使用 for update 宣告游標,則可在delete和update 語句中使用where current of cursor_name子句,修改或刪除游標結果集合當前行對應的資料庫表中的資料行。

如:從emp表中查詢某部門的員工情況,將其工資最低定為 1500;

declare

v_deptno emp.deptno%type :=&p_deptno;

cursor emp_cursor is select empno, sal

from emp where deptno=v_deptno for update of sal nowait;

for emp_record in emp_cursor loop

if emp_record.sal < 1500 then

update emp set sal=1500 where current of emp_cursor;

end if;

end loop;

-- commit;

end;

游標資料修改和游標變數

修改游標資料 如果建立的游標需要執行更新或者刪除必須帶有for update子句,for update子句會將游標提取出來的資料進行行級鎖定,這樣在本會話更新期間,其他使用者的會話就不能對當前游標中的資料進行更新操作,for update有如下兩種形式 for update of 列,列.為游標中的...

修改EditText背景和游標

安卓原生的edittext樣式不太好看 游標和背景 不同的專案都需要定製。2 styles.xml中修改coloraccent對應顏色即可。color colorprimarydark color coloraccent 效果圖 次選方案 如果不能修改主題,要單獨定製某個edittext的游標和背景...

修改和刪除

1.0 對資料庫的修改 刪除語句為 drop database 表名稱 2.0 對一張表的修改 2.1 重新命名一張表 rename table 原名 to 新名字 alter table 原名 rename 新名 alter table 原名 rename to 新名 2.2 刪除一張表 drop...