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
Line 1: Line 1:
<code>select</code><br/>
select
&nbsp;&nbsp;<code>text,</code><br/>
  text,
&nbsp;&nbsp;<code>case </code><br/>
  case  
&nbsp;&nbsp;&nbsp;&nbsp;<code>when REGEXP_LIKE (trim(text), '^[0-9]*$') then 'Yes'</code><br/>
    when REGEXP_LIKE (trim(text), '^[0-9]*$') then 'Yes'
&nbsp;&nbsp;&nbsp;&nbsp;<code>else 'No'</code><br/>
    else 'No'
&nbsp;&nbsp;<code>end "Only numbers ?"</code><br/>
  end "Only numbers ?"
<code>from(</code><br/>
from(
&nbsp;&nbsp;<code>select '19051989' text from dual</code><br/>
  select '19051989' text from dual
&nbsp;&nbsp;<code>union</code><br/>
  union
&nbsp;&nbsp;<code>select '19 mai 1989' text from dual</code><br/>
  select '19 mai 1989' text from dual
<code>);</code>
);

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

);