public static String getMergeSql(String table, String colnames, String keynames) {
		StringBuilder sb = new StringBuilder();
		sb.append("MERGE INTO " + table + " a ");
		sb.append(" USING (SELECT ");
		String[] colnamelist = colnames.split(",");
		for (int i = 0; i < colnamelist.length; i++) {
			String col = colnamelist[i].trim();
			sb.append(" ? " + col);
			if (i < colnamelist.length - 1)
				sb.append(",");
		}
		sb.append(" FROM dual) b ");
		sb.append("ON (");
		String[] keynamelist = keynames.split(",");
		for (int i = 0; i < keynamelist.length; i++) {
			String keyname = keynamelist[i].trim();
			sb.append(" a." + keyname + "= b." + keyname);
			if (i < keynamelist.length - 1)
				sb.append(" AND ");
		}
		sb.append(") " + "WHEN MATCHED THEN ");

		String updatenames = "";
		for (int i = 0; i < colnamelist.length; i++) {
			String colname = colnamelist[i].trim();
			if (!(keynames + ",").contains(colname + ",")) {
				updatenames += " a." + colname + "= b." + colname;
				updatenames += (" ,");
			}
		}
		if (updatenames.endsWith(","))
			updatenames = updatenames.substring(0, updatenames.length() - 1);
		sb.append(" UPDATE SET " + updatenames);
		sb.append(" WHEN NOT MATCHED THEN INSERT (" + colnames + ") ");
		sb.append(" VALUES (");
		for (int i = 0; i < colnamelist.length; i++) {
			String col = colnamelist[i].trim();
			sb.append(" b." + col);
			if (i < colnamelist.length - 1)
				sb.append(",");
		}
		sb.append(")");
		return sb.toString();
	}