mysql 生成流水号: select lpad(ifnull(max(substring(BUSINESS_ORDER_CODE,3,4))+1,1),4,0) as waterNumber from bh_customer_info
BUSINESS_ORDER_CODE的值为前面两位英文,后面四位数字,例如WH0001,LB0510
bh_customer_info这是表名。
substring(BUSINESS_ORDER_CODE,3,4) 获得的值为0001,0510
max(substring(BUSINESS_ORDER_CODE,3,4))+1获得该列中最大值并加1
ifnull(max(substring(BUSINESS_ORDER_CODE,3,4))+1,1)如果该列中的值为null,则赋值为1,这种情况只在数据库表中无数据的时候才起到作用。
lpad(ifnull(max(substring(BUSINESS_ORDER_CODE,3,4))+1,1),4,0)该函数的意思是,总共四位数,如果位数不足,则用0填充。
oracle判断列值为空时用NVL代替mysql的ifnull