Home > Net >  select where only have 8 digit number
select where only have 8 digit number

Time:12-15

I have question about how tow select serialnumber with condition just have 8 digit number. For example :

12345678

12343546565

43764374

23728328372873

I just want select serial number 12345678 & 43764374. So how can I match select only just serialnumber has 8 digit number

Thanks in advance

CodePudding user response:

This depends a bit on which kind of database you have, but it will look something like this:

WHERE LEN(SerialNumber) = 8

or this:

WHERE CHAR_LENGTH(SerialNumber) = 8

CodePudding user response:

You could use this

SELECT serialnumber
FROM TABLENAME
WHERE LENGTH(serialnumber) = 2;

CodePudding user response:

With Bigquery you can do this:


WITH subtab AS 
(
SELECT [12345678,12343546565,43764374,23728328372873] AS serialnumber
)

SELECT serialnumber FROM subtab, UNNEST(subtab.serialnumber) as serialnumber
WHERE CHAR_LENGTH(CAST(serialnumber as string)) = 8

Results:

enter image description here

  •  Tags:  
  • sql
  • Related