So, I have a list of plate numbers from different countries. If I want to filter Croatian plates, how can I do that? Croatian plate formats are like ZG 000-A, ZG 000-AA, ZG 0000-A or ZG 0000-AA. (Ignore the dashes)
I’ve tried several methods but can’t really filter the plates.
I have tried to filter according to first two letters that Croatia using and the plate lenght.
Assuming that you want:
^
)[A-Z]{2}
)
)[0-9]{3,4}
or \d{3,4}
)-?
)[A-Z]{1,2}
)$
).Then you can use a regular expression:
SELECT *
FROM table_name
WHERE REGEXP_LIKE(plate_number, '^[A-Z]{2} [0-9]{3,4}-?[A-Z]{1,2}$')
Which, for the sample data:
CREATE TABLE table_name (plate_number) AS
SELECT 'ZG 000-A' FROM DUAL UNION ALL
SELECT 'ZG 000-AA' FROM DUAL UNION ALL
SELECT 'ZG 0000-A' FROM DUAL UNION ALL
SELECT 'ZG 0000-AA' FROM DUAL UNION ALL
SELECT 'ABC00XY' FROM DUAL UNION ALL
SELECT '01234' FROM DUAL;
Outputs:
PLATE_NUMBER |
---|
ZG 000-A |
ZG 000-AA |
ZG 0000-A |
ZG 0000-AA |