思路OK,但有点小问题:
SELECT NVL(MAX(maxvalue),0)+1 INTO v_maxseq FROM copsendbillmax
WHERE compid = v_compid AND yearmonth = v_yearmonth;
这样写有并发问题,多个人同时操作可能产生重复的发票号
可以这样设计,在copsendbillmax中存储当月的当前流水
然后使用for update主动锁定,取流水号,最后更新流水号,提交释放锁
1.select maxvalue from copsendbillmax WHERE compid = v_compid AND yearmonth = v_yearmonth for update;
2. curr_value := maxvalue + 1;
3. update copsendbillmax set maxvalue= curr_value WHERE compid = v_compid AND yearmonth = v_yearmonth;
4.commit;
SELECT NVL(MAX(maxvalue),0)+1 INTO v_maxseq FROM copsendbillmax
WHERE compid = v_compid AND yearmonth = v_yearmonth;
这样写有并发问题,多个人同时操作可能产生重复的发票号
可以这样设计,在copsendbillmax中存储当月的当前流水
然后使用for update主动锁定,取流水号,最后更新流水号,提交释放锁
1.select maxvalue from copsendbillmax WHERE compid = v_compid AND yearmonth = v_yearmonth for update;
2. curr_value := maxvalue + 1;
3. update copsendbillmax set maxvalue= curr_value WHERE compid = v_compid AND yearmonth = v_yearmonth;
4.commit;
-- 为了实现单据状态这一业务逻辑,你可以添加一个check约束和一个触发器!在此不再多述!
-- 取消的单据和交易成功的单据不能再修改,
-- 当单据由状态1改变为状态0时,实际是订购单据的逆向操作,此时要将其交易的商品添加回库存表,
-- 这个可以用触发器来实现!-- 不知道我这样理解对不对?