Get number from string

Hi,
I have a problem with an select.
I need to compare two string columns. First column includes only a number with 9 characters:
'001234567'
Second column includes text where somewhere inside this text is the number 001234567.
'Hallo1 001234567'
I need to extract the 9 character big number out of the string. I thought using the regular expression feature could help me.
SELECT
  REPLACE(REGEXP_REPLACE('hallo 001122334', '[a-z]', ''),' ') "REGEXP_REPLACE"
FROM dual;But this would exclude the number 1 after Hallo:
Result: '1001234567'
The number I look for is always 9 character long.
Thanks ahead,
Tobias

You have many variants:
with your_table as
     (select
            'hallo1001122334' first_column,
            '001122334' second_column
      from dual
select *
from your_table
where
--1) regexp_like(first_column,'.*'||second_column||'$')
--2) first_column like '%'||second_column
--3) regexp_substr(first_column,'\d{9}$')=second_column
--4) regexp_replace(first_column,'\D','') like '%'||second_columnFourth variant - includes case when chars can be between numbers in first column (for example 'hallo100a1a1a2a2a3a3a4').

Similar Messages

  • Get chars from string of numerals

    here is what I would like to accomplish:
    Put the last four integers of the systemDate into a variable so I can do some math with them.
    Thanks.

    Excellent.  Thank you for the info.  Very helpful.
    Dewey
    From: jchunick [email protected]
    Sent: Friday, June 03, 2011 4:20 PM
    To: Dewey Parker
    Subject: Re: get chars from string of numerals
    This is a post I made for the wiki which should help: http://director-online.com/dougwiki/index.php?title=Undocumented_Lingo#the_systemDate

  • In XI mapping, how to get number from a number_range object in SAP R/3

    HI All,
    I have a scenario where I need to read a Number_range object  in SAP R/3 or ABAP XI and retreive the current number.
    I need to use this number during the message mapping.
    (I read about JCO and RFC, but am a little confused about how-to and what is the correct approach)
    Just to let you know, I do not want to pass this number in the original IDOC coming from IDOC, so I need this lookup.
    Scenario:
    In MM, make a call to SAP.
    Get the latest number from SNRO( number-range object)
    Use this number in mapping.
    Any help pointers, greatly appreciated.
    Many thanks
    Shirin

    Shrin,
    Please find the parameters you need to specify while creating UDF
    Imports:javax.xml.transform.stream.StreamResult;com.sap.aii.mapping.lookup.;javax.xml.transform.dom.DOMSource;javax.xml.parsers.DocumentBuilder;java.io.;javax.xml.parsers.;org.w3c.dom.;org.xml.sax.;javax.xml.transform.;
    The Template for RFC Lookup
    String content = "";
    MappingTrace importanttrace;
    importanttrace = container.getTrace() ;
    //Filling the string with our RFC-XML (With Values)
    String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:<Function Module name>xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"></ns0:ZFI_GET_RUNID> ";
    RfcAccessor accessor = null;
    ByteArrayOutputStream out = null;
    try
    //1. Determine a channel (Business System, Communication channel)
    Channel channel = LookupService.getChannel("<Business System Name>","Communication channel name");
    //2. Get a RFC accesor for a channel.
    accessor = LookupService.getRfcAccessor(channel);
    //3. Create a xml input stream representing the FM request message.
    InputStream inputstream = new ByteArrayInputStream(m.getBytes());
    //4. Create xml Payload
    XmlPayload payload  =  LookupService.getXmlPayload(inputstream);
    //5. Execute Lookup
    Payload result = accessor.call(payload);
    InputStream in = result.getContent();
    //This are the extra step which i dont know what it mean
    //out = new ByteArrayOutputStream(1024);
    //byte[] buffer = new byte[1024];
    //for (int read = in.read(buffer); read > 0; read = in.read(buffer))
    //out.write(buffer,0,read);
    //content = out.toString();
    try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(in);
    NodeList list = document.getElementsByTagName( "REsult" );
    Node node = list.item(0);
    if (node  != null)
         node = node.getFirstChild();
         if (node  != null)
              content = node.getNodeValue();
    } catch (Exception e) {
    importanttrace.addWarning("Error while closing accesor" + e.getMessage());
    catch (LookupException e)
    importanttrace.addWarning("Error While lookup" + e.getMessage());
    //This exception is not to be catch at this step as there is no try step before this
    //catch (IOException e)
    //importanttrace.addWarning("Error" + e.getMessage());
    finally
    if(out!=null)
      try{
           out.close();
    } catch (IOException e) {
    importanttrace.addWarning("Error while closing system" + e.getMessage());
    //7. close the accessor in order to free resources
    if (accessor!=null) {
    try{
          accessor.close();
    } catch (Exception e) {
    importanttrace.addWarning("Error while closing accesor" + e.getMessage());
    return content;
    Have mentioned in genric  where u need to specify the communication channel name, business service etc.,
    Moreover there is a field result, which is the output returned from the FM

  • Hyperion Brio: Computed Item Extract Number From String

    I would like to extract a number from a string in a computer item.  For example if I had a string such as "The customer purchased $5.00 of footballs", I would like to remove only the 5.00 from the string.  I would have to use the java functions in the results.  Any suggestions on how to do this?

    you can do this in the Results section with a computed column using the native string functions.  to break it down i have split it up a bit.
    strval is you string "The customer purchased $5.00 of footballs"
    position of $ = 25
         Instr ( strval, '$', 1, 1 )
    the starting position of the amount would then be 26
         Instr ( strval, '$', 1, 1 ) + 1
    position of decimal after $ = 26
         Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 )
    using Substr function you need to pick the string, the start value and the number of characters.
    string
         = strval
    start position
         = Instr ( strval, '$', 1, 1 ) + 1
    number of characters - location of decimal minus the start position plus 3 to get the cents
         = Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 )  + 3
    put all together
    Substr( strval, Instr ( strval, '$', 1, 1 ) + 1,  Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 )  + 3 ) * 1
    the multiply by 1 converts the string to number

  • How to get substring from string starting from the end of string

    Hi
    How to cut from string:
    $A=C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    this substring (name of VHD file): WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    This script should be universal so the best way to be cut all leters from the end of string $A till get the first mark \
    Thank you for help.
    Tomasz
    Kind Regards Tomasz

    PS > Split-Path 'C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781
    -A6DE-68497D4189B8.avhdx' -leaf
    WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    PS >
    That is what "Split-Path" is for:
    ¯\_(ツ)_/¯

  • How to get InputStream from String ?

    Hi !
    I want to get InputStream object from String.
    String str = "balabalabala";
    InputStream stream = getInputStream(str);
    How to realize getInputStream(str) function ?
    Thanks!

    The preferred method nowadays is to use Readers and Writers for String data - hence StringReader(String). If you're going to operate on the InputStream directly, then I'd modify your code to use the Reader calls and go that route.
    If, however, you need to pass the InputStream to some other piece of API that requires an InputStream instead of a Reader, then the ByteArrayInputStream is probably your best bet. StringBufferInputStream is deprecated because it doesn't work reliably in the face of many character encodings.
    Speaking of encodings - never call Strng.getBytes() - always use the getBytes(character-encoding) version, so you KNOW what encoding you're getting!
    Grant

  • Regular expression - get longest number from string

    I believe it is easy one but I can't get it.Lets say I have a string 'A1_1000' I want to substract the 1000 using regular expression. When I feed Match regular expression I get '1' which is not the longest number. I know other ways of doing that but I want clean solution in one step. Does anybody knows the right regular expression to accomplish that? Thanks!
    LV 2011, Win7
    Solved!
    Go to Solution.

    ceties wrote:
    This is the best solution I was able to come with. I am just wondering if there is "smoother way" without the cycle.
    Since multiple checks are required I would tend to beieve that we do have to loop through the possibilities. in this example
    I start check at offset "0" into the string for a number. Provided i find a number I check if it is longer that any previous number I found and if so save the new longer number in the shift register.
    Have fun!
    Ben
    Message Edited by Ben on 04-15-2009 09:23 AM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Find_Longest.PNG ‏33 KB

  • Get Items from String

    VB.net
    I need to get the third and forth item from a string. The string varies in items within delimiter and total number of delimiters.
    My delimiter is :
    MyString = "ALL:0:Red:11Green:31:Blue:217"
    MyItems = "Red:11"
    Also, if elements 3 and 4 are not there, messagebox.show("Items don't exist.")
    Thanks,
    ADawn
    ADawn

    There is a : between 11 and Green.
    "ALL:0:Red:11:Green:31:Blue:217"
    ADawn
    ADawn
    Then it's even easier.
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim s As String = "ALL:0:Red:11:Green:31:Blue:217"
    Dim parts As List(Of String) = s.Split(":"c).ToList
    Dim allLabel As String = parts(0)
    Dim allValue As String = parts(1)
    Dim redLabel As String = parts(2)
    Dim redValue As String = parts(3)
    Dim greenLabel As String = parts(4)
    Dim greenValue As String = parts(5)
    Dim blueLabel As String = parts(6)
    Dim blueValue As String = parts(7)
    MsgBox(String.Format("{0}:{1}", redLabel, redValue))
    End Sub
    End Class
    “If you want something you've never had, you need to do something you've never done.”
    Don't forget to mark
    helpful posts and answers
    ! Answer an interesting question? Write a
    new article
    about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

  • Extract Number from string

    I need to extract the number, if it exists, from an alphanumeric text string.  I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
    I know this is a simple formula, but I can't quite get it.

    Are the two alpha and remaining numeric characters always in the same position within the string?
    Are the two alpha characters always going to be the same?
    Is the length of the numeric value following the two alpha characters always going to be the same?
    The more no answers you have to the above the tougher it will be!
    Get back with the above answers and possibly copy and paste some examples of the ENTIRE strings from which you will be extracting the values and let us know which are the values you'll be pulling from within the larger string.
    "I need to extract the number, if it exists, from an alphanumeric text string. I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
    I know this is a simple formula, but I can't quite get it."

  • More efficient way to extract number from string

    Hello guys,
    I am using this Regexp to extract numbers from a string, and I doubt that there is a more efficient way to get this done:
    SELECT  regexp_replace (regexp_replace ( REGEXp_REPLACE ('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ' , '[[:punct:]]',''), '[[:space:]]',''), '[[:alpha:]]','')  FROM dual
    {code}
    Is there a more efficient way to get this done ?
    Regards,
    Fateh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Or, with less writing, using Perl syntax \D (non-digit):
    SELECT  regexp_replace('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ','\D')
      FROM  dual
    REGEXP_REPLACE(
    003240008702234
    SQL>
    {code}
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to get substring from string using index?

    hi,
    here i am having string ,
    i want the pullareddy from below line ,
    i know how to get from substring.
    but i want to get the above using "index",
    can any help how to do it?
    String str1="janapana,pullareddy, in malaysia";
    jpullareddy

    get the start index with indexAt("pullareddy")
    get the end index with adding the length of the word to the start
    get the char[] of str1 with toCharArray()
    make a new string with the chars from start to end index.

  • Read only number from string and number

    I have "COM4" from my I/O.  how could to read number 4 only?
      Thank you
    Solved!
    Go to Solution.

    Hello, i might need your help regarding this matter.
    I'm current taking a reading from Arduino from 2 accerolmeter to Labview. X=0.02 Y=-0.03 Z=0.99 A=0.33 B=0.42 C=0.84 (Example) 
    But when i display them using Waveform Chart in labview, I need to use the array to count the position of the String from buffer which sometimes might be inaccurate due to the the value extracted.
    I was told that i can use Search string from the beginning to allow the waveform to take in only the numeric. 
    Are you able to assist me regarding this issue?
    Below attached are the pictures..
    Attachments:
    LabviewBlockDiagram.png ‏64 KB
    LabviewFrontPanel.png ‏196 KB

  • Help on getting value from string

    Hello can someone please help me with my code?
    I would like to know how to get a value in a string as an integer type
    This is what I have so far
    String x = "12345";
    for(int f=0; f<5; f++){
    int c = stringDigits.charAt(f);     
    sum += c;                
    However the sum does not turn out to be 1+2+3+4+5 = 15 because the value of c will always turn out to be 48 more than it is supposed to be
    for example when f = 1 then c would = 49
    f = 2 then c would = 51
    Thank you very much for your help

    int i = Integer.parseInt(x);
    Will convert the String to an integer.The original poster was looking for a way to convert a single digit in a string to its numeric value, not to convert the whole string to an integer.
    I forgot to mention that this is contained in the
    java.text package, so you will need to
    import java.text.*;Integer is in the java.lang package, so no import is necessary.

  • Can we get Arraylist from String.Please check the code

    Hi all,
    I have just pasted my code over here.Can anyone of you find the solution for obtaining the Array list from the String.
    For Example :
    ArrayList al = new ArrayList();
    al.add(new byte[2]);
    al.add("2");
    String stringVar = "" + (ArrayList) al;
    Here I can convert the arraylist into string.But can we do he vice versa like obtaining the above arraylist from the string?If please advice me.
    URGENT!!!!

    cudIf you run the code you posted you will observe that the string form of the list does not contain all the information of the list: in particular the array elements are missing. It follows that the "vice versa" conversion you seek is simply not possible.
    A variation on this theme is the following:import java.util.ArrayList;
    public class ListEg {
        public static void main(String[] args) {
            ArrayList al = new ArrayList();
            al.add("foo");
            al.add("bar, baz");
            String stringVar = "" + (ArrayList) al;     
            System.out.println(stringVar);
    }If you think about the output you should be able to conclude that lists with different contents can easily have the same string form.
    Just something to chew on.

  • Get path from string in an column

    I have an data with text and url. I need to seprate the url only in the column and display in sql query
    Need to get data after Url: and the next immediate " " {blank space}
    my data is like below
    seach engine Url: www.bing.com this is the world famous search enging
    mail box Url: www.hotmail.com email is free
    microsoft webstie Url: http:\\microsoft.com the home page of microsoft.
    ShanmugaRaj

    Try the below:
    Create table Test_Shan(Textstring Varchar(1000))
    Insert into Test_Shan Values ('seach engine Url: www.bing.com this is the world famous search enging'),
    ('mail box Url: www.hotmail.com email is free'),
    ('microsoft webstie Url: http:\\microsoft.com the home page of microsoft.')
    Select substring(LTRIM(stuff(Textstring,1,CHARINDEX('Url:',Textstring)+4,' ')),0,charindex(' ',LTRIM(stuff(Textstring,1,CHARINDEX('Url: ',Textstring)+4,' ')),0))
    From Test_Shan

Maybe you are looking for