Constant Learner
Constant Learner

Reputation: 525

REGEX_LIKE not selecting correct result

I am trying to select numbers starting with one + character and having only digits afterward from a varchar column. I have used the regex_like operator but it also selects special character in the result.

Expected Correct value:

+369
+6589445
+5896552

Wrong:

693
+4534dfgfgf#
+3435435*%

I tried,

SELECT Column FROM Table WHERE REGEXP_LIKE(Column , '^[+][0-9]');

Upvotes: 3

Views: 46

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626893

To select values starting with + and then 1 or more digits, use

^[+][0-9]+$
         ^^

The $ will force the end-of-string boundary and + will allow matching 1 or more occurrences of the construct the plus quantifies (the [0-9] character class).

Here is a demo showing how this regex works.

Upvotes: 5

Related Questions