我正在尝试通过在最后一个数字之后添加1来生成数字,但是代码不想在90之后添加1并继续生成10
我的序列中的最后一个数字是1918190,但是我得到的新序列是1918110
if (ecdCentre.getCenterID() == null || ecdCentre.getCenterID().isEmpty()) {
sql = "SELECT concat(EC_CENTRE_REGION_ID, EC_CENTRE_CONSTITUENCY_ID, lpad( CASE WHEN MAX(SUBSTRING(EC_CENTRE_NO,6)) = '' THEN 0 ELSE MAX(SUBSTRING(EC_CENTRE_NO,6)) END + 1 , 2, '0') ) centre_number FROM ecd_centre_reference WHERE EC_CENTRE_REGION_ID = ? AND EC_CENTRE_CONSTITUENCY_ID = ? ";
centreNumber = template.queryForObject(sql,
new Object[] { ecdCentre.getRegionID(), ecdCentre.getConstituencyID() }, String.class);
ecdCentre.setCenterID(centreNumber);
System.out.println("Getting the con code: " + ecdCentre.getConstituencyID());
System.out.println("Geting the re code: " + ecdCentre.getRegionID());
System.out.println("Centre Number: " + centreNumber);
}
最佳答案
我通过转换表中的结果来解决它。首先,我必须将结果转换为以varchar格式存储的int
sql = "SELECT IFNULL(MAX(CONVERT( SUBSTRING(ec_centre_no, 6) , UNSIGNED INTEGER)), 0) + 1 new_centre_sequence FROM ecd_centre_reference "
+ " WHERE ec_centre_region_id = ? AND ec_centre_constituency_id = ? ";
```````````````````````````````````````````````````````````````