日期:2014-05-16  浏览次数:20679 次

求指导一下这个oracle题目,谢谢!!
有两张表,分别是cust_info(客户信息表)和cust_dep_info(客户盈利表)。
cust_info表中有三个字段,分别为cust_id(varchar2),cust_name(varchar2),cust_type(varchar2);
cust_dep_info表中有四个字段,分别是account_id(number),cust_id(varchar2),money(number),mounth(date)。

cust_info 中的cust_id 与cust_dep_info 中的cust_id关联。

存储过程实现:
给出一个日期,然后计算与日期对应的每个客户的money占总money的比例,根据计算出的这个比例,将客户划分成不同级别,然后将级别更新到cust_info表的cust_type字段中。

所占比例及对应的客户类型如下:
 [0 - 20%] 核心客户
(20% - 80%]战略客户
(80% - 100]普通客户

使用oracle中的存储过程实现。请大神赐教,菜鸟初入职场,能力有限,必定认真领会,感激不尽!

------解决方案--------------------
create or replace procedure your_pro(in_date in date,
                                     RetMemo out varchar2 --若失败,返回失败信息
                                     )
is
 v_cust_type    varchar2(20);
 v_count number;
 cursor c_find is
 select cust_id,100*round(e_money/sum(e_money)over(),4) bfb from
 (select cust_id,sum(money) e_money from cust_dep_info where mounth=in_date group by cust_id );
 cc c_find%rowtype;
begin
  RetMemo :='';
  v_count :=0;
  open c_find;
      loop
          fetch c_find into cc;
          exit when c_find%notfound;
          if cc.bfb>=0 and cc.bfb<=20 then
            v_cust_type :='核心客户';
            elsif  cc.bfb>20 and cc.bfb<=80 then
               v_cust_type :='战略客户';
            elsif cc.bfb>80 and cc.bfb<=100 then
                   v_cust_type :='普通客户';
                   end if;
          update cust_info set