• oracle to_date批量替换


    具体问题具体分析,本案例仅供参考。

    问题:

    因需求要大量替换类型以下sql语句:

    INSERT INTO test VALUES ('test', NULL, to_date('2021-01-04 20:42:17', to_date('2021-01-04 20:42:17',null;
    INSERT INTO test VALUES ('test', NULL, to_date('2021-01-04 20:42:17', to_date('2021-01-04 20:42:17',null;

    解决方案:

    正则替换相应字符:

    1.搜字符串在线转义,将sql转化为字符串

     2.编程C#程序

    using System.Text.RegularExpressions;
    
    var strs = "INSERT INTO test VALUES ('test', NULL, to_date('2021-01-04 20:42:17', to_date('2021-01-04 20:42:17',null);\n"
     + "INSERT INTO test VALUES ('test', NULL, to_date('2021-01-04 20:42:17', to_date('2021-01-04 20:42:17',null);";
    
    var ary = strs.Split(";");
    var matter = @"to_date\W+\S*\w\s[0-9]+:[0-9]+:[0-9]+\S+";
    var regex = new Regex(matter);
    var result = regex.Matches(strs).Select(p => p.Value).Distinct().ToList();
    for (int j = 0; j < result.Count; j++)
    {
        strs = strs.Replace(result[j], ", " + result[j] + "'yyyy-mm-dd hh24:mi:ss'),");
    
    }
    
    
    var newStrs = strs.Replace(", , to_date(", ", to_date(");
    Console.WriteLine(newStrs);
    Console.ReadKey();

    3.最终结果:

  • 相关阅读:
    JAVA语法之小结
    JAVA之经典Student问题1
    Android之动画1
    Android之屏幕测试
    Android之点击切换图片
    Android之标签选项卡
    Android简单计算器
    Javascript之相册拖动管理
    Javascript之改变盒子颜色
    CSS之照片翻转
  • 原文地址:https://www.cnblogs.com/Zhengxue/p/16020317.html
Copyright © 2020-2023  润新知