【问题标题】:MYSQL: multiple functions in query StringMYSQL:查询字符串中的多个函数
【发布时间】:2015-08-13 16:23:55
【问题描述】:

以下查询在 MYSql(触发器)中不起作用

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),0,5)

只有当我删除 SUBSTR 时,它才会给我一个正确的输出

set new.uniq = md5(concat(new.lat, '-', new.lon))

【问题讨论】:

  • 拜托,你能把new.uniqnew.latnew.lon做什么吗?
  • 如果你想要最左边的字符,你可以使用LEFT函数代替SUBSTR。例如,如果你想要最左边的五个字符LEFT(expr,5)

标签: mysql substring substr


【解决方案1】:

问题是零:

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),0,5)
                                                         ^

例如:

SELECT SUBSTR('whatever', 0, 5) --> returns empty string
SELECT SUBSTR('whatever', 1, 5) --> returns 'whate'

把零改成1就可以了:

set new.uniq = SUBSTR(md5(concat(new.lat, '-', new.lon)),1,5)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多