我知道這是一個古老的問題,但如果您使用Java編碼並遇到此問題,這可能會有幫助。你可以註冊一個處理類似檢查的函數。我得到了尖形式這篇文章:https://stackoverflow.com/a/29831950/1271573
的解決方案,我依賴的sqlite的jdbc:https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
在我的情況,看是否有一定的字符串存在作爲另一個字符串的一部分(如「%的MyString%我只需要'),所以我創建了一個Contains函數,但應該可以將其擴展爲使用正則表達式或類似方法進行更類似於sql的檢查。
要使用該功能在SQL,看看是否MyCol包含「搜索字符串」你會做:
select * from mytable where Contains(MyCol, 'searchstring')
這裏是我的包含功能:
public class Contains extends Function {
@Override
protected void xFunc() throws SQLException {
if (args() != 2) {
throw new SQLException("Contains(t1,t2): Invalid argument count. Requires 2, but found " + args());
}
String testValue = value_text(0).toLowerCase();
String isLike = value_text(1).toLowerCase();
if (testValue.contains(isLike)) {
result(1);
} else {
result(0);
}
}
}
要使用此功能,你必須先註冊它。當你完成使用它時,你可以選擇銷燬它。這裏是如何:
public static void registerContainsFunc(Connection con) throws SQLException {
Function.create(con, Contains.class.getSimpleName(), new Contains());
}
public static void destroyContainsFunc(Connection con) throws SQLException {
Function.destroy(con, Contains.class.getSimpleName());
}
http://stackoverflow.com/a/973777/1427878 – CBroe 2013-03-18 15:22:36