日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

oracle pl/sql编程详解,OraclePL/SQL高级编程详解

發布時間:2023/12/2 数据库 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle pl/sql编程详解,OraclePL/SQL高级编程详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

–創建一個表,此表作為子表

create table fk_t as select *from user_objects;

delete from fk_t where object_id is null;

commit;

–創建一個表,此表作為父表

create table pk_t as select *from user_objects;

delete from pk_t where object_id is null;

commit;

–創建父表的主鍵

alter table PK_t add constraintpk_pktable primary key (OBJECT_ID);

–創建子表的外鍵

alter table FK_t addconstraint fk_fktable foreign key (OBJECT_ID) references pk_t (OBJECT_ID);

–session1:執行一個刪除操作,這時候在子表和父表上都加了一個Row-S(SX)鎖

delete from fk_t whereobject_id=100;

delete from pk_t where object_id=100;

–session2:執行另一個刪除操作,發現這時候第二個刪除語句等待

delete from fk_t whereobject_id=200;

delete from pk_t whereobject_id=200;

–回到session1:死鎖馬上發生

delete from pk_t whereobject_id=100;

session2中報錯:

SQL> delete from pk_table where object_id=200;

delete from pk_table where object_id=200

*

第 1 行出現錯誤:

ORA-00060: 等待資源時檢測到死鎖

當對子表的外鍵列添加索引后,死鎖被消除,因為這時刪除父表記錄不需要對子表加表級鎖。

–為外鍵建立索引

create index ind_pk_object_id on fk_t(object_id) nologging;

–重復上面的操作session1

delete from fk_t whereobject_id=100;

delete from pk_t whereobject_id=100;

–session2

delete from fk_t whereobject_id=200;

delete from pk_t whereobject_id=200;

–回到session1不會發生死鎖

delete from pk_t whereobject_id=100;

總結

以上是生活随笔為你收集整理的oracle pl/sql编程详解,OraclePL/SQL高级编程详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。