Re: How to trim substrings?



Rauf Sarwar wrote:
RK wrote:
Help, please.

I have to query a table to trim a certain field, and to catch its
certain substrings. The tool I know is like ltrim() or rtrim(),
something like


select ltrim(ltrim(field_1,'a'),'b') from table_1;

or

select count(*) from table_1 where rtrim(field_1,'b') = 'xxc';


I know ltrim() or rtrim() only trim out one character/digit once. How
can I get all of the required results if I have more repeated 'a' to
the left or 'b' to the right? Like

aHaveOne
aaHaveTwo
abaabHaveMore

...

This must be done purely by SQL*Plus query. Thanks.

Use only one ltrim for both,

SQL> select ltrim('abaabHaveMore', 'ab') from dual;

LTRIM('ABAABHAVEMORE','AB')
---------------------------
HaveMore

SQL> select ltrim('abbbaabbaabHaveMore', 'ab') from dual;

LTRIM('ABBBAABBAABHAVEMORE','A
------------------------------
HaveMore

Regards
/Rauf

Or possibly use translate.

Demo in Morgan's Library at www.psoug.org
--
Daniel A. Morgan
http://www.psoug.org
damorgan@xxxxxxxxxxxxxxxx
(replace x with u to respond)
.



Relevant Pages

  • How to trim substrings?
    ... certain substrings. ... I know ltrim() or rtrimonly trim out one character/digit once. ... This must be done purely by SQL*Plus query. ...
    (comp.databases.oracle.misc)
  • Re: How to trim substrings?
    ... I know ltrim() or rtrimonly trim out one character/digit once. ... This must be done purely by SQL*Plus query. ... SQL> select ltrimfrom dual; ...
    (comp.databases.oracle.misc)
  • Re: Noise Words
    ... You will have to trim this noise ... word out from your query or remove it from your noise word list. ... Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.fulltext)
  • Re: why>?
    ... assuming for the moment there were an LTRIM ... to errors any moderately competent spreadsheet user would avoid. ... SET FormulaText = replace(formulatext, 'TRIM', 'LTRIM') ... then maybe i would be happy with excel. ...
    (microsoft.public.excel)
  • Re: Using Flattened table COSTLIER than using JOINS with the SETUP tables.
    ... tables and also attaching the Explain plan statements for the query ... Next Execution plan without PSOPRALIAS:- is 13135 ... DECODE (TRIM (c.jp_draft_to_status), ...
    (comp.databases.oracle.tools)