1. mysql更新某个字段,字段值从1开始递增:
set @rownum=0; update a SET id = ( select @rownum := @rownum +1 as nid) WHERE id < 10;
2. 获取指定字符串出现的次数
/** * 获取指定字符串出现的次数 * * @param srcText 源字符串 * @param findText 要查找的字符串 * @return */ public static int appearNumber(String srcText, String findText) { int count = 0; Pattern p = Pattern.compile(findText); Matcher m = p.matcher(srcText); while (m.find()) { count++; } return count; }
3. 数字转中文
/** * 数字转中文 * @param str * @return */ public static String numToChinese(String str) { String[] s1 = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; String[] s2 = { "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" }; String result = ""; int n = str.length(); for (int i = 0; i < n; i++) { int num = str.charAt(i) - '0'; if (i != n - 1 && num != 0) { result += s1[num] + s2[n - 2 - i]; } else { result += s1[num]; } } while(result.endsWith("零") && result.length()>1){ result = result.substring(0, result.length()-1); } return result; }