Getting parts of a string (using regexp_instr, REVERSE, ...)
915879Mar 27 2012 — edited Mar 29 2012Hi,
I'm trying to alter our company's existing procedure, so that it can extract the Nr of the house, and the bus ('mailbox') from the field "pio_address.street_nr_bus".
Now, if the input is something simple like "Testlane 15 A", there's no problem ofcourse, but since the data comes from what people entered in a form (on our site for example), it can get really messy and the input might be like:
[streetpart1] [streetpart2] [streetpart 3] [NR] [NRpart2] [mailbox] ==> ex: "Test 2 Lane 15 B A"
So in that example, I'd like to get "15 B A" (being a combination of house-nr and mailbox-nr)
So what I've come op with for now (would love to simplify it though) is the following code; but the procedure takes 30 minutes to complete now (~7000 records), which seems rather long, especially since it used to last like 5-10 minutes.
Any ideas/tips?
---------------------------
code:
SELECT REGEXP_REPLACE(trim(REVERSE(pio_address.street_nr_bus)),' *',' ') INTO pio_address.street_nr_bus
FROM DUAL;
SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:digit:]INTO v_posnr FROM DUAL;
SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:alpha:]]', v_posnr) INTO v_posstreet FROM DUAL;
IF v_posstreet = 0 THEN
SELECT REVERSE(pio_address.street_nr_bus) INTO v_nrbus FROM DUAL;
ELSE
SELECT trim(REVERSE(substr(pio_address.street_nr_bus,1, v_posstraat-1))) INTO v_nrbus FROM DUAL;
END IF;
------------------------------------------------------
*****UPDATE*****
*****************
it appears that this part of the code isn't what's slowing the procedure down, but if someone still knows a "shorter" way to accomplish what I'm doing with this code, tips are always welcome
Edited by: user11236545 on Mar 27, 2012 2:47 AM
Edited by: user11236545 on Mar 27, 2012 2:49 AM