Home » SQL & PL/SQL » SQL & PL/SQL » groups in regexp_instr (Oracle 10g)
groups in regexp_instr [message #643406] |
Wed, 07 October 2015 02:50 |
|
m.abdulhaq
Messages: 254 Registered: April 2013 Location: Ajman
|
Senior Member |
|
|
I want to extract the numbers part from the string of second column bs_Desc in a separate columns, i am using the following method to achieve this ,The problem is 2 reference position is not fixed.Only thing common is 1 number occurrence and 2nd number occurrence. i want to know whether it can be done using reference and if there is a solution without regular expressions.
CREATE TABLE BOLTS ( BS_CODE VARCHAR2(12),BS_DESC VARCHAR2(30));
INSERT INTO BOLTS(BS_CODE,BS_DESC) VALUES ('1','BOLTS_1NUTS_1WASHERS');
INSERT INTO BOLTS(BS_CODE,BS_DESC) VALUES ('2','BOLTS_2NUTS_1WASHERS');
INSERT INTO BOLTS(BS_CODE,BS_DESC) VALUES ('3','BOLTS_1NUTS_2WASHERS');
SELECT bs_desc,
SUBSTR (bs_desc,
REGEXP_INSTR (bs_desc, '(\d)', 1, 1, 0),
1
) first_reference,
SUBSTR (bs_desc,
REGEXP_INSTR (bs_desc, '(\d)', 8, 1, 0),
1
) second_number
FROM bolts;
FIRST_REFERENCE,SECOND_NUMBER
1,1
2,1
1,2
|
|
|
|
|
Re: groups in regexp_instr [message #643413 is a reply to message #643412] |
Wed, 07 October 2015 04:50 |
bugfox
Messages: 18 Registered: October 2010
|
Junior Member |
|
|
without regexp:
select substr(bs_desc, instr(translate(bs_desc, '1234567890', '##########'), '#'), 1) first_reference,
substr(bs_desc, instr(translate(bs_desc, '1234567890', '##########'), '#', -1), 1) second_number
from bolts
|
|
|
|
|
|
Goto Forum:
Current Time: Thu Apr 25 14:02:46 CDT 2024
|