pl/sql structure&package

【学习的点点滴滴】学了一段时间的pl/sql 这里Sinpoal将一些东西记录在这里头。首先我要写的是关于pl/sql 语句块的结构。所有的pl/sql块都会按这种结构来写:
-----pl/sql structure
declare
v_fenshu t8.fenshu%type;
v_name t8.name%type;
v_score t8.fenshu%type;
v_number constant number(3,2):=5.25;
begin
--执行体
select fenshu,name into v_fenshu ,v_name from t8 where name='&v_name'and chengji='&v_chengji';
v_score:=v_fenshu*v_number;
dbms_output.put_line(v_name||';'||v_fenshu);
dbms_output.put_line(v_score);
--异常处理
exception
when no_data_found then
dbms_output.put_line('please input the right values');

end;

--------接下来写一哈如何定义使用package--
--其实对它的理解我们可以用对c#中接口来理解的方式来理解package
 我们在package中定义function 和 procedure  ,在 package body 中实现。这一点接口有点共通之处。

----package-----------
create or replace package test_package
  is
 monthh number:=2;
 function validate (v_month number) return boolean;
 procedure add_data(monthh number,price number);
 procedure fire_date(monthh number);
 end test_package;

--------package body------
create or replace package body test_package
is
function validate (v_month number)
  return boolean
  is
  v_int number;
  begin
  select 1 into v_int from test where month=v_month;
  return false;
  exception
  when no_data_found then
  return true;
  end;
 
  procedure add_data(monthh number,price number)
   is
    begin
    if validate(monthh) then
     insert into test values (monthh,price);
     else
     raise_application_error(-20010,'该月份已存在');
     end if;
     end;
    
  procedure fire_date(monthh number)
     is
     begin
     delete from test where month=monthh;
   if sql%notfound then
  raise_application_error(-20010,'数据不存在');
    end if ;
    end;
 end test_package;
    
-----------call the package--------
--我们在调用package中的function 和procedures的时候。在 sql command的模式下用exec 调用
如:exec package_name.function_name or procedure_name.


 
    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值