【问题标题】:How to convert string value into number如何将字符串值转换为数字
【发布时间】:2019-05-20 03:44:01
【问题描述】:

我的桌子是 这里Loan_Time 字段是string 字段。我希望它转换为数字

||Loan_Time  ||   || Approve_amt||
|| 3 Year    ||   ||      15000.00||

我想要这样的

||Loan_Time|| ||Approve_amt||
||   36    || ||15000.00||

我该怎么做?

【问题讨论】:

  • @YCF_L 它可以如果你把它转换成月

标签: java postgresql-9.2


【解决方案1】:

你可以的

UPDATE table SET Loan_time=SUBSTR(SUBSTRING_INDEX(Loan_time, ' Year', 1), 1, 2)*12

请在测试服务器上测试该命令以确保它按预期工作。我已经占了大于 9 的年数

【讨论】:

    【解决方案2】:

    您可以使用模式匹配:

    String original = "3 Year";
    int months = 0;
    Matcher m = Pattern.compile("(\\d+)\\s.+").matcher(original);
    if (m.find()) {
        months = 12 * Integer.parseInt(m.group(1));
    }
    System.out.println(months); //update the DB with these months
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-09
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多