php 如何从mysql数据库字段中检索最后4个字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5467336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:32:04  来源:igfitidea点击:

How to retrieve the last 4 characters from a mysql database field?

phpmysqlsubstr

提问by Toni Michel Caubet

In order to be able to simulate substr from PHP and mysql, I want to do something like

为了能够从 PHP 和 mysql 模拟 substr,我想做一些类似的事情

select * from table where last_four_chars(field) = '.png'

回答by Frank Farmer

The docshave an example directly relevant to this.

文档有一个与此直接相关的示例。

select * from table where SUBSTRING(field, -4) = '.png'

回答by Vincent Savard

With RIGHT function :

具有正确的功能:

SELECT RIGHT('abcdefg', 3);
-- efg

You can achieve the same result with SUBSTRING :

您可以使用 SUBSTRING 获得相同的结果:

SELECT SUBSTRING('abcdefg', -3);
-- efg

回答by Ferhat KO?ER

This Fast query:

这个快速查询:

Select * from table where picName like '%.png'

回答by therealsix

SELECT * FROM table WHERE SUBSTRING( field, -4 ) = '.png'