使用oracle语句实现:
LPAD (
TO_NUMBER (NVL (
"MAX" ("SUBSTR"("SSCID", '10', '4')),
'0000'
)
) + 1,
4,
0
)
使用java代码实现:
final static int[] sizeTable = {9,99,999,9999,99999,999999,9999999,99999999, 999999999, Integer.MAX_VALUE};
public int sizeOfInt(int x){
for (int i = 0;; i++)
if (x <= sizeTable[i])
return i + 1;
}
Map<String,Object> map = new HashMap<String,Object>();
String SSCID = "BAG12";
StringBuffer stringBuffer = new StringBuffer(SSCID);
Map<String,Object> map1 = bafwgsspMapper.selectMaxSSCID();
String g = (String)map1.get("SSCID");
//转成数字
int i = Integer.parseInt(g);
i = i+1;
int b = sizeOfInt(i);
int c = 4;
int d = c - b;
String L = "";
for(int z = 0;z<d;z++){
L += "0";
}
StringBuilder sb = new StringBuilder(String.valueOf(i));
sb.insert(0, L);
String newSSCID = stringBuffer.append(sb.toString()).toString();
map.put("SSCID", newSSCID);
为了以后方便,留个备份。