阿里云sql配置单元,sql只排除数字和字母,只排除单个中文单词

ycggw6v2  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(230)

我有下面这样一个专栏


**col1**

1244
a888d
ahahd
我
我是
19mon

我想要的结果是


**col1**

a888d
我是
19mon

我试着用下面的语法来排除数字和字母表,但是没有字符串被打印出来。我不知道怎么排除一个中文单词,比如“我" 上面。

SELECT col1 from abc
where col1 like '%[^0-9.]%' AND col1 like '%[^a-zA-Z.]%'

有什么办法解决这个问题吗?谢谢您!

xwmevbvl

xwmevbvl1#

使用正则表达式:

with your_data as (
select stack(6,
'1244',
'a888d',
'ahahd',
'我',
'我是',
'19mon'
) as col1
) 

select col1 from your_data
 where col1 not rlike ('^\\d+$')      --not digits only
   and col1 not rlike ('^[a-zA-Z]+$') --not alpha only
   and length(col1) !=1;              --not single char (digit and alpha filtered already)

退货:

col1    
a888d   
我是  
19mon

演示:http://demo.gethue.com/hue/editor?editor=324999

tvmytwxo

tvmytwxo2#

你可以尝试以下方法:

SELECT *
FROM abc
WHERE LOWER(col1) != UPPER(col1) -- COLLATE Latin1_General_CS_AS SQL Server specific
  OR (LENGTH(col1) != 1 AND col1 like '%[^a-zA-Z.0-9]%');

db<>小提琴演示

相关问题