Home >Database >Mysql Tutorial >利用MySQL函数实现判断视频扩展名的代码_MySQL

利用MySQL函数实现判断视频扩展名的代码_MySQL

WBOY
WBOYOriginal
2016-06-01 13:22:411032browse

bitsCN.com
delimiter ||

DROP FUNCTION IF EXISTS IS_MOBILE||
CREATE FUNCTION IS_MOBILE( x VARCHAR(255)) RETURNS TINYINT(1)
BEGIN
DECLARE result TINYINT(1) DEFAULT 0;
SET x = LCASE(x);
IF RIGHT(x,4) = '.mp4' THEN
SET result = 1;
ELSEIF LEFT(x,9) = '[ctvideo]' THEN
SET result = 1;
END IF;
RETURN result;
END;

delimiter ;

注:
这种方法是有应用场景的,我是用来在建立sphinx索引中做一个标记如:

SELECT IS_MOBILE('http://www.bitsCN.com/demo/test.mp4') AS m
如果在前端大量使用,会增加MySQL的压力,建议还是由脚本程序完成。
我个人也仅时一个临时解决方案,后期会通过升级系统的方式用程序来完成。bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn