Orcale Function Sequence.
1 Create Or Replace Function F_Get_Sequence(As_Companyno In Varchar2,
As_Tablename In Varchar2,
As_Prefix In Varchar2,
As_Number In Number := 6)
Return Varchar2 Is
As_Seqvalue Varchar(32);
As_SeqvalueTemp Varchar(32);
As_Tablenameupper Varchar2(64);
As_Count Number(6);
As_Sql Varchar2(500);
As_Length Number(6);
Begin
If As_Number Is Null Then
As_Length := 6;
Else
As_Length := As_Number;
End If;
As_Tablenameupper := Upper(As_Tablename);
Select Count(1)
Into As_Count
From Basic_Sequence t
Where t.Companyno = As_Companyno
And t.Tablename = As_Tablenameupper;
If As_Count = 0 Then
Begin
As_Sql := 'Insert Into Basic_Sequence(Companyno,Tablename, Currentvalue) Values (:Companyno,:Tablename, 0)';
Execute Immediate As_Sql
Using As_Companyno, As_Tablenameupper;
Commit;
End;
End If;
Update Basic_Sequence t
Set t.Currentvalue = t.Currentvalue + 1
Where t.Companyno = As_Companyno
And t.Tablename = As_Tablenameupper;
Select Currentvalue
Into As_Seqvalue
From Basic_Sequence t
Where t.Companyno = As_Companyno
And t.Tablename = As_Tablenameupper;
IF Length(As_Seqvalue) < As_Length Then
As_Length = Length(As_Seqvalue);
End If;
As_Seqvalue := As_Prefix || To_Char(Sysdate, 'yyyymmdd') ||
Lpad(Substr(As_Seqvalue, -As_Length), As_Length, '');
Return(As_Seqvalue);
End f_Get_Sequence;