激情五月天婷婷,亚洲愉拍一区二区三区,日韩视频一区,a√天堂中文官网8

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

        Oracle 10g中存儲(chǔ)過程中使用游標(biāo)

        發(fā)布時(shí)間:  2012/9/19 17:17:28

        實(shí)例設(shè)計(jì)

            1. 功能設(shè)計(jì)
            某高校開發(fā)的研究生招生系統(tǒng),要求設(shè)計(jì)PL/SQL程序?qū)忌某煽償?shù)據(jù)進(jìn)行處理,處理的邏輯是根據(jù)每門專業(yè)課的最低分?jǐn)?shù)線和總分的最低分?jǐn)?shù)線自動(dòng)將考生歸類為錄取考生、調(diào)劑考生和落選考生。
            為此設(shè)計(jì)兩個(gè)數(shù)據(jù)表,graduate數(shù)據(jù)表存放考生成績,result數(shù)據(jù)表存放處理結(jié)果,PL/SQL程序完成的功能就是將graduate數(shù)據(jù)表中的數(shù)據(jù)逐行掃描,根據(jù)分?jǐn)?shù)線進(jìn)行判斷,計(jì)算出各科總分,在result數(shù)據(jù)表中將標(biāo)志字段自動(dòng)添加上“錄取”或“落選”。 -
         


            --創(chuàng)建數(shù)據(jù)庫表 --graduate
            CREATE TABLE "GRADUATE" (
                "BH" NUMBER(10) NOT NULL,
                "XM" VARCHAR2(10) NOT NULL,
                "LB" VARCHAR2(10) NOT NULL,
                "YINGYU" NUMBER(4, 1) NOT NULL,
                "ZHENGZHI" NUMBER(4, 1) NOT NULL,
                "ZHUANYE1" NUMBER(4, 1) NOT NULL,
                "ZHUANYE2" NUMBER(4, 1) NOT NULL,
                "ZHUANYE3" NUMBER(4, 1) NOT NULL
            )
            
            --創(chuàng)建序列
            create sequence my_suquence  --序列名稱
            minvalue 0                   --序列最小值
            start with 201112081                 --序列起始值
            maxvalue 999999999                  --序列最大值
            increment by 1               --序列的增長值
            nocache                      --不預(yù)先在內(nèi)存中緩存
            cycle;                       --達(dá)到最大值后再重新循環(huán)
           
            --插入數(shù)據(jù)
            insert into graduate values(my_suquence.nextval,'張三豐','碩士','56','56','67','78','79');
            insert into graduate values(my_suquence.nextval,'張無極','碩士','34','56','56','48','79');
            insert into graduate values(my_suquence.nextval,'張翠山','碩士','44','78','76','88','39');
            insert into graduate values(my_suquence.nextval,'趙敏','碩士','67','56','69','73','70');
            insert into graduate values(my_suquence.nextval,'周芷若','碩士','43','56','45','78','67');
            insert into graduate values(my_suquence.nextval,'小昭','碩士','64','66','64','76','79');
           
          --創(chuàng)建數(shù)據(jù)庫表  result 
             CREATE TABLE "RESULT" (
                "BH" NUMBER(10) NOT NULL,
                "XM" VARCHAR2(10) NOT NULL,
                "LB" VARCHAR2(10) NOT NULL,
                "YINGYU" NUMBER(4, 1) NOT NULL,
                "ZHENGZHI" NUMBER(4, 1) NOT NULL,
                "ZHUANYE1" NUMBER(4, 1) NOT NULL,
                "ZHUANYE2" NUMBER(4, 1) NOT NULL,
                "ZHUANYE3" NUMBER(4, 1) NOT NULL,
                "TOTALSCORE" NUMBER(5, 1) NOT NULL,
                "FLAG" VARCHAR2(4) NOT NULL
             )
            
             select * from result;
        --創(chuàng)建存儲(chǔ)過程
                     
              create or replace procedure graduateprocess(
                     tempzhangzhi in graduate.zhengzhi%type,--將表里面的類型賦給該變量
                     tempyingyu in graduate.yingyu%type,
                     tempzhuanye1 in graduate.zhuanye1%type,
                     tempzhuanye2 in graduate.zhuanye2%type,
                     tempzhuanye3 in graduate.zhuanye3%type,
                     temptotalscore in result.totalscore%type)
               as
               --定義graduate為記錄型變量,臨時(shí)存放通過游標(biāo)從graduate表中提取的記錄
                 graduaterecord graduate%rowtype;
               --定義graduatetotalscore為數(shù)值型變量,統(tǒng)計(jì)總分
                 graduatetotalscore result.totalscore%type;
                --定義graduateflag 為字符型變量,根據(jù)結(jié)果放入落選或錄取
                 graduateflag varchar2(4);
                 --定義游標(biāo)graduatecursor,存放的是所有的graduate數(shù)據(jù)表中的記錄
                 cursor graduatecursor is
                        select * from graduate;
                 --定義異常處理
                 errormessage exception;
                
                begin
                --打開游標(biāo)
                     open graduatecursor;
                     if graduatecursor%not found then
                        --如果沒有數(shù)據(jù)。拋出異常
                        raise errormessage;
                     end if;
                     --如果有數(shù)據(jù),將數(shù)據(jù)循環(huán)出來
                     loop
                         fetch graduatecursor into graduaterecord;
                     --計(jì)算總分
                     graduatetotalscore:=graduaterecord.zhengzhi+graduaterecord.yingyu+graduaterecord.zhuanye1+graduaterecord.zhuanye2+graduaterecord.zhuanye3;
                     --比較判斷條件,看是否將數(shù)據(jù)插入到result數(shù)據(jù)庫中
                     if(graduaterecord.yingyu>=tempyingyu and
                        graduaterecord.zhengzhi>=tempzhengzhi and
                        graduaterecord.zhuanye1>=tempzhuanye1 and
                        graduaterecord.zhuanye2>=tempzhuanye2 and
                        graduaterecord.zhuanye3>=tempzhuanye3 and
                        graduaterecord.totalscore>=temptotalscore )
                     then
                       graduateflag:='錄取'
                     else
                        graduateflag:='落選'
                     --退出if
                     end if;
                     --退出游標(biāo)循環(huán)
                     exit when graduatecursor%notfound;
                     --向result數(shù)據(jù)庫中插入數(shù)據(jù)
                     insert into result(BH,xm,lb,yingyu,zhengzhi,zhuanye1,zhuanye2,zhuanye3,totalscore,flag)
                     values(graduaterecord.BH,graduaterecord.XM,graduaterecord.LB,graduaterecord.YINGYU,graduaterecord.ZHENGZHI,
                     graduaterecord.ZHUANYE1,graduaterecord.ZHUANYE2,graduaterecord.ZHUANYE3,graduatetotalscore,graduateflag);
                     end loop;
                     --關(guān)閉游標(biāo)
                     close graduatecursor;
                     commit;--提交結(jié)果
                     --處理異常
                     exception
                        when errormessage then
                            dbms_output.put_line('無法打開數(shù)據(jù)表');
                        /*程序執(zhí)行結(jié)束"*/
                        end;
               end graduateprocess;--存儲(chǔ)過程結(jié)束


         


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

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

      2. 您可能在找
      3. 億恩北京公司:
      4. 經(jīng)營性ICP/ISP證:京B2-20150015
      5. 億恩鄭州公司:
      6. 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
      7. 億恩南昌公司:
      8. 經(jīng)營性ICP/ISP證:贛B2-20080012
      9. 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話:0371-60135900
      10. 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話:0371-60135900
      11. 專注服務(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)
          0
         
         
         
         

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