简体   繁体   English

SQL中的模式匹配

[英]Pattern matching in SQL

I have a SQL database column for uploaded content Mime types . 我有一个SQL数据库列,用于上传内容Mime类型 This column contains string values in the form: 此列包含以下形式的字符串值:

image/jpeg
image/gif
video/mpeg
video/mp4

Is there a SQL query where I can select all rows with the 'image' prefix? 是否有SQL查询可在其中选择所有带有“图像”前缀的行? Or do I have to hard code each value? 还是我必须对每个值进行硬编码?

WHERE mime_type IN ('image/png','image/gif', ... ) 在哪里mime_type IN('image / png','image / gif',...)

Hard coding these values will make the script hard to maintain when future mime types are declared. 声明未来的mime类型时,对这些值进行硬编码将使脚本难以维护。 The database already filters on input but adding a new column for grouping is out of my hands. 数据库已经根据输入进行过滤,但是我无法添加新的分组列。

WHERE mime_type LIKE 'image%'

As simple as that. 就如此容易。 % acts as a wildcard. %用作通配符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM