zoukankan      html  css  js  c++  java
  • ORACLE的程序包1程序包的基

    程序包简析

      oracle中的程序包简析    一 程序包的基本概念
        程序包可将若干函数或者存储过程组织起来,作为一个对象进行存储。程序包通常由两部分构成,规范(specification)和主体(body)。

        程序包也可以包含常量和变量,包中的所有函数和存储过程都可以使用这些变量或者常量。

       程序包是对相关过程、函数、变量、游标和异常等对象的封装 程序包由规范和主体两部分组成

        二 规范
        1 创建规范(SQL窗口)
        create or replace package pkg_staff as
        staffString varchar2(500);
        stafftAge number:=18;
        function get_staff_string return varchar2;
        procedure insert_staff(in_staff_id in number,in_staff_name in varchar2);
        procedure update_staff(in_staff_id in number);
        procedure delete_staff(in_staff_id in number);
        end pkg_staff;
        2 在数据字典中查看程序包规范的信息
        select object_name,object_type,status from user_objects
        where lower(OBJECT_NAME) = 'pkg_staff'
        三 主体
        所谓规范,就像面向对象编程中的接口,该规范的主体必须实现该规范的所有方法。Oracle会自动寻找与主体同名的规范,看是否全部实现了该规范函数或者存储过程。若没有,则编译错误。
        1 创建主体
        create or replace package body pkg_staff as
        function get_staff_string return varchar2 as
        begin
        return 'staff';
        end get_staff_string;
        procedure insert_staff(in_staff_id in number,in_staff_name in varchar2) as
        begin
        insert into staff values (in_staff_id,in_staff_name);
        end insert_staff;
        procedure update_staff(in_staff_id in number) as
        begin
        update staff set name = 'xy' where num = in_staff_id;
        end update_staff;
        procedure delete_staff(in_staff_id in number) as
        begin
        delete from staff where num = '1';
        end delete_staff;
        end pkg_staff;
        2 在数据字典中查看程序包主体的信息
        select object_name,object_type,status from user_objects
        where lower(OBJECT_NAME) = 'pkg_staff'
        www.2cto.com
        四 调用程序包中的函数或者存储过程
        调用函数(SQL window)
        select pkg_staff.get_staff_string() as result from dual
        调用存储过程(Command window)
        begin
        pkg_staff.delete_staff(1);
        end;
        /

  • 相关阅读:
    P2788 数学1(math1)- 加减算式
    数据库第三章-学习笔记
    字典序
    P1739 表达式括号匹配
    P3742 umi的函数
    P1765 手机
    P2192 HXY玩卡片
    全排函数c++ next_permutation()
    11.css定义下拉菜单
    10.php引用(&)详解及注意事项
  • 原文地址:https://www.cnblogs.com/violin508/p/4321434.html
Copyright © 2011-2022 走看看