久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    oracle觸發器中定義變量

     jp乞巧樓 2015-08-26
    ----------------------------------------------------------
    --每進行一次交易,就要調用觸發器,自動扣除或增加賬戶金額
    ----------------------------------------------------------
    create table account
    (
      customerName varchar2(30) primary key,
      cardID varchar2(8),
      currentMoney number
    );
    insert into account values('Daivd','10010001',5000);
    insert into account values('Jason','10010002',3000);
    
    create table trans
    (
      transDate date,
      cardID varchar2(8),
      transType varchar2(10),
      transMoney number
    );
    insert into trans 
    values(sysdate,'10010001','取款',1000);
    
    create or replace trigger trans_trigger
    before insert
    on trans
    for each row
    declare
      v_currentMoney account.currentMoney%type;
    begin
      --判斷類型
      if :new.transType='取款' then
       --取款
       select currentMoney into v_currentMoney
       from account
       where cardID=:new.cardID;
       
       if v_currentMoney < :new.transMoney then
         raise_application_error(-20001,'余額不足');
       end if;
       
       update account
       set currentMoney=currentMoney-:new.transMoney
       where cardID=:new.cardID;
      else
       --存款
       update account
       set currentMoney=currentMoney+:new.transMoney
       where cardID=:new.cardID;
      end if;
    exception  
      when no_data_found then
        raise_application_error(-20002,'無效的帳戶');
    end;
    
    
    --模式(schema)級觸發器
    create or replace trigger schema_trigger
    before drop
    on schema
    begin
      dbms_output.put_line('schema_trigger called');
      dbms_output.put_line(ora_dict_obj_name);
      dbms_output.put_line(ora_dict_obj_type);
      
      if ora_dict_obj_name='ACCOUNT' then
        raise_application_error(-20003,'ACCOUNT表不能被刪除');
      end if;
    end;
    
    drop table account;
    --ora_dict_obj_name 操作對象名稱
    --ora_dict_obj_type 操作對象類型
    
    --啟用觸發器
    alter trigger schema_trigger enable;
    --禁用觸發器
    alter trigger schema_trigger disable;
    
    
    -------------------------自己寫的-------------------
    -----------------------測試表---------------------
    create table Test
    (
    iKey int,
    iValue int,
    primary key(iKey)
    );
    create table Test_Log
    (
    iKey int,
    iClass varchar(4)
    );
    create trigger Test_Tri after insert on Test
    for each row
    begin
       if :new.iValue>90 then
       insert into Test_log values(:new.iKey,1);
       end if;
    end;
    
    insert into Test values(12,120);
    insert into Test values(18,60);
    insert into Test values(10,90);

      本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發現有害或侵權內容,請點擊一鍵舉報。
      轉藏 分享 獻花(0

      0條評論

      發表

      請遵守用戶 評論公約

      類似文章 更多

      主站蜘蛛池模板: 粗大的内捧猛烈进出小视频| 真实国产熟睡乱子伦视频| 久久精品手机观看| 在线观看AV永久免费| 亚洲成A人一区二区三区| 久久99热只有频精品8| 久久伊人精品青青草原APP | 偷炮少妇宾馆半推半就激情| 天天在线看无码AV片| 成人3D动漫一区二区三区| 一本色道久久88亚洲精品综合| 国产一区二区高清不卡| 精品国产午夜福利在线观看| 国产一区在线播放av| 久久一日本道色综合久久| 国产一区二区三区不卡AV| 午夜DY888国产精品影院| 久久综合亚洲色HEZYO国产| 疯狂做受XXXX高潮国产| 夜夜爽一区二区三区精品| 成人啪精品视频网站午夜| 日日碰狠狠添天天爽无码| 亚洲欧洲日产国无高清码图片| 色综合久久久久综合体桃花网| 亚洲精品在线二区三区| 无翼乌工口肉肉无遮挡无码18 | 亚洲欧洲自拍拍偷午夜色无码| 久久精品蜜芽亚洲国产AV| 五月丁香啪啪| 18禁美女裸体爆乳无遮挡| 国产影片AV级毛片特别刺激| 国产激情视频在线观看的| 亚洲最大成人网色| 亚洲日韩性欧美中文字幕| 一区二区三区精品视频免费播放| 伊人久久精品无码麻豆一区| 黄又色又污又爽又高潮| 无码国内精品久久人妻蜜桃| 日日摸夜夜添狠狠添欧美| 亚欧美日韩香蕉在线播放视频| 在线中文字幕国产精品|