欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Oracle 中包的應(yīng)用

系統(tǒng) 1911 0

? ? ? ?包由兩個(gè)分離的部分組成:包頭(PACKAGE)和包體(PACKAGEBODY)。包頭是包的說明部分,是對(duì)外的操作接口,對(duì)應(yīng)用是可見的;包體是包的代碼和實(shí)現(xiàn)部分,對(duì)應(yīng)用來說是不可見的黑盒。
? ? ? ?出現(xiàn)在包頭中的稱為公有元素,出現(xiàn)在包體中的稱為私有元素,出現(xiàn)在包體的過程(或函數(shù))中的稱為局部變量。

創(chuàng)建包頭的簡(jiǎn)要語句如下:

      
        CREATE [OR REPLACE] PACKAGE 包名

{IS
      
      |
      
        AS}

公有變量定義

公有類型定義

公有游標(biāo)定義

公有異常定義

函數(shù)說明

過程說明

END;
      
    

創(chuàng)建包體的簡(jiǎn)要語法如下:

      
        CREATE [OR REPLACE] PACKAGE BODY 包名

{IS
      
      |
      
        AS}

私有變量定義

私有類型定義

私有游標(biāo)定義

私有異常定義

函數(shù)定義

過程定義

END;
      
    

其它操作:

      
        刪除包頭:

DROP PACKAGE 包頭名

刪除包體:

DROP PACKAGE BODY 包體名

重新編譯包頭:

ALTER PACKAGE 包名 COMPILE PACKAGE

重新編譯包體:

ALTER PACKAGE 包名 COMPILE PACKAGE BODY
      
    

案例:對(duì)學(xué)生表infos提供一個(gè)增刪改查的包,infos表內(nèi)容如下圖所示:

包中的內(nèi)容結(jié)構(gòu)如下:

程序結(jié)構(gòu) 類型 參數(shù) 說明
v_infos_count 公有變量 ? 學(xué)生總總數(shù)量,number類型
p_init 公有過程

p_max number

p_min number

最大值,最小值
p_list_infos 公有過程 ? 顯示學(xué)生列表數(shù)據(jù)
p_add_infos 公有過程

p_stuid infos.stuid%type,
p_stuname infos.stuname%type,
p_gender infos.gender%type,
p_age infos.age%type,
p_seat infos.seat%type,
p_enrolldate infos.enrolldate%type,
p_stuaddress infos.stuaddress%type,
p_classno infos.classno%type

增加一條學(xué)生記錄
p_delete_infos 公有過程 p_stuid infos.stuid%type 根據(jù)stuid刪除一條學(xué)生記錄
p_edit_infos_name 公有過程

p_stuid infos.stuid%type
p_stuname infos.stuname%type

根據(jù)stuid修改學(xué)生的姓名
v_msg 私有變量 ? show message
v_max_age 私有變量 ? max age ,number
v_min_age 私有變量 ? min age ,number
f_exist_infos 私有函數(shù)

p_stuid infos.stuid%type

判斷學(xué)生是否存在,

return boolean

p_show_msg 私有過程 ? show msg

包SQL:


        1
      
      
        )創(chuàng)建包頭


      
      
        create
      
      
        or
      
      
        replace
      
      
         package pck_infos


      
      
        as
      
      
        --
      
      
        總數(shù)量
      
      

  v_infos_count 
      
        number
      
      
        ;

  
      
      
        --
      
      
        初始化操作
      
      
        procedure
      
       p_init(p_max 
      
        number
      
      , p_min 
      
        number
      
      
        );

  
      
      
        --
      
      
        顯示學(xué)生列表數(shù)據(jù)
      
      
        procedure
      
      
         p_list_infos;

  
      
      
        --
      
      
        增加一條學(xué)生記錄
      
      
        procedure
      
      
         p_add_infos(

    p_stuid       infos.stuid
      
      
        %
      
      
        type,

    p_stuname     infos.stuname
      
      
        %
      
      
        type,

    p_gender      infos.gender
      
      
        %
      
      
        type,

    p_age         infos.age
      
      
        %
      
      
        type,

    p_seat        infos.seat
      
      
        %
      
      
        type,

    p_enrolldate  infos.enrolldate
      
      
        %
      
      
        type,

    p_stuaddress  infos.stuaddress
      
      
        %
      
      
        type,

    p_classno     infos.classno
      
      
        %
      
      
        type);

  
      
      
        --
      
      
        刪除一條學(xué)生記錄
      
      
        procedure
      
       p_delete_infos(p_stuid infos.stuid
      
        %
      
      
        type);

  
      
      
        --
      
      
        根據(jù)stuid修改學(xué)生的姓名
      
      
        procedure
      
      
         p_edit_infos_name(

    p_stuid   infos.stuid
      
      
        %
      
      
        type,

    p_stuname infos.stuname
      
      
        %
      
      
        type);


      
      
        end
      
      
        ;

(
      
      
        2
      
      
        )創(chuàng)建包體


      
      
        create
      
      
        or
      
      
        replace
      
      
         package body pck_infos


      
      
        as
      
      
        

  v_msg     
      
      
        varchar2
      
      (
      
        100
      
      );  
      
        --
      
      
        show message
      
      

  v_max_age 
      
        number
      
      ;         
      
        --
      
      
        max age
      
      

  v_min_age 
      
        number
      
      ;         
      
        --
      
      
        min age
      
      
        --
      
      
        判斷學(xué)生是否存在
      
      
        function
      
       f_exist_infos(p_stuid infos.stuid
      
        %
      
      
        type)

  
      
      
        return
      
      
         boolean;

  

  
      
      
        --
      
      
        show msg
      
      
        procedure
      
      
         p_show_msg;

  

  
      
      
        --
      
      
        初始化操作
      
      
        procedure
      
       p_init(p_max 
      
        number
      
      , p_min 
      
        number
      
      
        )

  
      
      
        as
      
      
        begin
      
      
        select
      
      
        count
      
      (stuid) 
      
        into
      
       v_infos_count 
      
        from
      
      
         infos;

    v_max_age:
      
      
        =
      
      
        p_max;

    v_min_age:
      
      
        =
      
      
        p_min;

    v_msg:
      
      
        =
      
      
        '
      
      
        init finished!
      
      
        '
      
      
        ;

    p_show_msg;

  
      
      
        end
      
      
         p_init;

  

  
      
      
        --
      
      
        顯示信息
      
      
        procedure
      
      
         p_show_msg

  
      
      
        as
      
      
        begin
      
      
        

    dbms_output.put_line(v_msg);

  
      
      
        end
      
      
         p_show_msg;

   
      
      
        --
      
      
        判斷學(xué)生是否存在
      
      
        function
      
       f_exist_infos(p_stuid infos.stuid
      
        %
      
      
        type)

  
      
      
        return
      
      
         boolean

  
      
      
        as
      
      
        

    v_num 
      
      
        number
      
      
        ;

  
      
      
        begin
      
      
        select
      
      
        count
      
      (stuid) 
      
        into
      
       v_num 
      
        from
      
       infos 
      
        where
      
       stuid
      
        =
      
      
        p_stuid;

    
      
      
        if
      
       v_num
      
        =
      
      
        1
      
      
        then
      
      
        return
      
      
         true;

    
      
      
        else
      
      
        return
      
      
         false;

    
      
      
        end
      
      
        if
      
      
        ;

  
      
      
        end
      
      
         f_exist_infos;

  

  
      
      
        --
      
      
        顯示學(xué)生列表數(shù)據(jù)
      
      
        procedure
      
      
         p_list_infos

  
      
      
        as
      
      
        

    v_infos_record infos
      
      
        %
      
      
        rowtype;

    
      
      
        cursor
      
       cur_infos 
      
        is
      
      
        select
      
      
        *
      
      
        from
      
      
         infos;

  
      
      
        begin
      
      
        open
      
      
         cur_infos;

    loop

      
      
      
        fetch
      
       cur_infos 
      
        into
      
      
         v_infos_record;

      
      
      
        exit
      
      
        when
      
       cur_infos
      
        %
      
      
        notfound;

      dbms_output.put_line(
      
      
        '
      
      
        stuid:
      
      
        '
      
      
        ||
      
      
        v_infos_record.stuid);

    
      
      
        end
      
      
         loop;

    
      
      
        close
      
      
         cur_infos;

  
      
      
        end
      
      
         p_list_infos;

  

  
      
      
        --
      
      
        增加一條學(xué)生記錄
      
      
        procedure
      
      
         p_add_infos(

    p_stuid       infos.stuid
      
      
        %
      
      
        type,

    p_stuname     infos.stuname
      
      
        %
      
      
        type,

    p_gender      infos.gender
      
      
        %
      
      
        type,

    p_age         infos.age
      
      
        %
      
      
        type,

    p_seat        infos.seat
      
      
        %
      
      
        type,

    p_enrolldate  infos.enrolldate
      
      
        %
      
      
        type,

    p_stuaddress  infos.stuaddress
      
      
        %
      
      
        type,

    p_classno     infos.classno
      
      
        %
      
      
        type)

  
      
      
        as
      
      
        begin
      
      
        if
      
      
        not
      
       f_exist_infos(p_stuid) 
      
        then
      
      
        insert
      
      
        into
      
      
         infos(stuid,stuname,gender,age,seat,enrolldate,stuaddress,classno)

        
      
      
        values
      
      
        (p_stuid,p_stuname,p_gender,p_age,p_seat,p_enrolldate,p_stuaddress,p_classno);

      
      
      
        commit
      
      
        ;

      v_infos_count:
      
      
        =
      
      v_infos_count
      
        +
      
      
        1
      
      
        ;

    
      
      
        else
      
      
        

      v_msg:
      
      
        =
      
      
        '
      
      
        already exist!
      
      
        '
      
      
        ;

    
      
      
        end
      
      
        if
      
      
        ;

  
      
      
        end
      
      
         p_add_infos;

  

  
      
      
        --
      
      
        刪除一條學(xué)生記錄
      
      
        procedure
      
       p_delete_infos(p_stuid infos.stuid
      
        %
      
      
        type)

  
      
      
        as
      
      
        begin
      
      
        if
      
       f_exist_infos(p_stuid) 
      
        then
      
      
        delete
      
      
        from
      
       infos 
      
        where
      
       stuid
      
        =
      
      
        p_stuid;

      
      
      
        commit
      
      
        ;

      v_infos_count:
      
      
        =
      
      v_infos_count
      
        -
      
      
        1
      
      
        ;

    
      
      
        else
      
      
        

      v_msg:
      
      
        =
      
      
        '
      
      
        not exist infos!
      
      
        '
      
      
        ;

    
      
      
        end
      
      
        if
      
      
        ;

  
      
      
        end
      
      
         p_delete_infos;

  

   
      
      
        --
      
      
        根據(jù)stuid修改學(xué)生的姓名
      
      
        procedure
      
      
         p_edit_infos_name(

    p_stuid   infos.stuid
      
      
        %
      
      
        type,

    p_stuname infos.stuname
      
      
        %
      
      
        type)

  
      
      
        as
      
      
        begin
      
      
        if
      
       f_exist_infos(p_stuid) 
      
        then
      
      
        update
      
       infos 
      
        set
      
       stuname
      
        =
      
      p_stuname 
      
        where
      
       stuid
      
        =
      
      
        p_stuid;

      
      
      
        commit
      
      
        ;

    
      
      
        else
      
      
        

      v_msg:
      
      
        =
      
      
        '
      
      
        not exists infos
      
      
        '
      
      
        ;

    
      
      
        end
      
      
        if
      
      
        ;

  
      
      
        end
      
      
         p_edit_infos_name;

    


      
      
        end
      
      ;
    

?

Oracle 中包的應(yīng)用


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: www.ouchn.com | 精品久久不卡 | 国产成人理在线观看视频 | 成人精品一区二区三区 | 日本在线视 | 九九热视频免费 | 欧洲色吧 | 学院传说之三生三世桃花缘 | 啪啪网页 | 国产亚洲精品高清在线 | 日本成人在线看 | 1024污视频| 久久在线视频 | 琪琪色在线视频 | 亚洲 欧洲 偷拍 校园 另类 | 久久y| 成人免费福利 | 亚洲成人福利在线 | 欧美精品综合 | 亚洲国产视频在线观看 | 国内一级一级毛片a免费 | 九九精品视频一区二区三区 | 久久久久久亚洲 | 九九精品在线 | 免费看黄在线网站 | 欧美一级美国一级 | 久久高清| 日韩欧美一区二区三区在线视频 | 国产欧美一区二区三区免费看 | 牛牛a级毛片在线播放 | 亚洲成人免费视频 | 亚洲精品vr一区 | 国产成人18黄网站免费网站 | 蜜臀传煤mv在线观看 | 欧美视频在线一区二区三区 | 黄工厂精品视频在线观看 | 奇米影视777中文久久爱 | 免费网站国产 | 女人色毛片女人色毛片中国 | 99精品欧美一区二区三区综合在线 | 国产精品久久久久aaaa九色 |