基于位数的sql查询

zlhcx6iw  于 2021-08-01  发布在  Java
关注(0)|答案(2)|浏览(246)

sql新手。
我试图把所有的记录,其中“客户号码”是一个12位数字。在“客户编号”列中,只有9位或12位数字。我只需要客户谁的“客户号码”是12位数字。似乎很直截了当,但没能弄明白。
谢谢

doinxwow

doinxwow1#

你可以用 len() / length() (取决于您的数据库):

select t.*
from t
where len(customer_number) = 12

你也可以使用 like :

where customer_number like '____________'  -- exactly 12 underscores
wbrvyc0a

wbrvyc0a2#

select customer_num from
xx_customers
where length(customer_num)=12;
``` `Length` 函数可用于where条件

相关问题