欢迎来到代码驿站!

Oracle

当前位置:首页 > 数据库 > Oracle

Oracle生成单据编号存储过程的实例代码

时间:2020-12-23 12:16:02|栏目:Oracle|点击:

Oracle生成单据编号存储过程,在做订单类似的系统都可能会存在订单编号不重复,或是流水号按日,按年,按月进行重新编号。

可以参考以下存储过程

CREATE OR REPLACE
procedure Pro_GetBillNO(TypeTable in varchar2,cur_mycursor out sys_refcursor)
as
DReceiptCode varchar2(40);
DReceiptName varchar2(50);
DPrefix1 varchar2(50);
DISO varchar2(50);
DIsAutoCreate varchar2(20);
DPrefix2 varchar2(20);
DPrefix3 varchar2(20);
DDateValue date;
DNO number;
DLength number;
DResetType number;
DSeparator varchar2(20);
DReturnValue varchar2(50);
strSql varchar2(1000);
begin
DReturnValue:='';
select "ReceiptCode","ReceiptName","Prefix1","ISO","IsAutoCreate","Prefix2","Prefix3","DateValue","NO","Length","ResetType","Separator" into
DReceiptCode,DReceiptName,DPrefix1,DISO,DIsAutoCreate,DPrefix2,DPrefix3,DDateValue,DNO,DLength,DResetType,DSeparator from
"SysReceiptConfig" where "ReceiptCode"=TypeTable;
if to_number(DResetType)>0
then
if DIsAutoCreate=1 THEN
if DResetType=1 then --按年份
if to_number(to_char(sysdate,'yyyy')) <>to_number(to_char(DDateValue,'yyyy')) then
update "SysReceiptConfig" set "NO"=1,"DateValue"=to_date(sysdate) where "ReceiptCode"=TypeTable;
else
update "SysReceiptConfig" set "NO"="NO"+1 where "ReceiptCode"=TypeTable;
end if; --年份
end if;--DResetType=1
if DResetType=2 then --按月份
if to_number(to_char(sysdate,'MM')) <>to_number(to_char(DDateValue,'MM')) then
update "SysReceiptConfig" set "NO"=1,"DateValue"=to_date(sysdate) where "ReceiptCode"=TypeTable;
else
update "SysReceiptConfig" set "NO"="NO"+1 where "ReceiptCode"=TypeTable;
end if; --月份
end if;--DResetType=2
if DResetType=3 then --按日
if to_number(to_char(sysdate,'dd')) <>to_number(to_char(DDateValue,'dd')) then
update "SysReceiptConfig" set "NO"=1,"DateValue"=to_date(sysdate) where "ReceiptCode"=TypeTable;
else
update "SysReceiptConfig" set "NO"="NO"+1 where "ReceiptCode"=TypeTable;
end if; --月份
end if;--DResetType=3
else
update "SysReceiptConfig" set "NO"="NO"+1 where "ReceiptCode"=TypeTable;
end if;--DResetType
end if;
strSql:=' select * from "SysReceiptConfig" where 1=1 ';
strSql:=strSql ||' and "ReceiptCode"='''||TypeTable||'''';
open cur_mycursor for strSql;
end;

上一篇:Oracle数据库性能优化技术开发者网络Oracle

栏    目:Oracle

下一篇:Oracle自我补充之trunc()函数的使用方法

本文标题:Oracle生成单据编号存储过程的实例代码

本文地址:http://www.codeinn.net/misctech/35773.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有