![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have the following details in a file: (ADDRESS = (CITY_DETAILS = (STREET# = 416) (STREET_NAME = UNITY BLVD.) (CITY = AUSTIN)) (STATE_DETAILS = (STATE_NAME = TEXAS)(ZIPCODE = 12345))) I need to pull word after the word STATE_NAME. In this case it is TEXAS. The required word will be enclosed within '=' and ')'. These are multiple line rows. How to do this using regular expressions in Oracle 10g please ? Thanx -GC |
#3
| |||
| |||
|
|
Hi, I have the following details in a file: (ADDRESS = (CITY_DETAILS = (STREET# = 416) (STREET_NAME = UNITY BLVD.) (CITY = AUSTIN)) (STATE_DETAILS = (STATE_NAME = TEXAS)(ZIPCODE = 12345))) I need to pull word after the word STATE_NAME. In this case it is TEXAS. The required word will be enclosed within '=' and ')'. These are multiple line rows. How to do this using regular expressions in Oracle 10g please ? Thanx -GC |
#4
| |||
| |||
|
|
admin (AT) rbtron (DOT) com schrieb: Hi, I have the following details in a file: (ADDRESS = (CITY_DETAILS = (STREET# = 416) (STREET_NAME = UNITY BLVD.) (CITY = AUSTIN)) (STATE_DETAILS = (STATE_NAME = TEXAS)(ZIPCODE = 12345))) I need to pull word after the word STATE_NAME. In this case it is TEXAS. The required word will be enclosed within '=' and ')'. These are multiple line rows. How to do this using regular expressions in Oracle 10g please ? Thanx -GC Somewhat like this ? SQL> with t as ( 2 select '(ADDRESS = 3 (CITY_DETAILS = (STREET# = 416) 4 (STREET_NAME = 5 UNITY BLVD.) 6 (CITY = AUSTIN)) 7 (STATE_DETAILS = (STATE_NAME = 8 TEXAS)(ZIPCODE = 12345)))' s 9 from dual) 10 select 11 regexp_replace(s,'.*STATE_NAME\s*=\s*(\w+).*','\1' ,1,1,'mn') rr 12 from t 13 ; RR ----- TEXAS Best regards Maxim |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Awesome answers! ... Thanks a lot ... just one more thing: Sometimes the file will have : (STATE_DETAILS = (STATE_NAME = * * * * * * * * * * * * * * * * * * * TEXAS)(ZIPCODE = 12345)) or (STATE_DETAILS = (TERRITORY = * * * * * * * * * * * * * * * * * * * TEXAS)(ZIPCODE = 12345)) So how to find the word after : either STATE_NAME or TERRITORY ? Thanx once again! -GC |
#7
| |||
| |||
|
|
On Feb 9, 3:35 pm, ad... (AT) rbtron (DOT) com wrote: Awesome answers! ... Thanks a lot ... just one more thing: Sometimes the file will have : (STATE_DETAILS = (STATE_NAME = TEXAS)(ZIPCODE = 12345)) or (STATE_DETAILS = (TERRITORY = TEXAS)(ZIPCODE = 12345)) So how to find the word after : either STATE_NAME or TERRITORY ? Thanx once again! -GC Ok, I got that boolean part ... I modified it to [STATE_NAME | TERRITORY] and it worked fine ... Two other things: 1) Some files have Territory as US.TEXAS ... in such cases, the script outputs only US not US.TEXAS 2) Some files don't have STATE_NAME or TERRITORY in them. I need to output the word NULL in such cases. Thanks! |
#8
| |||
| |||
|
|
ad... (AT) rbtron (DOT) com schrieb: On Feb 9, 3:35 pm, ad... (AT) rbtron (DOT) com wrote: Awesome answers! ... Thanks a lot ... just one more thing: Sometimes the file will have : (STATE_DETAILS = (STATE_NAME = * * * * * * * * * * * * * * * * * * * TEXAS)(ZIPCODE = 12345)) or (STATE_DETAILS = (TERRITORY = * * * * * * * * * * * * * * * * * * * TEXAS)(ZIPCODE = 12345)) So how to find the word after : either STATE_NAME or TERRITORY ? Thanx once again! -GC Ok, I got that boolean part ... I modified it to [STATE_NAME | TERRITORY] and it worked fine ... Two other things: 1) Some files have Territory as US.TEXAS ... in such cases, the script outputs only US not US.TEXAS 2) Some files don't have STATE_NAME or TERRITORY in them. I need to output the word NULL in such cases. Thanks! SQL> set NULL NULL SQL> with t as ( * *2 *select '(ADDRESS = * *3 * * * * *(CITY_DETAILS = * *(STREET# = 416) * *4 * * * * * * * * * * * *(STREET_NAME = * *5 * * * * * * * * * * * *UNITY BLVD.) * *6 * * * * * * * * * * * *(CITY = AUSTIN)) * *7 * * * * *(STATE_DETAILS = (STATE_NAME = * *8 * * * * * * * * * * * * * * * * * * * *TEXAS)(ZIPCODE = 12345)))' s * *9 *from dual union all * 10 *select '(ADDRESS = * 11 * * * * *(CITY_DETAILS = * *(STREET# = 416) * 12 * * * * * * * * * * * *(STREET_NAME = * 13 * * * * * * * * * * * *UNITY BLVD.) * 14 * * * * * * * * * * * *(CITY = AUSTIN)) * 15 * * * * *(STATE_DETAILS = (TERRITORY = * 16 * * * * * * * * * * * * * * * * * * * *US.TEXAS)(ZIPCODE = 12345)))' s * 17 *from dual union all * 18 *select '(ADDRESS = * 19 * * * * *(CITY_DETAILS = * *(STREET# = 416) * 20 * * * * * * * * * * * *(STREET_NAME = * 21 * * * * * * * * * * * *UNITY BLVD.) * 22 * * * * * * * * * * * *(CITY = AUSTIN)) * 23 * * * * *(STATE_DETAILS = (STATE_NAM = * 24 * * * * * * * * * * * * * * * * * * * *TEXAS)(ZIPCODE = 12345)))' s * 25 *from dual * 26 *) * 27 *select * 28 *nullif( * 29 * * *regexp_replace(s, * 30 * * * * *'.*(STATE_NAME|TERRITORY)\s*=\s*((\w|\.)+).*', * 31 * * * * *'\2', * 32 * * * * *1, * 33 * * * * *1, * 34 * * * * *'mn'),s * 35 * * *) rr * 36 *from t * 37 *; RR ---------------------------------------------------------------------------*-------------------------------------------------- TEXAS US.TEXAS NULL If your client is not sqlplus, wrap whole expression into nvl Best regards Maxim- Hide quoted text - - Show quoted text - |
#9
| |||
| |||
|
|
ad... (AT) rbtron (DOT) com schrieb: Hi, I have the following details in a file: (ADDRESS = * * * * (CITY_DETAILS = * *(STREET# = 416) * * * * * * * * * * * (STREET_NAME = * * * * * * * * * * * UNITY BLVD.) * * * * * * * * * * * (CITY = AUSTIN)) * * * * (STATE_DETAILS = (STATE_NAME = * * * * * * * * * * * * * * * * * ** TEXAS)(ZIPCODE = 12345))) I need to pull word after the word STATE_NAME. In this case it is TEXAS. The required word will be enclosed within '=' and ')'. These are multiple line rows. How to do this using regular expressions in Oracle 10g please ? Thanx -GC Somewhat like this ? SQL> with t as ( * *2 *select '(ADDRESS = * *3 * * * * *(CITY_DETAILS = * *(STREET# = 416) * *4 * * * * * * * * * * * *(STREET_NAME = * *5 * * * * * * * * * * * *UNITY BLVD.) * *6 * * * * * * * * * * * *(CITY = AUSTIN)) * *7 * * * * *(STATE_DETAILS = (STATE_NAME = * *8 * * * * * * * * * * * * * * * * * * * *TEXAS)(ZIPCODE = 12345)))' s * *9 *from dual) * 10 *select * 11 *regexp_replace(s,'.*STATE_NAME\s*=\s*(\w+).*','\1 ',1,1,'mn') rr * 12 *from t * 13 *; RR ----- TEXAS Best regards Maxim Maxim, |
#10
| |||
| |||
|
|
On 9 Feb, 18:17, Maxim Demenko <mdeme... (AT) gmail (DOT) com> wrote: ad... (AT) rbtron (DOT) com schrieb: Hi, I have the following details in a file: (ADDRESS = * * * * (CITY_DETAILS = * *(STREET# = 416) * * * * * * * * * * * (STREET_NAME = * * * * * * * * * * * UNITY BLVD.) * * * * * * * * * * * (CITY = AUSTIN)) * * * * (STATE_DETAILS = (STATE_NAME = * * * * * * * * * * * * * * * * * * * TEXAS)(ZIPCODE = 12345))) I need to pull word after the word STATE_NAME. In this case it is TEXAS. The required word will be enclosed within '=' and ')'. These are multiple line rows. How to do this using regular expressions in Oracle 10g please ? Thanx -GC Somewhat like this ? SQL> with t as ( * *2 *select '(ADDRESS = * *3 * * * * *(CITY_DETAILS = * *(STREET# = 416) * *4 * * * * * * * * * * * *(STREET_NAME = * *5 * * * * * * * * * * * *UNITY BLVD.) * *6 * * * * * * * * * * * *(CITY = AUSTIN)) * *7 * * * * *(STATE_DETAILS = (STATE_NAME = * *8 * * * * * * * * * * * * * * * * * * * *TEXAS)(ZIPCODE = 12345)))' s * *9 *from dual) * 10 *select * 11 *regexp_replace(s,'.*STATE_NAME\s*=\s*(\w+).*','\1 ',1,1,'mn') rr * 12 *from t * 13 *; RR ----- TEXAS Best regards Maxim Maxim, Would you mind explaining how the REGEXP_REPLACE function is working in your example, please? *I am familiar with regular expressions but only on a fairly basic level. Cheers, -g |
![]() |
| Thread Tools | |
| Display Modes | |
| |