簡體   English   中英

選擇僅字母,長度為三個字符的字符串

[英]Select alphabetic only strings of three characters length

我的表中有一個varchar字段,包含字母,數字和混合字母數字值。

我想只選擇該字段中長度為3個字符且僅按字母順序排列的值。

我正在使用oracle。

樣本數據:

AAA
BBB
12345
CCC25
DDDDD

select語句應該只返回:

AAA
BBB

我嘗試了以下內容,但沒有奏效。 這沒有任何回報。

select name from MyTable where name like '[a-Z][a-Z][a-Z]';

然后,我嘗試了以下方法,以為它會返回所有3個字符的長結果,而它只會返回所有內容:

select name from MyTable where name like '%%%';

您可以使用regexp_like函數

SQL> with x as (
  2    select 'aaa' str from dual union all
  3    select 'bbb' from dual union all
  4    select '12345' from dual union all
  5    select 'CCC25' from dual union all
  6    select 'DDDDD' from dual
  7  )
  8  select *
  9    from x
 10   where regexp_like( str, '^[[:alpha:]]{3}$' );

STR
-----
aaa
bbb

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM