无码视频在线观看,99人妻,国产午夜视频,久久久久国产一级毛片高清版新婚

  • 始創(chuàng)于2000年 股票代碼:831685
    咨詢熱線:0371-60135900 注冊有禮 登錄
    • 掛牌上市企業(yè)
    • 60秒人工響應(yīng)
    • 99.99%連通率
    • 7*24h人工
    • 故障100倍補(bǔ)償
    全部產(chǎn)品
    您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

    Oracle基本事務(wù)和ForAll執(zhí)行批量DML練習(xí)

    發(fā)布時(shí)間:  2012/8/26 15:29:48

    基本事務(wù)的使用:
    從賬戶一的余額中轉(zhuǎn)100到賬戶二的余額中去,如果賬戶二不存在或賬戶一中的余額不足100則整筆交易回滾


    Sql代碼
    1.select * from account;   
    2.-- 創(chuàng)建一張賬戶表   
    3.create table account(   
    4.       -- 賬戶ID   
    5.       id number(3) not null,   
    6.       -- 賬戶名稱   
    7.       name varchar2(50) not null,   
    8.       -- 賬戶余額   
    9.       balance number(8,2) not null,   
    10.       -- 開啟時(shí)間   
    11.       btime date not null  
    12.)   
    13.-- 插入數(shù)據(jù)   
    14.insert into account(id,name,balance,btime) values(1,'張三',2000.23,to_date('2008-02-12','yyyy-mm-dd'));   
    15.insert into account(id,name,balance,btime) values(2,'李四',530,to_date('2008-10-03','yyyy-mm-dd'));   
    16.insert into account(id,name,balance,btime) values(3,'王五',1620.2,to_date('2007-08-20','yyyy-mm-dd'));   
    17.insert into account(id,name,balance,btime) values(4,'小強(qiáng)',910.9,to_date('2009-01-23','yyyy-mm-dd'));   
    18.insert into account(id,name,balance,btime) values(5,'小周',8700,to_date('2006-09-10','yyyy-mm-dd'));   
    19.  
    20.declare  
    21.   -- 臨時(shí)保存賬戶一的余額總數(shù)   
    22.   v_balance account.balance%type;   
    23.begin  
    24.   update account set balance = balance - 100 where name = '&轉(zhuǎn)出賬號(hào):' returning balance into v_balance;   
    25.   if sql%notfound then  
    26.      raise_application_error(-20001,'轉(zhuǎn)出賬號(hào) 不存在!');   
    27.   end if;   
    28.   if v_balance < 0 then  
    29.      raise_application_error(-20002,'賬戶余額不足!');   
    30.   end if;   
    31.   update account set balance = balance + 100 where name = '&轉(zhuǎn)入賬號(hào):';   
    32.   if sql%notfound then  
    33.      raise_application_error(-20003,'轉(zhuǎn)入賬號(hào) 不存在!');   
    34.   end if;   
    35.   commit;   
    36.   dbms_output.put_line('轉(zhuǎn)賬成功!');   
    37.exception   
    38.   when others then rollback;   
    39.   dbms_output.put_line(sqlerrm);   
    40.end; 
     
    1.select * from account; 
    2.-- 創(chuàng)建一張賬戶表   3.create table account(  4.       -- 賬戶ID   5.       id number(3) not null,  6.       -- 賬戶名稱   7.       name varchar2(50) not null,  8.       -- 賬戶余額   9.       balance number(8,2) not null,  10.       -- 開啟時(shí)間   11.       btime date not null  12.) 
    13.-- 插入數(shù)據(jù)   14.insert into account(id,name,balance,btime) values(1,'張三',2000.23,to_date('2008-02-12','yyyy-mm-dd'));  15.insert into account(id,name,balance,btime) values(2,'李四',530,to_date('2008-10-03','yyyy-mm-dd'));  16.insert into account(id,name,balance,btime) values(3,'王五',1620.2,to_date('2007-08-20','yyyy-mm-dd'));  17.insert into account(id,name,balance,btime) values(4,'小強(qiáng)',910.9,to_date('2009-01-23','yyyy-mm-dd'));  18.insert into account(id,name,balance,btime) values(5,'小周',8700,to_date('2006-09-10','yyyy-mm-dd'));  19. 
    20.declare  21.   -- 臨時(shí)保存賬戶一的余額總數(shù)   22.   v_balance account.balance%type; 
    23.begin  24.   update account set balance = balance - 100 where name = '&轉(zhuǎn)出賬號(hào):' returning balance into v_balance;  25.   if sql%notfound then  26.      raise_application_error(-20001,'轉(zhuǎn)出賬號(hào) 不存在!');  27.   end if;  28.   if v_balance < 0 then  29.      raise_application_error(-20002,'賬戶余額不足!');  30.   end if;  31.   update account set balance = balance + 100 where name = '&轉(zhuǎn)入賬號(hào):';  32.   if sql%notfound then  33.      raise_application_error(-20003,'轉(zhuǎn)入賬號(hào) 不存在!');  34.   end if;  35.   commit;  36.   dbms_output.put_line('轉(zhuǎn)賬成功!');  37.exception 
    38.   when others then rollback;  39.   dbms_output.put_line(sqlerrm); 
    40.end;  使用ForAll執(zhí)行批量DML練習(xí):
    賬戶建立超過6個(gè)月的贈(zèng)送100,超過12個(gè)月的贈(zèng)送200,超過24個(gè)月的贈(zèng)送500,建立時(shí)間未過6個(gè)月的不贈(zèng)送

    Sql代碼
    1.declare  
    2.   -- 保存建立賬戶日期與當(dāng)前日期相差的份數(shù)   
    3.   v_monthbt number(5,2);   
    4.   type str_table_type is table of varchar2(50) index by binary_integer;   
    5.   type id_table_type is table of number(3) index by binary_integer;   
    6.   -- 賬戶名稱數(shù)組   
    7.   name_table str_table_type;   
    8.   -- 贈(zèng)送金額數(shù)組   
    9.   money_table str_table_type;   
    10.   -- 賬戶ID數(shù)組   
    11.   id_table id_table_type;   
    12.begin  
    13.   for i in 1..5 loop   
    14.       select months_between(sysdate,btime) into v_monthbt from account where id=i;   
    15.       if v_monthbt between 6 and 12 then  
    16.          money_table(i) := 100;   
    17.       elsif v_monthbt between 12 and 24 then  
    18.          money_table(i) := 200;   
    19.       elsif v_monthbt >= 24 then  
    20.          money_table(i) := 500;   
    21.       else  
    22.          money_table(i) := 0;   
    23.       end if;   
    24.       id_table(i) := i;   
    25.   end loop;   
    26.   -- 使用ForAll批量更新數(shù)據(jù)   
    27.   forall i in 1..money_table.count  
    28.      update account set balance = balance + money_table(i) where id = id_table(i) returning name bulk collect into name_table;   
    29.      for i in 1..name_table.count loop   
    30.          dbms_output.put_line(name_table(i));   
    31.      end loop;   
    32.   commit;   
    33.end;   
    34./ 
     
    1.declare 
    2.   -- 保存建立賬戶日期與當(dāng)前日期相差的份數(shù)   3.   v_monthbt number(5,2); 
    4.   type str_table_type is table of varchar2(50) index by binary_integer;  5.   type id_table_type is table of number(3) index by binary_integer;  6.   -- 賬戶名稱數(shù)組   7.   name_table str_table_type; 
    8.   -- 贈(zèng)送金額數(shù)組   9.   money_table str_table_type; 
    10.   -- 賬戶ID數(shù)組   11.   id_table id_table_type; 
    12.begin  13.   for i in 1..5 loop  14.       select months_between(sysdate,btime) into v_monthbt from account where id=i;  15.       if v_monthbt between 6 and 12 then  16.          money_table(i) := 100; 
    17.       elsif v_monthbt between 12 and 24 then  18.          money_table(i) := 200; 
    19.       elsif v_monthbt >= 24 then  20.          money_table(i) := 500; 
    21.       else  22.          money_table(i) := 0; 
    23.       end if;  24.       id_table(i) := i; 
    25.   end loop;  26.   -- 使用ForAll批量更新數(shù)據(jù)   27.   forall i in 1..money_table.count  28.      update account set balance = balance + money_table(i) where id = id_table(i) returning name bulk collect into name_table;  29.      for i in 1..name_table.count loop  30.          dbms_output.put_line(name_table(i)); 
    31.      end loop;  32.   commit;  33.end;  34./ 
     


    本文出自:億恩科技【mszdt.com】

    服務(wù)器租用/服務(wù)器托管中國五強(qiáng)!虛擬主機(jī)域名注冊頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話:0371-60135900
  • 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話:0371-60135900
  • 專注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號(hào)
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
      1
     
     
     
     

    0371-60135900
    7*24小時(shí)客服服務(wù)熱線