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

Revision as of 16:29, 24 August 2016

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
);