• 读《Oracle PLSQL 程序设计第五版》创建包规范和包体


    create or replace package favorites_pkg
    authid current_user 
    --authid字句,用来确定在引用包中的数据对象是应该根据包的属主(authid definer)来解析
    --还是根据包的调用者(authid current_user)来解析
    is /*or as*/
    --两个常量
    c_chocolate constant pls_integer := 16;
    c_strawberry constant pls_integer := 29;
    
    --用type声明一个嵌套表类型
    type codes_nt is table of integer;
    
    --根据之前那个类型声明的一个嵌套表变量
    my_favorites codes_nt;
    
    --  一个返回信息的ref cursor 游标类型
    type fav_info_rct is ref cursor return favorites%rowtype;
    
    --  一个过程,接收信息列表,然后显示列表中的信息
    procedure show_favorites(list_in in codes_nt);
    
    --  一个函数,返回信息中的内容
    function most_popular return fav_info_rct;
    
    end favorites_pkg;
    

    创建完包规范后,创建包体。

    create or replace package body favorites_pkg
    --不能在包体中使用authid字句,其必须出现在包规范中。
    is
    --  一个私有变量
    g_most_popular pls_integer := c_strawberry;
    
    --函数的实现部分
    function most_popular return fav_info_rct
      is
      retval fav_info_rct;
      null_cv fav_info_rct;
      begin
        open retval for
             select * from favorites where id = g_most_popular;
        return retval;
      exception
        when no_data_found then return null_cv;
    end most_popular;
    
    --过程的实现部分
    procedure show_favorites (list_in in codes_nt) is
      begin
        for indx in list_in.first .. list_in.last
          loop
            dbms_output.put_line(list_in (indx));
          end loop;
    end show_favorites;
    
    --初始化单元
    begin
    g_most_popular = c_chocolate ;
    end favorites_pkg;
    

      

      

  • 相关阅读:
    day12_函数
    day12_游标
    day12_序列——重置序列
    day12_序列——oracle主键自动增加
    day12_B2B用户禁止PLSQL登录
    七月未央,安之若素
    php----显示中文乱码的问题
    C#--中实现邮件发送
    C#--使用存储过程
    C#--之文件操作
  • 原文地址:https://www.cnblogs.com/liuzhe/p/5198016.html
Copyright © 2020-2023  润新知