SQL to get only a string with leading numbers

I think this is pretty simple. I would only like to return the string values ​​that bind the leading numbers in my query results.

For instance:

003 - Preliminary Examination Plan 005 - Coordination 1000a - Balance sheet Advertising Amortization Partnerships 

I would like to receive:

 003 - Preliminary Examination Plan 005 - Coordination 1000a - Balance sheet 

This code gave me zero results. How to check if leading numbers contain digits and return the rest of the string?

 select distinct AIssue from SQLIssue where regexp_like( AIssue, '^[[:digit:]]*$' ) order by AIssue 
+4
source share
3 answers

Your current regex requires the string to consist entirely of numbers. Try the following:

 where regexp_like( AIssue, '^[[:digit:]].*$' ) 

(pay attention to the added point).

To develop,. matches any character, and * means "repeat the previous term zero or more times."

Thus, the original regular expression says “zero or more digits”, while the above expression says “digit, followed by zero or more of any characters.

edit . A shorter version of the above regex was suggested by @mellamokb in the comments:

 where regexp_like( AIssue, '^[[:digit:]]' ) 
+6
source

If you are using SQL Server, try the following:

 select distinct Issue from SQLIssue where AIssue LIKE '[0-9]%' order by AIssue 

See the documentation for LIKE

+1
source

Another solution, but not related to regular expressions:

 select distinct Issue from SQLIssue where substr(AIssue, 1, 1) between '0' and '9' order by AIssue 
+1
source

Source: https://habr.com/ru/post/1414184/


All Articles