像整数运算符 [英] Like operator for integer

查看:33
本文介绍了像整数运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有一个 bigint (ProductSerial) 类型的列.我需要使用 like 运算符按产品序列过滤表.但我发现,像运算符不能用于整数类型.

I have a column of type bigint (ProductSerial) in my table. I need to filter the table by the Product serial using like operator. But I found that, like operator can't be used for integer type.

有没有其他方法可以做到这一点(我不想使用 = 运算符).

Is there any other method for this (I don't want to use the = operator).

推荐答案

如果你必须使用LIKE,你可以将你的号码转换为char/varchar,并对结果执行 LIKE.这是非常低效的,但由于 LIKE 无论如何都有很大的可能杀死索引,因此它可能适用于您的场景:

If you must use LIKE, you can cast your number to char/varchar, and perform the LIKE on the result. This is quite inefficient, but since LIKE has a high potential of killing indexes anyway, it may work in your scenario:

... AND CAST(phone AS VARCHAR(9)) LIKE '%0203'

如果您希望使用 LIKE 来匹配数字的开头或结尾,您可以使用整数除法和取模运算符来提取数字.例如,如果您想要所有以 407 开头的九位数字,请搜索

If you are looking to use LIKE to match the beginning or the end of the number, you could use integer division and modulus operators to extract the digits. For example, if you want all nine-digit numbers starting in 407, search for

phone / 1000000 = 407

这篇关于像整数运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆