1

The data contains a series of names of the format:

ABC123456 XYZ987654 DE-234567

The query

select distinct(substring(field, '([A-Z]{1,3})')) pref, count(*) tot from table;

identifies entries with characters. The question is: what is the escape character pull the '-' character along with the alpha characters. The '-' character is used in the select character sequence [A-Z]. How can that selection sequence be extended to include the '-' character.

1
  • distinct is NOT a function Commented Jun 4, 2016 at 16:30

1 Answer 1

1

The '-' character is used in the select character sequence [A-Z]

Dash - is interpreted as a range only when it is in the middle of other characters. If you put it at the beginning or at the end of a character class, it becomes just a regular character:

select distinct(substring(field, '([A-Z-]{1,3})')) pref, count(*) tot from  table;
--                                     ^

[-A-Z] would work as well.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.