[英]SQL pattern search
What 'where' stmt can I use to locate and return values from field cfmesg where the field content is a number followed by hyphen?我可以使用什么 'where' stmt 从字段 cfmesg 中定位和返回值,其中字段内容是数字后跟连字符?
sample data
087-2-1-11
56-080
040-4-2-60
You can try this query你可以试试这个查询
Select * From [TableName] Where [ColumnName] LIKE '%[0-9]-%' Select * 来自 [TableName] Where [ColumnName] LIKE '%[0-9]-%'
"[0-9]-" will look for numbers followed by a hyphen. "[0-9]-" 将查找后跟连字符的数字。
You can use REGEXP_LIKE
and use a regular expression to find that pattern:您可以使用
REGEXP_LIKE
并使用正则表达式来查找该模式:
WITH YOUR_TABLE AS (
SELECT '087-2-1-11' AS CFMESG
FROM sysibm.sysdummy1
UNION
SELECT '56-080'
FROM sysibm.sysdummy1
UNION
SELECT 'abcd'
FROM sysibm.sysdummy1
)
SELECT * FROM YOUR_TABLE
WHERE REGEXP_LIKE(CFMESG, '\d-')
CFMESG ![]() |
---|
087-2-1-11 ![]() |
56-080 ![]() |
I guess it depends on what you are looking for.我想这取决于你在寻找什么。 If you want to find all lines with a '-' in the value then you would run something like this:
如果您想查找值中带有“-”的所有行,那么您将运行如下内容:
select * from table where locate('-', cfmesg) > 1
If you are looking for something more specific where the beginning part only contains numbers then you'll want something like this:如果您正在寻找更具体的开头部分仅包含数字的内容,那么您将需要这样的内容:
select * from table where REGEXP_LIKE(cfmesg, '^\d+-')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.