To find substr within string

Hello,
I have a string (column is normal range) like 70 - 110 mg/dl.
I wanted to separate 70 and 110.
For 70 i am using like this
select substr(normal_range,1,instr(normal_range,'-')-1) from m_parameters where normal_range='70-110 mg/dL'. It works.
But how to get 110.
Some rows may also be 110-209 U/L without any space between '-'.I want a query which works for all conditions.
Conditions are.
1. 70 - 110 mg/dL
2. 70-110mg/dL
3. 70 -110mg/dL
4. 70- 110mg/dL
5. 70-110 mg/dL
thanks
Swapna

Hi Swapna,
Using the old-fashioned SUBSTR and INSTR combination:
SQL>   with t
  2  as
  3  (
  4  select '0.3 - 1.0 mg/dL' str from dual union all
  5  select '70 - 110 mg/dL' str from dual  union all
  6  select '70-110mg/dL   ' str from dual  union all
  7  select '70 -110mg/dL  ' str from dual  union all
  8  select '70- 110mg/dL  ' str from dual  union all
  9  select '70-110 mg/dL  ' str from dual
10  )
11  select trim(substr(str, 1, instr(str, '-') - 1)) num1,
12         trim(substr(str, instr(str, '-') + 1, instr(str, 'mg') - instr(str, '-') - 1 )) num2
13    from t;
NUM1            NUM2
0.3             1.0
70              110
70              110
70              110
70              110
70              110
6 rows selected.
SQL>Asif Momen
http://momendba.blogspot.com

Similar Messages

  • Find Substring in String in Workflow

    I'm trying to separate the content from GUID with metadata, but I can't find the Find Substring in String function in SharePoint Designer 2013 mentioned on
    MSDN. Can anyone provide guidance? Thanks!

    Its a not a function. It is workflow action under Actions menu in your SPD 2013. 
    You can find that action under the Utility Actions and make sure you have selected All Actions as show in the image above.
    Amit

  • Finding substring from string.

    I'll have to find substring from another string. Substring to find can be example: CVB and the string can be example ACHGVNB.
    Give me some hints about what methods I should use.

    Like this:public class Test {
        public static void main (String[] parameters) {
            String sub;
            String text;
            if (parameters.length == 2) {
                sub = parameters[0];
                text = parameters[1];
            } else {
                sub = "levi_h";
                text = "l e v i _ h";
            System.out.println (isSub (sub, text));
        private static boolean isSub (String sub, String text) {
            int s = 0;
            int t = 0;
            while ((s < sub.length ()) && (t < text.length ())) {
                if (sub.charAt (s) == text.charAt (t)) {
                    s ++;
                t ++;
            return s == sub.length ();
    }Kind regards,
    Levi

  • Find number within string

    Hi guys/gals,
    Im looking to be able to find a number (any number) within a text string, what i ultimately want to do is crop the number out of the string to just be left with a number value, the only problem is the string could be any length and the number doesnt necessarily start at any point from the last character
    I have items on the stage named 'image0', 'textfield2', 'button500' etc, as you can see the prefix before the number isnt a fixed length so I couldnt use substr and set an index, and since the number could be any number i couldnt set the index as a certain value before the end of the string. (ie it might return '500' or 'ld2' or 'ge0' in the examples given before)
    I was looking into how to use IndexOf, but I dont really know how to make it so that it finds any number rather than a specific one
    can anyone help me out?
    Thanks

    One way to do this is by using regular expressions.  In the example below, the str string has anything that is not a number removed.
    var str:String = "button500";
    var regex:RegExp = /\D/g; // matches anything that is not a digit
    var numStr:String = str.replace(regex, "");
    trace(numStr);

  • Help with finding digits within string

    Hi, I am very close (I believe) to finishing this program. Basically I need to scan the input (string) the user enters. If the input contains 2 digits then I outprint "Valid ID" if not, I outprint "Invalid ID"
    please review and if possible help fix it?
    Thank you.
    import java.util.Scanner;
    public class programTest
         public static void main(String[] args)
    d     {
         String id;//id entered by user
         Scanner kb=new Scanner(System.in);//scanner utility
              System.out.println("Please enter an ID: ");
              id=kb.next();//assigns user's id to variable id
              if (id.length()>=2 && id.length()<=9)
                      for (int i=0; i<id.length(); i++)
                        if(Character.isDigit(id.charAt(i)))//if id contains 2 digits
                        System.out.println(i);
                        System.out.println("Valid ID");
              }

    Finally! After sitting down for a few minutes and watching the show House I thought of a way to do it.
    I am almost POSITIVE there is a simpler way to do this, so if you have it please repost the more "efficient" way.
    Thank you very much for everyone's help!
    import java.util.Scanner;
    public class Test
         public static void main(String[] args)
         String id;//id entered by user
         Scanner kb=new Scanner(System.in);//scanner utility
         int digit=0;
              System.out.println("Please enter an ID: ");
              id=kb.next();//assigns user's id to variable id
              if (id.length()>=2 && id.length()<=9)
              {//if
                      for (int i=0; i<id.length(); i++)
                             if(Character.isDigit(id.charAt(i)))               
                             digit++;
                             if (digit!=2)
                             System.out.println("Invalid ID");
              }//if      
              else
                   {     System.out.println("Invalid ID");     }
              if (digit==2)
              System.out.println("Valid ID");          
    }

  • Searching for a substring within a string

    can someone reccomend a simple way to search for a substring within a string and count the number occurences of that substring.
    The substring and the string will be provided as command line parameters.
    Thanks
    gg

    A simple way would be to use the indexOf methods in String:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
    Not sure what this has to do with event handling though :-P

  • How can I find out  the strings that will be presented to the UI

    Hi All,
    I am working on a Swing based application (Swing based UI)
    I am requested to do the following on the bytecode of that application:
    I am supposed to find out what strings from within that bytecode will be presented to the UI and what will be used for an internal usage.
    i have no way of running the application to verify that, i can only work on the static bytecode files.
    hard question ha?
    Thanks,
    EItan.

    You would of course have to run it. Either via a VM or recreating a VM yourself.
    As an example of that how would you figure out what string occurs in the following (pseudo) code?
    String msg = (cnt > 1) ? ("files=" + cnt) : ("file=" + cnt);
    if (cnt > 1) DisplayMessage(msg);

  • BPM xpath issue with last-index-within-string

    Hey all,
    I have a script task in BPM that updates a field by using multiple xpath functions. I have narrowed the issue down to the oraext:last-index-within-string function.
    If I do something like oraext:last-index-within-string('ora/in/ok/d', '/').....I get 9 like expected.
    But if I base it off the request data like so:
    oraext:last-index-within-string(bpmn:getDataObject('Request')/ns:document/ns1:dDocAccount, '/')........when I go to em I have an internal xpath error.
    I'm assuming it has something to do with using bpmn:getDataObject as a parameter. But I'm not sure what. If I use the getDataObject as a parameter in substring like so:
    substring(bpmn:getDataObject('Request')/ns:document/ns1:dDocAccount, 8)....it works as expected.
    What is it about the combination with last-index-within-string that is giving me an issue??
    Thanks
    John

    Got it. Apparently, sometimes with xpath, you have to concatenate the variable with an empty string to change it into a string....sometimes, but not all the time...yay.... I'm guessing the xpath inbuilt functions already know to convert the variable passed in into a string, whereas the oraext functions don't. I could be completely wrong on that though...:-P . Anyway, this works:
    oraext:last-index-within-string(concat(bpmn:getDataObject('Result')/ns:document/ns1:dDocAccount, ''), '/')
    Thanks,
    John

  • Oracle Spatial function to find nearest line string based on lat/long

    Hi,
    Here is my scenario. I have a table that contains geometries of type line strings (the roadway network). The line geomteries are of type Ohio state plane south (SRID 41104).
    I have a requirement - given a lat/long, find the line string that snaps to that lat/long or the nearest set of line strings within a distance of 0.02 miles.
    This is a typical example of trying to identify a crash location on our roadway network. The crashes being reported to us in lat/long thru the GPS system.
    How can i acheive this through any spatial functions?
    Thanks for the help in advance.
    thanx,
    L.

    Hi L,
    That is not the way I would do it. I would convert my road segments to LRS data, then you can do all queries on the same data.
    Or, if you do not want to modify your original data, create a copy of your road segments with the same ID's and convert the copy into LRS data. If you keep the ID's identical, you can easily use geometry from one and LRS data from the other - as long as you are sure the ID is the same.
    Which will make the workflow a bit easier:
    1. Use SDO_NN to get the closest segments
    2. Use SDO_LRS.PROJECT_PT to get the projected point
    3. Use SDO_LRS.GET_MEASURE to get the measure
    And most of these you can incorporate into one single query. Now I am writing this of the top of my head (It's been a while since I played with LRS). so this has not been tested, but something like this should work (but could probably be greatly improved - it's getting late for me :-) ):
    SELECT
    SDO_LRS.FIND_MEASURE  --//find_measure needs an LRS segment and a point
        SELECT            --//here we select the LRS segment
          r.geometry 
        FROM
          roadsegments r
        WHERE SDO_NN(r.geometry,    --//based on the given GPS point
                     sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL), 
                     'sdo_num_res=2 distance=0.02 unit=mile') = 'TRUE'
      SDO_LRS.PROJECT_PT  --//We project the point on the LRS segment
          SELECT         --//here we select the LRS segment (again, which could probably be improved!!)
            r.geometry 
          FROM
            roadsegments r
          WHERE SDO_NN(r.geometry,
                       sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL), 
                       'sdo_num_res=2 distance=0.02 unit=mile') = 'TRUE'
        sdo_geometry(2001, 41104, sdo_point_type(lat,lon,NULL), NULL, NULL) --//The GPS point again
    AS milemarker from dual;So it is not as complicated as you think, it can easily be done with just one query (SQL can do a lot more than you think ;-) ).
    Good luck,
    Stefan

  • How to find the last string value in dynamic object?

    Hi All,
    I am trying to find the last string value in dyanamic objects,Any one have solution for this.
    Ex:
    my data :12347-ebjdone-525-ecgfjf-25236-defdafgdeg
    And i want to show the output is :defdafgdeg
    Any ideas:
    Thanks
    Srini

    For oracle try using oracle function.
    e.g.
    SELECT  reverse(substr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),1,instr(reverse('12347-ebjdone-525-ecgfjf-25236-defdafgdeg'),'-','1'))) from dual
    Object definition might look like:
    reverse(substr(reverse({ObjectName}),1,instr(reverse({ObjectsName}),'-','1')))
    Regards,
    Kuldeep
    Edited by: Kuldeep Chitrakar on Feb 12, 2010 8:12 AM

  • Index-within-string

    I have an xml string and there's a tag called </ErrorDescription>, I want to find where in the string does this tag begins. I used
    oraext:index-within-string(<inputstring>,'</ErrorDescription>') but I got the xpath error. I think it's because of the slash character (/).
    How do I escape it please?

    Hi,
    First try getting the xml as string using ora:getContentAsString and then use above function.

  • Find out varchar2 string NULL columns and Empty columns

    Hi dev's ,
    my requiremnt is to find out the string columns Names of whose storing NULL values and EMPTY strings. for that i had written below code. it's getting some error.
    SET ECHO OFF;
    SET FEEDBACK OFF;
    SET SERVEROUTPUT ON;
    SET VERIFY OFF;
    SET PAGES 0;
    SET HEAD OFF;
    spool D:\stringnull.csv
    DECLARE
      v_tab_indent NUMBER(5);
      v_col_indent NUMBER(5);
      v_val1       VARCHAR2(20);
      v_val2       VARCHAR2(20);
      v_query1     VARCHAR(500);
      v_query2     VARCHAR(500);
    BEGIN
      --DBMS_OUTPUT.ENABLE(100000);
      SELECT MAX(LENGTH(table_name))+1,MAX(LENGTH(column_name))    +1
      INTO v_tab_indent,v_col_indent
      FROM user_tab_columns
      WHERE data_type='VARCHAR2';
    FOR i IN
      (SELECT table_name,
        column_name
      FROM user_tab_columns
      WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      ORDER BY table_name,
        column_name
      LOOP
        v_query1:='SELECT NVL('||i.column_name||',0) AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||' IS NULL';
        v_query2:='SELECT '||i.column_name||' AS VAL    
                  FROM '||i.table_name||' where '||i.column_name||'=''''';
        --dbms_output.put_line(v_query1);
       -- dbms_output.put_line(v_query2);
        EXECUTE immediate v_query1 INTO v_val1;
        EXECUTE immediate v_query2 INTO v_val2;
        dbms_output.put_line (rpad(i.table_name,v_tab_indent,' ')||','||rpad(i.column_name,v_col_indent,' ')||' ,'||v_val1||','||v_val2);
      END LOOP;
    END;
    Spool OFF
    Set echo on
    Set feedback onERROR:
    Error report:
    ORA-01403: no data found
    ORA-06512: at line 31
    01403. 00000 -  "no data found"
    *Cause:   
    *Action:
    set feedback onpls help me on this issue..
    Thanks,

    Example:
    SQL> DECLARE
      2    v_val       VARCHAR2(20);
      3    v_query1     VARCHAR(32767);
      4  BEGIN
      5   FOR i IN (SELECT table_name, column_name FROM user_tab_columns
      6             WHERE data_type IN ('NVARCHAR2', 'CHAR', 'NCHAR', 'VARCHAR2')
      7             ORDER BY table_name, column_name
      8            )
      9   LOOP
    10     v_query1 := 'SELECT count(*) FROM '||i.table_name||' where '||i.column_name||' IS NULL';
    11     EXECUTE immediate v_query1 INTO v_val;
    12     dbms_output.put_line(rpad(i.table_name,30,' ')||' : '||rpad(i.column_name,30,' ')||' : '||v_val);
    13   END LOOP;
    14  END;
    15  /
    CHILD_TAB                      : DESCRIPTION                    : 0
    DEPT                           : DNAME                          : 0
    DEPT                           : LOC                            : 0
    EMP                            : ENAME                          : 0
    EMP                            : JOB                            : 0
    MYEMP_OLD                      : ENAME                          : 0
    MYEMP_OLD                      : JOB                            : 0
    MYNULLS                        : ENAME                          : 0
    MYNULLS                        : JOB                            : 4
    PARENT_TAB                     : DESCRIPTION                    : 0
    T                              : CHAR_VALUE                     : 0
    TABLE1                         : COL1_DESC                      : 0
    PL/SQL procedure successfully completed.

  • Drag-n-Drop not working (Finder and within apps)

    while using machine, after about 15 minutes or so, Drag-n-Drop stops working....in Finder and within all apps. Cant' move files within Finder; can't highlight text and move it within an app, can't D-n-D photos; nothing
    it takes either a system restart, or logout of user, then log back in as user and D-n-D is restored.
    But, it works for about 15 minutes or so, again...then stops functioning.
    Happens repeatedly, doesn't matter what apps I'm using, or even using any apps at all...just power up machine....move a few files...let it sit for a while and do nothing, and then D-n-D stops working again.
    This is very annoying...and makes Leopard almost useless, since I can't manipulate anything with the mouse.
    HHHHEEELLLPPP!!!!!!

    I am having the same problem. Even restarting does not work, i am using a jail iphone 3gs, not sure if thats got anything to do with it?
    Anyone help, the only way i can get albums etc to add is to sync and that messing all kinds up.

  • Use REGEXP_INSTR to find a text string with space(s) in it

    I am trying to use REGEXP_INSTR to find a text string with space(s) in it.
    (This is in a Function.)
    Let's say ParmIn_Look_For has a value of 'black dog'. I want to see if
    ParmIn_Search_This_String has 'black dog' anywhere in it. But it gives an error
    Syntax error on command line.
    If ParmIn_Look_For is just 'black' or 'dog' it works fine.
    Is there some way to put single quotes/double quotes around ParmIn_Look_For so this will
    look for 'black dog' ??
    Also: If I want to use the option of ignoring white space, is the last parm
    'ix' 'i,x' or what ?
    SELECT
    REGEXP_INSTR(ParmIn_Search_This_String,
    '('||ParmIn_Look_For||')+', 1, 1, 0, 'i')
    INTO Position_Found_In_String
    FROM DUAL;
    Thanks, Wayne

    Maybe something like this ?
    test@ORA10G>
    test@ORA10G> with t as (
      2    select 1 as num, 'this sentence has a black dog in it' as str from dual union all
      3    select 2, 'this sentence does not' from dual union all
      4    select 3, 'yet another dog that is black' from dual union all
      5    select 4, 'yet another black dog' from dual union all
      6    select 5, 'black dogs everywhere...' from dual union all
      7    select 6, 'black dog running after me...' from dual union all
      8    select 7, 'i saw a black dog' from dual)
      9  --
    10  select num, str
    11  from t
    12  where regexp_like(str,'black dog');
           NUM STR
             1 this sentence has a black dog in it
             4 yet another black dog
             5 black dogs everywhere...
             6 black dog running after me...
             7 i saw a black dog
    5 rows selected.
    test@ORA10G>
    test@ORA10G>pratz
    Also, 'x' ignores whitespace characters. Link to doc:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#i1048942
    Message was edited by:
    pratz

  • Finding a Particular string in a Database in the most Optimized way

     Hi All,
              Below is the query to find  a Particular String in the entire database tables,I have a Database of about 500 + tables and each contains many data's .In these tables i want to find a particular
    string but didn't know the column name and table name.so i did as below,but for executing this it almost take 40 - 45 minutes.Is there any other way to Optimize this and make the Query execution Faster.I am copying the code below.Please comment
    DECLARE
        @search_string  VARCHAR(100),
        @table_name     SYSNAME,
        @table_id       INT,
        @column_name    SYSNAME,
        @sql_string     VARCHAR(2000),
     @TableCount    INT,
     @ColumnCount   INT
    SET @search_string = 'Developer'
    DECLARE   @Tables TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    DECLARE   @Columns TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    INSERT INTO @Tables
    SELECT name, object_id FROM sys.objects WHERE type = 'U'
    SELECT @TableCount=COUNT(1) FROM @Tables
    WHILE (@TableCount >0)
    BEGIN
      SELECT TOP(1)
         @table_name=name
        ,@table_id=id
      FROM  @Tables ORDER BY Rownumber
    INSERT INTO @Columns
    SELECT name,object_id FROM sys.columns WHERE object_id = @table_id AND system_type_id IN (167, 175, 231, 239)
    SELECT @ColumnCount=COUNT(1) FROM @Columns
      WHILE (@ColumnCount >0)
      BEGIN
        SELECT TOP(1)
           @column_name=name
        FROM  @Columns
        WHERE id= @table_id
         ORDER BY Rownumber
         --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''%' + @search_string + '%'') PRINT ''' + @table_name + ', ' + @column_name + ''''
          SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''' + @search_string + '%'') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         --select (@sql_string);
          --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] = ''' + @search_string + ''') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         EXECUTE(@sql_string)
       SET @ColumnCount=@ColumnCount-1
       DELETE FROM @Columns WHERE  Name =   @Column_Name
      END
    SET @TableCount=@TableCount-1
    DELETE FROM @Tables WHERE Name= @Table_Name
    END

    You may also try the below :
    http://gallery.technet.microsoft.com/c0c57332-8624-48c0-b4c3-5b31fe641c58

Maybe you are looking for