java 实现自增编号+Oracle序列
原理:a,a++,fillStr(a, 9, false, "0");
新建序列:
create sequence seq_line
minvalue 1
maxvalue 999999999
start with 1
increment by 1
cache 10
NOCYCLE;获取该序列的下一个值:
select seq_trip.nextval from dual
获取编号:
public static void main(String[] args) {
String outString="";
outString=fillStr("1", 9, false, "0");
System.out.println("false"+outString);
outString=fillStr("123", 9, true, "0");
System.out.println("true"+outString);
}
public static String fillStr(String value, int count, boolean frontORback, String fillChar) {
String rtvalue = value;
if (rtvalue == null) {
rtvalue = "";
for (int i = 0; i < count; i++)
if (frontORback)
rtvalue = String.valueOf(rtvalue)
+ String.valueOf(fillChar);
else
rtvalue = String.valueOf(fillChar)
+ String.valueOf(rtvalue);
} else {
int len = rtvalue.length();
if (len > count) {
rtvalue = rtvalue.substring(0, count);
} else {
int a = count - len;
for (int i = 0; i < a; i++)
if (frontORback)
rtvalue = String.valueOf(rtvalue)
+ String.valueOf(fillChar);
else
rtvalue = String.valueOf(fillChar)
+ String.valueOf(rtvalue);
}
}
return rtvalue;
}
本文原创,转载必追究版权。