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.

Similar Messages

  • 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.

  • 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

  • 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

  • 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.

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to Communicate a string between LabView 7.0 and VB using TCP/IP

    HI
    I want to know how to communicate , " by passing a string  "  between LabView 7.1  and VB 6.0  using tcp/ip . Please if anyone couild help me on this..
    Regards
    Ashish Doshi

    Ashish,
    I've got great news for you! LabVIEW has built in TCP functions. They are located in Data Communication>>Protocols>>TCP. From the LabVIEW side, I think you'll find everything you need in there. Good luck!
    Chris C
    Chris Cilino
    National Instruments
    LabVIEW Product Marketing Manager
    Certified LabVIEW Architect

  • 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,

  • Error "Conversion failed when converting date and/or time from character string" to execute one query in sql 2008 r2, run ok in 2005.

    I have  a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
    USE [Runtime]
    GO
    /****** Object:  UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt]    Script Date: 06/11/2013 08:47:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE   FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)  
    -- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
    RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
    AS  
    BEGIN 
    -- Crea el Cursor
    DECLARE cursorHora CURSOR
    READ_ONLY
    FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
    -- Declaracion de variables locales
    DECLARE @produc_opt_hora int
    DECLARE @produc_opt_parc int
    DECLARE @nsacos int
    DECLARE @time_parc datetime
    -- Inicializamos VARIABLES
    SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
    -- Abre y se crea el conjunto del cursor
    OPEN cursorHora
    -- Comenzamos los calculos 
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    /************  BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR  ************/
    WHILE (@@fetch_status <> -1)
    BEGIN
    IF (@@fetch_status = -2)
    BEGIN
    -- Terminamos la ejecucion 
    BREAK
    END
    -- REALIZAMOS CÁLCULOS
    SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
    -- INSERTAMOS VALORES EN LA TABLA
    INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
    -- Avanzamos el cursor
    FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
    END
    /************  FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR  ***************/
    -- Cerramos el cursor
    CLOSE cursorHora
    -- Liberamos  los cursores
    DEALLOCATE cursorHora
    RETURN 
    END

    You can search the forums for that error message and find previous discussions - they all boil down to the same problem.  Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime.  In general,
    this works in any version of sql server if the runtime settings are correct for the format of the string data.  The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
    the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers. 
    I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion.  It may not be in the function you posted, since that function also executes other functions. 
    You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all. 
    Tibor's site

  • How to create Unique Identifier and save it to identify user(device)

    I want to create unique identifier on iOS 5 and use it for identifying user (user device) every time app is started. I am able to create a unique identifier by following code 
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID); CFRelease(theUUID);
    But unable to save it on user device so that particular identifier is not deleted even when app is uninstalled. I tried using SSKeychain approach but it gives Apple Mach-o Linker error.
    Please let me know the the way I can accomplish the same.
    Any help is appreciated.

    I want to create unique identifier on iOS 5 and use it for identifying user (user device) every time app is started. I am able to create a unique identifier by following code 
    CFUUIDRef theUUID = CFUUIDCreate(NULL);
    CFStringRef string = CFUUIDCreateString(NULL, theUUID); CFRelease(theUUID);
    But unable to save it on user device so that particular identifier is not deleted even when app is uninstalled. I tried using SSKeychain approach but it gives Apple Mach-o Linker error.
    Please let me know the the way I can accomplish the same.
    Any help is appreciated.

  • Get the string between li tags, with regular expression

    I have a unordered list, and I want to store all the strings between the li tags (<li>.?</li>)in an array:
    <ul>
    <li>This is String One</li>
    <li>This is String Two</li>
    <li>This is String Three</li>
    </ul>
    This is what have so far:
    <li>(.*?)</li>
    but it is not correct, I only want the string without the li tags.
    Thanks.

    No one?
    Anoyone here experienced with Regular Expression?

  • How would I split a string between two strings?

    Hi Guys,
    I have a question hopefully you guys can help with..
    I have a set of data similar to
    sefsfesef<1111>Example<2222>desefsefsefefsefsef<1111>Example2<2222>sefsefsef
    What I want to do is split my string between the <1111> and <2222> and get "Example" and "Example2" back... is this possible in Java? Possibly using regular expressions of sorts. I'm a little lost, any help would be much appreciated!
    Thanks,
    Vasant

    Here is an example (parse.java) that will work provided that the content between <1111> and <2222> does not contain the < character.
    import java.util.regex.*;
    public class parse {
      public static void main(String args[]) {
        String teststring = "sefsfesef<1111>Example<2222>desefsefsefefsefsef<1111>Example2<2222>sefsefsef";
        Pattern p = Pattern.compile("<1111>([^<]*)<2222>");
        Matcher m = p.matcher(teststring);
        while(m.find()) {
          System.out.println(m.group(1));
    }I'm sure some regex guru around here could solve this one in 3 characters or less, but that ain't me :)

  • Identifying string validity

    hi i have a problem creating a class for identify string validity
    example a string would be invalid if
    String xx = "abcdef'abde";
    theres an '
    how would i detect any illegal expressions in a string

    It all of course depends upon what you define as "invalid". Having said that, for great flexibility in checking strings, matching strings, replacing substrings, etc... look into Java's implementation of Regular Expressions. This is a large and complex subject requiring quite a bit of effort if you are new at it, but the effort pays off in the long run. Have a look here
    [http://java.sun.com/docs/books/tutorial/essential/regex/index.html]

  • Find and replace value in Delimited String

    Hi All,
    I have a requirement, where i need to find and replace values in delimited string.
    For example, the string is "GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~". The 4th column gives month and year. I need to replace it with previous month name. For example: "GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~". I need to do same for last 12 months.
    I thought of first devide the values and store it in variable and then after replacing it with required value, join it back.
    I just wanted to know if there is any better way to do it?

    for example (Assumption: the abbreviated month is the first occurance of 3 consecutive alphabetic charachters)
    with testdata as (
    select 'GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~' str from dual
    select
    str
    ,regexp_substr(str, '[[:alpha:]]{3}') part
    ,to_date('01'||regexp_substr(str, '[[:alpha:]]{3}')||'2013', 'DDMONYYYY') part_date
    ,replace (str
             ,regexp_substr(str, '[[:alpha:]]{3}')
             ,to_char(add_months(to_date('01'||regexp_substr(str, '[[:alpha:]]{3}')||'2013', 'DDMONYYYY'),-1),'MON')
    ) res
    from testdata
    STR
    PART
    PART_DATE
    RES
    GL~1001~157747~FEB-13~CREDIT~A~N~USD~NULL~
    FEB
    02/01/2013
    GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~
    with year included
    with testdata as (
    select 'GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~' str from dual
    select
    str
    ,regexp_substr(str, '[[:alpha:]]{3}-\d{2}') part
    ,to_date(regexp_substr(str, '[[:alpha:]]{3}-\d{2}'), 'MON-YY') part_date
    ,replace (str
             ,regexp_substr(str, '[[:alpha:]]{3}-\d{2}')
             ,to_char(add_months(to_date(regexp_substr(str, '[[:alpha:]]{3}-\d{2}'), 'MON-YY'),-1),'MON-YY')
    ) res
    from testdata
    STR
    PART
    PART_DATE
    RES
    GL~1001~157747~JAN-13~CREDIT~A~N~USD~NULL~
    JAN-13
    01/01/2013
    GL~1001~157747~DEC-12~CREDIT~A~N~USD~NULL~
    Message was edited by: chris227 year included

  • Hi I am having problems downloading and updating apps on my iPad and iPhone. The message cycles between waiting and loading then I get an error message saying unable to download app. Eventually,after many attempts it works.

    Hi Guys - for a few days I have been having problems downloading and updating apps on my iPad and iPhone. The message cycles between waiting and downloading then eventually says unable to download app. Sometimes after many attempts it wil eventually work. I tested it on an old iPhone 3G and got the same problem so it is not an iOS 5 issue. My WI-FI connection is working fine. I was wondering if this is an App Store problem? Anyone else in the UK having this problem?

    Hi John
    iTunes Support wasn't of any use to me.
    I have also been having another problem - with BBC iPlayer and other video streaming not working due to insufficient bandwidth, despite my overall download speed being consistently around 50Gb.  This is also affecting AppleTV downloads
    I am using Virgin Media as my ISP, and was wondering whether you do as well.  This might be the common thread.
    -Bernard

Maybe you are looking for