【发布时间】:2015-08-20 11:48:50
【问题描述】:
我正在尝试解析数以千计的 Oracle SQL 脚本 WHERE 子句。
我想将关键字 user(与当前登录的人一样)替换为其他内容。我不能只进行全部替换,因为用户可能被用作 where 子句中另一个单词的一部分,例如列名,例如 payuser。而且我不能简单地检查它的两侧是否有空格,因为它可能在括号内,或者旁边有等号或其他数学字符。
where (username = user or admin = user) and loggedIn=user order by pay_group_code;
public class TestClass{
public static void main(String []args){
String where = "where (username = user or admin = user) and loggedIn=user order by pay_group_code;";
where = where.replaceAll("\buser\b", "test");
System.out.println(where);
}
}
【问题讨论】:
-
你能提供一个示例输入和所需的输出吗?