search

Home  >  Q&A  >  body text

mysql - 如何在sql语句中判断一个字段(内容为文件的路径)里面的文件后缀名?求大神告知,不会啊

PHPzPHPz2781 days ago637

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:37:37

    MYSQL:

    SELECT RIGHT(RTRIM(@Path), LOCATE('.',REVERSE(RTRIM(@Path))) - 1)

    SQLSERVER:

    SELECT RIGHT(RTRIM(@Path), CHARINDEX('.',REVERSE(RTRIM(@Path))) - 1)

    Assume the @Path placeholder is your field. Idea: To find the last character ., reverse it and find the position of the first ., and then go to the original string to intercept the characters after ..

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:37:37

    I don’t have MySQL at hand, but you can do this in Oracle:

    select substr(PATH, instr(PATH, '.') + 1) from 表名

    As for MySQL, you can just check if there are corresponding functions.

    reply
    0
  • Cancelreply