在oracle中使用正则表达式查找POBOX - PL / SQL

时间:2015-12-09 13:07:28

标签: regex oracle plsql

我想在oracle-PL / SQL中使用正则表达式从单词POBOX之后出现的字符串中提取pobox值。 以下是一些例子 I / P

1. COMPANY (W L L ) POBOX - 24440 DOHA QATAR TEL 4765888
2. STAR LIMITED POBOX PO KHUPARI PO KHUPARI, TQ-WADA,DIST-THANE 421312INDIA
3. LENNOX ACCOUNT POBOX - N-4875 SD- THE BAHAMAS
4. MEDHIN WEREDA 13, ADDIS ABABA, ETHIOPIA, POBOX- 1110-1668 //UA
5. UHTHOFF, SC POBOX M-2059 06000 MEXICO  
6. PHARMACIE AKWABA POBOX AVENUE ESPEREY 00000 ABIDJAN 45 (COTE D IVOIRE),
7. CAAS POBOX 1 .//SG 
8. CORAL TECH PETER MAYNARD CO BAY DEVEAUX STREETS 2ND FLOOR POBOX N-1000 
9. GULF OCEAN CENTRE - MONTAGU FORESHORE EAST BAY STREET POBOX SS -19084
10. AHMED SAEED DAMMAM 2044 31453 POBOX 011383-KSA 
11. MISR COMPRESSOR (CO) 10 TH OF INDUSTRIAL ZONE A-2 POBOX 1001
12. NOKIA AND NETWORKS OY C/O NSN FRANCE POBOX1 3 KARAPORTII
13. HEWLETT PACKARD EUROP BV POBOX 100- POBOX 100-CH-1217
14. DUMONT BERGMAN BIDER + CO., S.C. POBOX456 DELEGACION CUAUHTEMO MX

O / P

1. 24440
2. 421312
3. 4875
4. 1110-1668
5. 2059
6. 00000
7. 1
8. 1000
9. 19084
10. 011383
11. 1001
12. 1
13. 100
14. 456

1 个答案:

答案 0 :(得分:1)

这样的事可能会帮助你:

WITH the_table AS (SELECT '1. COMPANY (W L L ) POBOX - 24440 DOHA QATAR TEL 4765888' line FROM dual
                   UNION
                   SELECT '2. STAR LIMITED POBOX PO KHUPARI PO KHUPARI, TQ-WADA,DIST-THANE 421312INDIA' FROM dual
                   UNION
                   SELECT '3. LENNOX ACCOUNT POBOX - N-4875 SD- THE BAHAMAS' FROM dual
                   UNION
                   SELECT '4. MEDHIN WEREDA 13, ADDIS ABABA, ETHIOPIA, POBOX- 1110-1668 //UA' FROM dual
                   UNION
                   SELECT '5. UHTHOFF, SC POBOX M-2059 06000 MEXICO' FROM dual
                   UNION
                   SELECT '6. PHARMACIE AKWABA POBOX AVENUE ESPEREY 00000 ABIDJAN 45 (COTE D IVOIRE),' FROM dual
                   UNION
                   SELECT '7. CAAS POBOX 1 .//SG' FROM dual
                   UNION
                   SELECT '8. CORAL TECH PETER MAYNARD CO BAY DEVEAUX STREETS 2ND FLOOR POBOX N-1000' FROM dual
                   UNION
                   SELECT '9. GULF OCEAN CENTRE - MONTAGU FORESHORE EAST BAY STREET POBOX SS -19084' FROM dual
                   UNION
                   SELECT '10. AHMED SAEED DAMMAM 2044 31453 POBOX 011383-KSA' FROM dual
                   UNION
                   SELECT '11. MISR COMPRESSOR (CO) 10 TH OF INDUSTRIAL ZONE A-2 POBOX 1001' FROM dual
                   UNION
                   SELECT '12. NOKIA AND NETWORKS OY C/O NSN FRANCE POBOX1 3 KARAPORTII' FROM dual
                   UNION
                   SELECT '13. HEWLETT PACKARD EUROP BV POBOX 100- POBOX 100-CH-1217' FROM dual
                   UNION
                   SELECT '14. DUMONT BERGMAN BIDER + CO., S.C. POBOX456 DELEGACION CUAUHTEMO MX' FROM dual)                   
SELECT line, REGEXP_SUBSTR(line,'(.+?)(POBOX.*?)([0-9]([0-9\-]*[0-9])?)(.+)?',1,1,null,3) pobox
FROM the_table 
ORDER BY to_number(replace(substr(line,1,2),'.'))