Here is the code i used to get the desire result. The only problem is if there is null value then it does not generate the next number.
declare
matter_no number(2);
begin
select max(to_number(substr(matter_code,1,2))) + 1 into :matter.matter_code from matter where
client_code=:matter.client_code;
if :matter_code > 1 and :matter_code <= 10 then
:matter.matter_code:='0'||matter_no;
elsif client_no >=10 and client_no <=99 then
:client.client_code:='00'||client_no;
elsif client_no >=100 and client_no <=999 then
:client.client_code:='0'||client_no;
else :matter.matter_code:=''||matter_no;
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN
message('No record exist');
end;
any advice or correction in the code will be appreciated.
declare
matter_no number(2);
begin
select max(to_number(substr(matter_code,1,2))) + 1 into :matter.matter_code from matter where
client_code=:matter.client_code;
if :matter_code > 1 and :matter_code <= 10 then
:matter.matter_code:='0'||matter_no;
elsif client_no >=10 and client_no <=99 then
:client.client_code:='00'||client_no;
elsif client_no >=100 and client_no <=999 then
:client.client_code:='0'||client_no;
else :matter.matter_code:=''||matter_no;
end if;
EXCEPTION
WHEN NO_DATA_FOUND THEN
message('No record exist');
end;
any advice or correction in the code will be appreciated.