Replace string based on condition [message #643184] |
Thu, 01 October 2015 02:49 |
|
m.abdulhaq
Messages: 254 Registered: April 2013 Location: Ajman
|
Senior Member |
|
|
I have to replace the first instance of '-' starting from left with '-RF-' .
CREATE TABLE REFAB ( REFFAB_STR VARCHAR2(60))
INSERT INTO REFAB(REFFAB_STR) VALUES ('1510029-1001');
INSERT INTO REFAB(REFFAB_STR) VALUES ('1410029M-1001');
INSERT INTO REFAB(REFFAB_STR) VALUES ('008-R230-B206');
SELECT REPLACE(REFFAB_STR,'-','-RF-') FROM REFAB;
-- I am getting the result as below
REPLACE(REFFAB_STR,'-','-RF-')
1510029-RF-1001
1410029M-RF-1001
008-RF-R230-RF-B206
--i want the result to be like below.
1510029-RF-1001
1410029M-RF-1001
008-RF-R230-B206
|
|
|
|
|
|
|
|