Welcome 微信登录

首页 / 数据库 / MySQL / 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"四调用程序包中的函数或者存储过程调用函数(SQL window)
select pkg_staff.get_staff_string() as result from dual
调用存储过程(Command window)
begin
pkg_staff.delete_staff(1);
end;
/ibatis调用Oracle中的functionOracle中的存储过程使用相关资讯      Oracle基础知识 
  • 查看Oracle 32位还是64位(x86 or   (10/05/2014 19:10:00)
  • Oracle中表的建立与修改-五种约束  (02/07/2013 09:49:18)
  • Oracle select 语句字段连接  (12/17/2012 14:51:53)
  • Oracle online redo log 基础知识  (02/09/2013 09:43:04)
  • 如何查看Oracle数据库的session阻  (01/01/2013 09:11:15)
  • Oracle Redo Log 及Logmnr配置使用  (12/14/2012 19:36:51)
本文评论 查看全部评论 (0)
表情: 姓名: 字数

版权所有©石家庄振强科技有限公司2024 冀ICP备08103738号-5 网站地图