Ltrim and rtrim

NAME
THE ADAMS
ETH BILLA
EXP RAJA
I want to remove the THE From the name but when i use ltrim it removing
as below.
select ltrim(name,'the') from xy;
ADAMS
BILLA
XP RAJA
how can we remove the particular word "THE" from the string in the first occurence(left side).Pls suggest any method

the following will only work if the first occurrence is at the begining of the string
CASE
    WHEN  name LIKE 'THE %'
    THEN  SUBSTR (name, 5)
    ELSE  name
ENDthe following works for the first occurrence in the string, note the comment if you want to keep the extra space after the first THE
col txt format a30
with t as
(select column_value txt
   from table(sqlstringsequence('THE ADAMS', 'ETH BILLA', 'EXP RAJA', 'ETH BILLE THE ADAMS THE SMITHS')))
select case
        when instr(txt, 'THE') > 0
        then trim(substr(txt, 1, instr(txt, 'THE')-1)||substr(txt, instr(txt, 'THE')+4))--3 to keep space after THE
        else txt
       end txt,
       case
        when txt like 'THE %'
        then substr(txt, 5)
        else txt
       end txt2
  from t
/Edited by: mwooldridge on Jul 9, 2009 11:20 AM
Edited by: mwooldridge on Jul 9, 2009 11:23 AM

Similar Messages

  • Urgent:LTRIM and RTRIM Function

    How do I use the LTRIM and RTRIM function?
    For Example:
    Name: Isis Cheung Hui Mei
    i have the name in a text field and I need to extract out 3 initial.how do i use the RTRIM and LTRIM function?

    So sorry have to trouble u all again.
    what i mean is the NAME is already in the database and i need to display the name and the initial in the form based on the employee id.from there, i must take out 3 initial of name and display and making sure there is no duplicate in the database as it will be treat as the UserID.
    the name is not input by the user but is retireve from the database
    thank you

  • String : lacks of ltrim and rtrim

    Hi there
    - why the String class is not provided with functions like ltrim() and rtrim(), just like basic ?
    - how to implement an efficient ltrim() or rtrim() function ?

    java.lang.String has a trim method that removes leading and trailing whitespace at the same time. I'll bet the guys who wrote it were smart enough to optimize it so it was relatively efficient. Use that.
    Besides, if your code is running so poorly that you're worried about the efficiency of the trim operation, I'd be willing to bet that you've got bigger problems somewhere else. Don't optimize prematurely, and don't guess. Use a profiler to find out where the real trouble spots are.
    I'd say that if the lack of an ltrim/rtrim functionality in the String class is such a big deal, then write one for yourself and be done with it. I wouldn't urge Sun to be wasting time on it. Java's been around for years now and it hasn't been an impediment to its adoption.
    Or just go back to writing Basic.
    This thread has that Swiftian "big endian/little endian" feel to it now.

  • Using LTRIM and RTRIM in field

    Hi,
    The table has no of row. want to remove the space before and after in the name field and update the name field without space in the same table.
    EXAMPLE;
    name
    m
    c
    d

    Better would be fixing it in the source itself..
    Else try this.
    update your_tbl set name=replace(name,' ');
    commit;
    Cheers,
    Manik.

  • LTRIM and RTRIM syntax to identify string between commas

    My [Locations] field is a character field that contains <addresses> separated by commas
    ie: (1 University Avenue, 3 Maple Street, 575 Commonwealth Avenue,,,,,,,)
    I want to select the <address> between the 2nd and the 3rd comma ......575 Commonwealth Avenue
    Can someone please help me with the syntax for writing this select statement.
    I've tried some due diligence, but am having problems.
    In another scenario, I'm also going to need to update the address by specifying its location in the textstring.
    Thanks in advance for your help.
    -Gary

    Let me explain ->
    Since, you didn't provide any table structure - so i need to prepare one virtual table.
    -----My Dummy Table With Data Part ------
    satyaki>with pp
      2  as
      3    (
      4      select '1 University Avenue, 3 Maple Street, 575 Commonwealth Avenue,,,,,,,' cola from dual
      5    )
    ------End Of My Dummy Table With Data Part--------
      6  select trim(substr(cola,instr(cola,',',1,2)+1,instr(cola,',',1,3) - instr(cola,',',1,2)-1)) res
      7  from pp;In your case,
    You can only use the select statement. cola - will be your data column name.
    Now, talking about INSTR function ->
    instr(cola,',',1,2)As you can see the digit in bold part, it will find the ',' with 2nd occurrence inside your string.
    Similarly, instr(cola,',',1,3) - this will find the third occurrence of ',' inside you string.
    Now,
    You have to see the substr function.
    In substr, you have to pass the column name on which you want to extract the required data, then you have to pass the starting position of the character from where you want extract the data, then you have to pass the number of character you want to cut from the start position.
    So, i've used ->
    substr(cola,instr(cola,',',1,2)+1,instr(cola,',',1,3) - instr(cola,',',1,2)-1)cola -> Source String
    instr(cola,',',1,2) -> Start position of the String
    instr(cola,',',1,3) - instr(cola,',',1,2)-1 -> Total number character you want extract from your string.
    Regards.
    Satyaki De.

  • Help with a query using ISNULL and RTRIM in the same select statement

    What I'm trying to accomplish is to blend the following two statements together:
    ISNULL (EMail_Address, '') As Matrix_Member_Email
     AND
    RTRIM (EMail_Address) as Matrix_Member_EMail
    So that if the email address is NULL, it gets changed to blank and I still need to RTRIM the other entries and use the column header of Matrix_Member_Email.
    I've tried:
    ISNULL ((EMail_Address, '') (RTRIM (EMail_Address)) as Matrix_Member_EMail
    Any help would be greatly appreciated.
    Thank you,

    I'm sorry.  Here is the query:
    --Declare @EMail_Address nvarchar(100) = null
    Select SVAssociationID.R_ShortValue as MATRIX_AssociationID, Matrix_Modified_DT as Matrix_LastModified
      ,RTRIM (MLS_ID) As Matrix_MLS_ID
      , ISNULL(EMail_Address, '') AS MATRIX_member_Email
      ,RTRIM (EMail_Address) as Matrix_Member_EMail
      --,RTRIM( LTRIM(  ISNULL (@EMail_Address, '') ) ) as Matrix_Member_EMail 
      ,Last_Name AS MATRIX_LastName, Nickname AS MATRIX_NickName
      FROM    dbo.Agent_Roster_VIEW a
            LEFT JOIN dbo.select_values_VIEW SV ON a.Status_SEARCH = SV.ID
            LEFT JOIN dbo.select_values_VIEW BillType ON a.Bill_Type_Code_SEARCH = BillType.ID
      LEFT JOIN dbo.select_values_VIEW SVAssociationID ON A.Primary_Association_SEARCH = SVAssociationID.ID
    WHERE   Status_SEARCH IN (66,68) 
        Order by MLS_ID
    Results:
    MATRIX_AssociationID
    Matrix_LastModified
    Matrix_MLS_ID
    MATRIX_member_Email
    Matrix_Member_EMail
    MATRIX_LastName
    MATRIX_NickName
    STC
    09/02/14
    CCWILLI
    [email protected]
    [email protected]
    Williams                      
    Christine   
    STC
    09/12/14
    CCWORSL
    [email protected]
    [email protected]
    Worsley                       
    Charlie
    STC
    09/02/14
    CCYROBIN
    NULL
    Robinson       
    ECBR
    09/02/14
    CDABLACK
    [email protected]
    [email protected]
    Black                         
    Dale        
    STC
    09/02/14
    CDABRADY
    [email protected]
    [email protected]
    Brady                         
    David       
    Thank you,

  • Problem  with sqlloader and rtrim in direct path

    Im trying to load near 40 Gb of information to Oracle 9i (9.2.0.6.0) so to acelerate the load we are using direct=true but we are having problems with table where we need to aply sql funtions. Like an example check this control file please:
    LOAD DATA
    INFILE 'PSACTIVIMG.dat' "str '~~~~~'"
    BADFILE 'PSACTIVIMG.bad'
    DISCARDFILE 'PSACTIVIMG.dsc'
    INTO TABLE PSACTIVIMG
    TRAILING NULLCOLS (
    ACTIVITYNAME CHAR terminated by '@@#' "NVL(RTRIM(:ACTIVITYNAME),:ACTIVITYNAME)",
    SEQNO terminated by '@@#',
    PSIMAGEVER terminated by '@@#',
    IMGSEG RAW(65536))
    When we try to run it with direct=true we are getting:
    SQL*Loader-961: Error calling once/load finishing for table PSACTIVIMG
    ORA-26090: row is in partial state
    SQL*Loader-2026: the load was aborted because SQL Loader cannot continue.
    But in alert.log we are getting:
    ORA-00600: internal error code, arguments: [klafre_30], [0], [], [], [], [], [], []
    ORA-01403: no data found
    If i remove the rtrim function or i use conventional path the data its loades correctly. Any body have any suggestion about this problem?
    thanks in advance.
    Alejandro Amador.

    Could you use an external table and insert as select with the /*+ append */ hint?

  • Trim,ltrim,rtrim

    Hi,
    I understand TRIM is used for trimming the spaces....
    Is this used for any other purpose...
    Actually at what scenario these (trim,ltrim,rtrim) are used.
    Can anyone please explain me with good examples of how it is used....
    Thanks in advance.....

    Hi,
    They are all used to remove any character from the end of a string.
    Space is the default character, but any other character can be specified.
    TRIM has the advantage of being able to remove characters from eith the beginning or end of the string at the same time.
    TRIM has the disadvnatage of using only one character.
    LTRIM and RTRIM have the disadvantage of only operating on the beginning (Left side) or end (Right side) of the string.
    LTRIM and RTRIM have the advantage of using as many characters as you want. For example, removing 3 different punctuation marks at once:
    RTRIM ( '..;;,,;,.AB,C..;;,,;,.'
          )returns
    ..;;,,;,.AB,CREGEXP_REPLACE can be an altternative.

  • Select query hangs on Oracle 9i but works fine in Oracle 8i

    Hi Guys,
    For a recap of what happened:
    Migrated from Oracle 8i to 9i for a customer, all queries and statements are working fine, except for this particular query. If i run the same query on 8i it works like a charm.
    In 9i, if i remove even one field from the query, it works else it just hangs.
    Any idea, any one???
    **Added 2:09PM: When i removed some ltrim and rtrim that i believe not necessary, the query works fine, is there any field length limitation in Oracle 9i???
    Below is the query:
    set pagesize 100;
    set linesize 1024;
    set heading off;
    set echo off;
    spool scb_xfer_hdr_npsx;
    select ltrim(rtrim(to_char(hdr_srl_no,'99'))) || ';' ||
    'P' || ';' || rtrim(ltrim(payment_type))|| ';'|| ';' ||
    ltrim(rtrim(our_ref_no))|| ';'|| 'MY;KUL;' ||
         rtrim(ltrim(debit_account_no))||';'||
    rtrim(ltrim(to_char(scb_batch_date,'YYYY/MM/DD'))) || ';'|| ';' ||
    rtrim(ltrim(payee_name_1))|| ';'|| ';' ||
    rtrim(ltrim(address_1))|| ';'||
    rtrim(ltrim(address_2))|| ';'||
    rtrim(ltrim(address_3))|| ';'|| ';' ||
    rtrim(ltrim(payee_name_11))|| ';' ||
    rtrim(ltrim(address_11))|| ';'||
    rtrim(ltrim(address_21))|| ';'||
    rtrim(ltrim(address_31))|| ';'|| ';' ||
         rtrim(ltrim(payee_bank_code)) || ';' || ';' ||
         rtrim(ltrim(payee_account_no)) || ';' ||
         rtrim(ltrim(our_ref_no2)) || ';' || ';' ||
         rtrim(ltrim(our_ref_no2)) || ';' || ';' || ';' || ';' ||
    rtrim(ltrim(payment_currency))|| ';'||
    rtrim(ltrim(to_char(payment_amount,'9999999999.99')))|| ';'||
         'C;P;;' || rtrim(ltrim(payee_bank_name))|| ';' ||
         'KL;;' ||
         rtrim(ltrim(delivery_method)) || ';' ||
         rtrim(ltrim(delivery_by)) || ';' ||
         rtrim(ltrim(counter_pickup_location))
    from scb_xfer_hdr_npsx
    order by hdr_srl_no;
    select distinct 'T;' || ltrim(rtrim(to_char(total_payments))) || ';' ||
         ltrim(rtrim(to_char(total_pay_amount,'9999999999.99')))
    from scb_xfer_hdr_npsx;
    spool off;
    spool scb_xfer_dtl_npsx;
    select ltrim(rtrim(to_char(srl_no,'99'))) || ';' || 'I' || ';' ||
         ltrim(rtrim(doc_no)) || ';' || ltrim(rtrim(to_char(doc_date,'yyyy/mm/dd'))) || ';' ||
         ltrim(rtrim(doc_description)) || ';' ||
         ltrim(rtrim(to_char(doc_amount,'9999999999.99')))
    from scb_xfer_dtl_npsx
    order by srl_no;
    spool off;
    set echo on;
    exit;
    Message was edited by:
    Logesh

    Hi,
    are you still on a 32bit kernel on AIX?
    How are the Form4.5 connected, are they on the same box, or are they using the forms GUI?
    What about the statistics, how do you collect them? Is the database set to the COST based optimizer?
    Do you use dbms_utility.analyze_schema, or this:
    exec dbms_stats.gather_schema_stats( -
    ownname => '$OWNER', -
    estimate_percent => 10, -
    granularity => 'ALL', -
    method_opt => 'FOR ALL COLUMNS SIZE 75', -
    degree => NULL , -
    options => 'GATHER $GATH', -
    cascade => TRUE -
    What does it mean the SQL hangs? Can you cancel the query? Do you have to kill the session? Do you use any diagnostic tools like TOAD to trace the session, see what it is doing? Usually if this is a performance/tuning issue, you will see the session is not dead, but you will see advancing reads.
    Regards,
    Richard.

  • Formatting function for columns which store japanese characters

    I have a table which stores names in all languages.I have a SQL Report.When the names are in English the formatting is good.But when the names are in Japanese.The formatting is going wrong.
    A part of SQL report is as follows
    COLUMN emp_name formata20
    COLUMN mgr_name formata20
    select emp_name,mgr_name
    from employee;
    The data in the columns are coming in ZigZag fashions.I tried using ltrim and rtrim but had no impact.Are there any functions which would help in formatting the query.I need this very urgently.
    Thanks in advance

    Change your environment variable 'nls_lang' appropriately to reflect the language.
    For example on my computer, this variable has the value
    American_America.WE8ISO8859P1
    Typically NLS_LANG environment variable is of type:
    language_territory.charset
    If you are using Japanese character set, you could specify the environment variable as:
    JAPANESE_JAPAN.JA16EUC
    Please go through Oracle's Globalization Support Guide for additional information.

  • Long Running Queries Using Group By & Order By

    I have his query and it takes forever to run. The TABLE 'term' has over a million rows and I think that the 'group by' and the 'Order By' together is killing the execution...
    Or is it due to the compute clauses.. I am at loss to understand the whole issue..
    Any ideas or thougts on how to solve this issue. Oracle Version is 8.1.6 ...
    Please help !!!!
    Thanx
    Rama
    ====================
    set pages 10000;
    set heading on;
    compute sum of total on area
    compute sum of total on report
    break on area skip 2 on report
    SELECT c.area area
    , b.modelcode model
    , count(1) total
    FROM leadterm a
    ,lead e
    ,term b
    ,temp_veh b
    ,leaddealer d
    ,dealer c
    WHERE
    a.leadid not in (select leadid from leadno_tmp)
    and a.leadid = e.leadid
    and a.termid = b.termid
    and e.leaddealerid = d.leaddealerid
    and ltrim(rtrim(d.vwdealercode)) = ltrim(rtrim(c.dealercode))
    group by c.area
    , b.modelcode
    order by to_number(c.area)
    , b.modelcode
    exit;

    Did you run this query through the explain plan yet?
    A few thoughts:
    - Order by is not needed, since group by automatically sorts the records.
    - Assuming that dealercode is a primary key, ltrim and rtrim functions will cause Oracle NOT to use indexes, but a full table scan. If a foreign key is defined, then ltrim and rtrim should not be necessary at all.
    - Instead of "not in" use "where not exists"

  • How to trim spaces in SQL?

    Hi there,
    I have installed Oracle XE on my machine and have populated it with some data. In one table,namely the Id column i noted there are spaces before the actual code. For example _ _ _12345. My question is, how do i removed these spaces? I am using Oracle SQL Developer to query the tables in XE. I have over 100,000 records.
    Thanks for the help
    SI

    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/functions002.htm#CJAEEJFC
    Refer to the TRIM, LTRIM and RTRIM functions and issue an appropiate UPDATE statement
    Sybrand Bakker
    Senior Oracle DBA

  • About trim function capabulity

    Hi Experts,
    I have a some doubts regarding trim function.
    1)trim function any limitations like it will trim for this munch length string(consider adding space also)? please consider in case of trimming spaces
    Regards,
    Surya

    Hi, Surya,
    surya wrote:
    Hi Experts,
    I have a some doubts regarding trim function.
    1)trim function any limitations like it will trim for this munch length string(consider adding space also)? please consider in case of trimming spaces Good idea; let's simplify the conversation by saying we only want to trim spaces.
    TRIM removes all of the spaces, regardless of how many there are.
    If you want to limit the number of spaces it removes, then you have to use other functions, either in addition to or instead of TRIM. (REGEXP_REPLACE comes to mind quickly.)
    I'm not sure what you're saying about "adding space also". LPAD and RPAD are rather like opposites of LTRIM and RTRIM. (There is no bi-directional PAD function.) RTRIM can remove spaces from the end of a string, RPAD can add spaces to the end of a string.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, showing some strimgs you want to change), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Replacing several commas in a string

    Hi ,
    Hi ,
    I have string like the following.
    1.,Accenture, , ,EDS,Sun,Training Partner
    2.United States,,,,
    3.Canada,
    I want to have the string like the following as a result of the query.
    1. Accenture,EDS,Sun,Training Partner
    2. United States
    3. Canada
    Help is appreciated.
    _PS
    Here is the script to create table and insert script.
    create table temps
    (val varchar2(1000));
    insert into temps values (',Accenture, , ,EDS,Sun,Training Partner');
    insert into temps values ('United States,,,, ');
    insert into temps values ('Canada,');
    insert into temps values (',Canada ');
    commit;

    Hi,
    You can do this in any version of Oracle, but you should have some excuse ready if you do it in Oracle 10 (or higher):
    SELECT     val
    ,     TRIM
         ( ',' FROM
              REPLACE          -- (4) See notes below
              (     REPLACE          -- (3)
                   (     REPLACE          -- (2)
                        (     REPLACE     ( val     -- (1)
                                  )     -- (1)
                        )          -- (2)
                   )          -- (3)
              )          -- (4)
         )     AS reduced
    FROM     temps
    ;This assumes you know of a string ('??' in this example) that never appears next to a comma.
    In case it's not completely clear what the various REPLACEs are doing:
    (1) Remove single spaces after commas (unlike the REGEXP_REPLACE solution, which removes any number of spaces) The interesting cases now are a single comma (such as 'x,y') or muliple consecutive commas (like 'w,,,z').
    (2) Add '??' AFTER every comma (resulting in 'x,??y' or 'w,??,??,??z')
    (3) Remove all instances of '??,' (that is, the flag BEFORE a comma, resulting in 'x,??y' (no change) or 'w,??z')
    (4) Remove '??' AFTER every comma (resulting in 'x,y' or 'w,z')
    If you really need to remove any number of spaces in step (1), you can use the technique from steps (2)-(4), a total of seven nested REPLACE calls.
    Edited by: Frank Kulash on Oct 31, 2008 5:10 PM
    Actually, this has to be changed to work in Oracle 8 (and earlier)
    The ambidextrous TRIM function was introduced in Oracle 9.
    In earlier versions, you have to nest LTRIM and RTRIM, as in Sy's message (below).

  • Trim() function in C?

    quick question: I'm looking for a way to remove the leading spaces from a character array. I know I could right my own algorithm to do this, but I was just curious if there is a pre-defined function or something for this purpose. I know other languages have functions like trim() and ltrim() and rtrim() -- does C have something like this? If so, can you tell me what it is and what library I would have to include to use it? Thank you!

    Thanks, Bob! I certainly agree that strtok()--and more recently strsep()--should be in every programmer's bag of tricks, and I wouldn't be surprised if Tron's next thread follows up on your tip. Teaching Tron a new runtime function can be very rewarding, but the good deed carries with it some degree of responsibility. So I think that next thread will be all yours.
    In my case, it's sometimes easier to crunch because I may be scanning certain patterns out of rich text, and when I find them I want to include them in a database. For example if I'm looking for the title of a section, I might seek to a particular paragraph style in RTF. If I recognize the title, I might prefer the crunched version in the database based on the assumption that excess white space is most likely a typo rather than a unique phrase that needs a new key (of course I might save the raw text as well so the document's author can receive a courteous e-mail pointing out that wrist protectors and sandwiches should be positioned away from the space bar). I used to get more interesting work btw, but lots of other pursuits were more interesting when I was younger.
    So some of my nasty jobs are a little different from what we do in the front end of a compiler, etc. Whoever decided that a source code identifier couldn't include embedded spaces was really onto something. Where would we be today without that simple rule?
    All the best,
    \- Ray

Maybe you are looking for