id code

145623 xyz001

178956 sbh002

165895 sbi003

As per this logic,for every new entity of id a new autogenerated code will be generated.

This xyz code should be fetched using select query using id. And 001,002 is autogenerated code

ex: select b_code into table.code from cmp where c_id =145623;

Could you please help me..