Difference between revisions of "SQL - Check with regex if the string text is only composed of numbers"

From GUILLARD WIKI
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<code>select</code><br/>
<syntaxhighlight lang="sql">
&nbsp;&nbsp;<code>text,</code><br/>
select
&nbsp;&nbsp;<code>case </code><br/>
  text,
&nbsp;&nbsp;&nbsp;&nbsp;<code>when REGEXP_LIKE (trim(text), '^[0-9]*$') then 'Yes'</code><br/>
  case  
&nbsp;&nbsp;&nbsp;&nbsp;<code>else 'No'</code><br/>
    when REGEXP_LIKE (trim(text), '^[0-9]*$') then 'Yes'
&nbsp;&nbsp;<code>end "Only numbers ?"</code><br/>
    else 'No'
<code>from(</code><br/>
  end "Only numbers ?"
&nbsp;&nbsp;<code>select '19051989' text from dual</code><br/>
from(
&nbsp;&nbsp;<code>union</code><br/>
  select '19051989' text from dual
&nbsp;&nbsp;<code>select '19 mai 1989' text from dual</code><br/>
  union
<code>);</code>
  select '19 mai 1989' text from dual
);
</syntaxhighlight>

Latest revision as of 10:10, 13 April 2018

select
  text,
  case 
    when REGEXP_LIKE (trim(text), '^[0-9]*$') then 'Yes'
    else 'No'
  end "Only numbers ?"
from(
  select '19051989' text from dual
  union
  select '19 mai 1989' text from dual
);