<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Decode360's Blog

    業精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評論 :: 0 Trackbacks
    關于并發問題的測試
    ?
    ??? 在論壇上看到有人討論并發的這個問題,因為平時主要是處理數據倉庫,所以對并發的問題一直沒有怎么注意,記錄一下:
    ?
    ?
    --第一段:
    create or replace procedure Delete_Pno(v_Pno varchar2) is
    ? v_state varchar2(20);
    begin
    ? begin
    ??? select state into v_state from P_Table where Pno = v_Pno;
    ? exception
    ??? when no_data_found then
    ????? dbms_output.put_line('Pno:' || v_Pno || 'not exists.');
    ????? return;
    ? end;
    ? if v_state = 'N' then
    ??? delete from P_Table where Pno = v_Pno;
    ??? dbms_output.put_line('Pno:' || v_Pno || 'delete success.');
    ? else
    ??? dbms_output.put_line('Pno:' || v_Pno || 'has been checked.');
    ? end if;
    commit;
    exception
    ? when others then
    ??? rollback;
    end;
    -- 如果在 select state into v_state 之后,如果發生了狀態變化,或者單證刪除,都會發生并發性錯誤。
    --需要在select into 語句后面加上forupdate,這樣就可以鎖住該信息而防止其被修改或刪除。
    ?
    ?
    --第二段:
    create or replace procedure Delete_Pno(v_Pno varchar2) is
    ? v_state varchar2(20);
    begin
    ? delete from P_Table
    ?? where Pno = v_Pno
    ???? and state = 'N';
    ? if sql%rowcount > 0 then
    ??? dbms_output.put_line('Pno:' || v_Pno || 'delete success.');
    ? else
    ??? begin
    ????? select state into v_state from P_Table where Pno = v_Pno;
    ??? exception
    ????? when no_data_found then
    ??????? dbms_output.put_line('Pno:' || v_Pno || 'not exists.');
    ??????? return;
    ??? end;
    ??? dbms_output.put_line('Pno:' || v_Pno || 'has been checked.');
    ? end if;
    commit;
    exception
    ? when others then
    ??? rollback;
    end;
    --先刪除必然需要刪除的,然后再判斷是不存在還是無需刪除,這樣不會出現并發錯誤。
    ?
    ?
    --第三段
    create or replace procedure Delete_Pno(v_Pno varchar2) is
    ? v_state varchar2(20);
    begin
    ? delete from P_Table where Pno = v_Pno returning state into v_state;
    ? if sql%rowcount > 0 then
    ??? if v_state = 'N' then
    ????? dbms_output.put_line('Pno:' || v_Pno || 'delete success.');
    ??? else
    ????? rollback;
    ????? dbms_output.put_line('Pno:' || v_Pno || 'has been checked.');
    ????? return;
    ??? end if;
    ? else
    ??? dbms_output.put_line('Pno:' || v_Pno || 'not exists.');
    ? end if;
    commit;
    exception
    ? when others then
    ??? rollback;
    end;
    --用returning返回狀態,如果狀態是'N'則刪除,否則回滾,這樣也不會有并發的問題。
    ?
    ?
    ?
    ??? 要注意delete from P_Table where Pno = v_Pno returning state into v_state;語句屬于OUT BIND
    ??? 就好比是update ... set () = (select ...) 一樣,語句和自己的子句之間,是不會造成并發的不一致性的。
    ?
    ?
    posted on 2009-01-30 22:22 decode360 閱讀(139) 評論(0)  編輯  收藏 所屬分類: 06.PLSQL
    主站蜘蛛池模板: 久久久高清免费视频| 91大神免费观看| 国产免费人成视频在线观看| 亚洲国产日韩精品| 久久久www成人免费毛片| 亚洲国产精品午夜电影| 久久久久av无码免费网| 亚洲国产成+人+综合| 免费观看黄网站在线播放| 亚洲日韩精品无码专区加勒比☆| 成人毛片免费播放| 亚洲成在人线在线播放无码 | 亚洲av无码天堂一区二区三区| 亚洲精品永久在线观看| 免费观看午夜在线欧差毛片| 国产亚洲高清在线精品不卡| 免费二级毛片免费完整视频| 国产黄在线观看免费观看不卡| 亚洲精品无码久久久久去q| 国产精品免费看久久久 | 亚洲韩国在线一卡二卡| 国产乱码免费卡1卡二卡3卡| 亚洲成在人线在线播放无码| 国产亚洲自拍一区| 四虎成人精品永久免费AV| 亚洲人成人77777网站不卡| 四虎成人免费大片在线| eeuss草民免费| 亚洲日本香蕉视频| 免费一级特黄特色大片在线观看| www免费黄色网| 亚洲日本在线播放| 免费a级毛片大学生免费观看| 黄色短视频免费看| 亚洲人成网站在线观看播放动漫| 免费亚洲视频在线观看| 黄网站免费在线观看| 亚洲欧美国产国产综合一区 | 亚洲国产成人久久笫一页| 久久免费国产视频| 亚洲av纯肉无码精品动漫|