【讨论】Oracle 存储过程写法

[复制链接]
查看11 | 回复9 | 2013-2-25 14:51:24 | 显示全部楼层 |阅读模式
本帖最后由 yangrongyan2008 于 2014-11-10 10:27 编辑
请教各位大侠!
CREATE OR REPLACE PROCEDURE "PROC_POINT_ACTIVITY_11" is
cursor c2 is
select o.customer_idmycustomerid,
o.order_id myorderid,
o.customer_card_id mycardid
from t_to_order_info o
union
select o.customer_idmycustomerid,
o.order_id myorderid,
o.customer_card_id mycardid
from t_ho_order_info o;
begin
---插入信息之前 先判断t_c_activity_customer 表里有没有这个会员
for r2 in c2 loop
insert into t_c_activity_customer values (r2.mycustomerid);
---生成积分明细
insert into t_c_point_record2014
values
(seq_t_c_point_record.nextval,
null,
1,
7,
r2.mycustomerid,
null,
1000,
'手机客户端营销活动',
2,
r2.myorderid,
sysdate,
1,
r2.mycardid);
--更新会员表积分记录 加1000
update t_c_customer c
set c.gc_points_total= c.gc_points_total + 1000,

c.gc_points_usable = c.gc_points_usable + 1000
where c.customer_id = r2.mycustomerid
and not exists (select CUSTOMER_ID

from t_c_activity_customer

where customer_id = r2.mycustomerid); -- --------愿意是想 排除 更新过的会员,实现会员即使预定多次 也只送一次积分。目前这里有问题 会员下几个订单 ,积分就翻倍增加
commit;
end loop;
end;


回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
在线等答案了。。
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
业务上的事?我还以为是存储过程的语法不懂。
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
额 插入信息之前 先判断t_c_activity_customer 表里有没有这个会员号呗
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
moseslin 发表于 2014-11-7 13:28
业务上的事?我还以为是存储过程的语法不懂。

嗯啊。。是只赠送一次 我实现有难度?请教下
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
iyee_tu 发表于 2014-11-7 13:31
额 插入信息之前 先判断t_c_activity_customer 表里有没有这个会员号呗

能在具体些吗?


回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
update t_c_customer c
set c.gc_points_total= c.gc_points_total + 1000,

c.gc_points_usable = c.gc_points_usable + 1000
where c.customer_id=r2.mycustomerid
and not exists (select CUSTOMER_ID from t_c_activity_customer
where customer_id=c.customer_id ); --------愿意是想 排除 更新过的会员,实现会员即使预定多次 也只送一次1000积分。目前这里有问题 会员下几个订单 ,积分就翻倍增加
这个要修改啊
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
xkf01 发表于 2014-11-7 13:49
update t_c_customer c
set c.gc_points_total= c.gc_points_total + 1000,

c.gc_poin ...

嗯 知道要改 如何 改呢
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
本帖最后由 xkf01 于 2014-11-7 13:59 编辑
----rowid刚才写错了
update t_c_customer c
set c.gc_points_total= c.gc_points_total + 1000,
c.gc_points_usable = c.gc_points_usable + 1000
where c.customer_id=r2.mycustomerid
and not exists (select CUSTOMER_ID from t_c_activity_customer
where customer_id=c.customer_id );
and (customer_id
,rowid) in (
select d.customer_id
,max(rowid) fromt_c_customer d
group by d.customer_id
)
回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
第一次,那积分不是为0的时候?判断一下不就是了?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行