Use MySQL functions to determine the video extension code

Source: Internet
Author: User
Tags mysql functions
MySQL has powerful user-defined functions, as shown below. I wrote a MySQL function to determine whether the video address can be played on the mobile phone.

MySQL has powerful user-defined functions, as shown below. I wrote a MySQL function to determine whether the video address can be played on the mobile phone.

The Code is as follows:
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;

Note:
This method has application scenarios. I used to make a tag in the creation of the sphinx index, for example:

SELECT IS_MOBILE ('HTTP: // www.jb51.net/demo/test.mp4') AS m
If the front-end is used in large quantities, the MySQL pressure will be increased. It is recommended that the script program be used.
I personally only have a temporary solution, which will be completed by upgrading the system later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.