日期:2014-05-20  浏览次数:20796 次

求一sql的正则
SELECT t.organization_id, t.rtl_loc_id FROM hrs_employee t WHERE t.organization_id = 16 AND t.rtl_loc_id = 19 AND (t.start_date <= to_date('2011-08-30T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS')) AND (t.end_date <= to_date('2011-08-31T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS'))

转换成 SELECT t.organization_id, t.rtl_loc_id FROM hrs_employee t WHERE t.organization_id = 16 AND t.rtl_loc_id = 19 AND (t.start_date <= '2011-08-30T00:00:00') AND (t.end_date <= '2011-08-31T00:00:00')

------解决方案--------------------
C# code
Regex reg = new Regex(@"to_date\((\'\d{4}(-\d{2}){2}T(\d{2}:){2}\d{2}\'),\s*\'YYYY\s*-\s*MM\s*-\s*DD\\""T\\""HH24:MI:SS\'");
            string result = reg.Replace(input, reg.Match(input).Groups[1].Value);

------解决方案--------------------
探讨

看错了,连to_date也要去掉
Java code
tring sql = "...";
sql = sql.replaceAll("(?i)to_date[(]\\s*('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}')\\s*[,]\\s*'YYYY-MM-DD\"T\"HH24:MI:SS'", "$1");
System.out.println……

------解决方案--------------------
给个完整的
Java code
String sql = "SELECT t.organization_id, t.rtl_loc_id FROM hrs_employee t WHERE t.organization_id = 16 AND t.rtl_loc_id = 19 AND (t.start_date <= to_date('2011-08-30T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS')) AND (t.end_date <= to_date('2011-08-31T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS'))";
sql = sql.replaceAll("(?i)(.*?)to_date[(]\\s*('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}')\\s*[,]\\s*'YYYY-MM-DD\"T\"HH24:MI:SS'\\s*[)]", "$1$2");
System.out.println(sql);

------解决方案--------------------
Java code
String sql = "SELECT t.organization_id, t.rtl_loc_id FROM hrs_employee t WHERE t.organization_id = 16 AND t.rtl_loc_id = 19 AND (t.start_date <= to_date('2011-08-30T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS')) AND (t.end_date <= to_date('2011-08-31T00:00:00', 'YYYY-MM-DD\"T\"HH24:MI:SS'))";
sql = sql.replaceAll("(?i)(.*?)to_date[(]\\s*('\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}')\\s*[,]\\s*'YYYY-MM-DD\"T\"HH24:MI:SS'\\s*[)]", "$1$2");
System.out.println(sql);