Simple SQL query [message #1883] |
Fri, 07 June 2002 05:19 |
Vinayak Awasthi
Messages: 19 Registered: October 2001
|
Junior Member |
|
|
Hi all,
I have a string 'abcabcccc i love oracle abc'.I want to remove the leading abc's only ie the result i want should be 'ccc i love oracle abc'.
I want this with SQL only (no PLSQL).
Please help me.
Rgds
|
|
|
|
Re: Simple SQL query [message #1895 is a reply to message #1883] |
Sat, 08 June 2002 12:04 |
Amit Chauhan
Messages: 74 Registered: July 1999
|
Member |
|
|
Hi,
Try this :
SELECT REPLACE(LTRIM(REPLACE('abcabcabccccd abc ', 'abc', CHR(1)), CHR(1)), CHR(1), 'abc')
FROM DUAL
/
What am doing here is, am replacing the string that is to be removed (abc here) to character 1 (CHR(1)), you can use any other character if you want, am just using it assuming this will not appear in the string anywhere. Then I am using LTRIM to remove CHR(1) from left. And then replace back CHR(1) to abc.
Hope that helps.
Thanks
Amit
|
|
|
Re: Simple SQL query [message #1902 is a reply to message #1883] |
Sun, 09 June 2002 20:37 |
Balaji
Messages: 102 Registered: October 2000
|
Senior Member |
|
|
hi vinayak
try this out. this statement will take the substr of the string with starting position as the instr of ccc
it doesnt matter how many times the abc appears.
select substr('abcabcabcabcabcabcccc i love oracle abc',instr('abcabcabcabcabcabcccc i love oracle abc','ccc',1)+1
,length('abcabcabcabcabcabcccc i love oracle abc'))from dual
|
|
|
Re: Simple SQL query [message #2733 is a reply to message #1895] |
Thu, 08 August 2002 09:51 |
Faisal
Messages: 16 Registered: November 2001
|
Junior Member |
|
|
Can you explain me the Ltrim funstion a little clear it would be better if you explain me giving an example in Access. I used your query in Access but it doesnt work.
|
|
|