SimpleIntelligence
asked on
Use REGEXP to help clean up POSTCODE field
Hi
I need to find invalid postcodes using REGEXP.
The valid formats are:
A9 9AA
AA99 9AA
AA9 9AA
A9A 9AA
AA9A 9AA
I need to find invalid postcodes using REGEXP.
The valid formats are:
A9 9AA
AA99 9AA
AA9 9AA
A9A 9AA
AA9A 9AA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
SELECT *--(premise.*)
FROM
(SELECT *
FROM ice1.premise
UNION ALL
SELECT *
FROM ice2.premise) premise
where NOT REGEXP_LIKE(postcode, '[a-z]{1,2}[a-z]{0,1}[0-9] {1,2} [0-9][a-z]{2} , i' )
I don't want it to return a postcode like
KW15LE
but that query above does. Any thoughts?
FROM
(SELECT *
FROM ice1.premise
UNION ALL
SELECT *
FROM ice2.premise) premise
where NOT REGEXP_LIKE(postcode, '[a-z]{1,2}[a-z]{0,1}[0-9]
I don't want it to return a postcode like
KW15LE
but that query above does. Any thoughts?
This regex accepts AA99A 9AA. So the regular expression may be like this [a-z]{1,2}[0-9]([0-9]|[a-z]){0,1} [0-9][a-z]{2}
ASKER
Hi Vishnu
Thanks for looking at this question. In order for me to understand this function, can you show me the expression that would identify:
KW1 5LE
Thanks for looking at this question. In order for me to understand this function, can you show me the expression that would identify:
KW1 5LE
// can you show me the expression that would identify
sorry i can't get the question.... which expression you need.
sorry i can't get the question.... which expression you need.
ASKER
I want the postcode KW1 5LE to be picked up by the REGEXP function.
[A-Z]{2}[0-9] [0-9][A-Z]{2}
ASKER
Its still not picking up
KW1 5LE
KW1 5LE
Could you please send your query that you have executed...
please change the [A-Z] as [[:alpha:]]. This accepts both lower and upper case. please put ^ in the beging of the regular exp and $ for last.
'^[[:alpha:]]... $'
ASKER
I am trying to identify bad data. So I want to show postcodes that DO NOT adhere to the standard postcode format. Here is your code. But a postcode like KW1 5LE DOES appear which means the filter is not filtering out the good postcode.
SELECT *
FROM (SELECT *
FROM ice1.premise
UNION ALL
SELECT *
FROM ice2.premise) premise
where NOT REGEXP_LIKE(postcode, '[A-Z]{2}[0-9] [0-9][A-Z]{2}, i' )
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It did not completely solve the problem but sent me on my way.
ASKER