Substring to convert from varchar2 to number

Hello all,
I have a little question..
columnA
'123 d'
'98-f'
'34.4'
How is it possible to get only the fist number characters of the column?
select substr(columnA,1,instr(columnA, non number char ) from dual ..
Anyone can help me ?
tnx Ludo

Hi, Ravi,
ravikumar.sv wrote:
Ludock wrote:
Hello all,
I have a little question..
columnA
'123 d'
'98-f'
'34.4'
since decimals are also there in your data....You're right! I missed that.
select REGEXP_SUBSTR ( val1, '[[:digit:]]+\.?[[:digit:]]+')that requires there to be at least one digit before the decimal point and at least one digit after the decimal point.
Even worse, it ignores single-digit numbers unless they are followed by a decimal point and at least one more digit.
Unfortunately, to really check for numbers (including optional decimal points) is much messier.
For example:
TO_NUMBER (REGEXP_SUBSTR ( columna
                      , '[+-]?'          ||     -- Optional sign
                  '('               ||     -- choice: either
                    '[0-9]+'     ||     --   (1) 1 or more digits
                    '\.?'          ||     --         then an optional decimal point
                        '[0-9]*'     ||     --         then 0 or more digits
                  '|'               ||     -- or
                    '\.'          ||     --   (2) a decimal point
                    '[0-9]+'     ||     --         followed by 1 or more digits
          )            )Edited by: Frank Kulash on Oct 30, 2009 8:18 AM

Similar Messages

  • Convert from date to number

    Hi,
    I want to convert from date to number. How can I do?
    Thanks
    [email protected]

    That rather depends on what sort of number you want.
    You can probably get what you want by a combination of to_char and to_number.

  • How to convert from Datetime to number?

    chg_date_time
    40265.492
    SELECT c.chg_date_time, TO_DATE('01011900','DDMMYYYY')+CHG_DATE_TIME FROM CHNGHIST C
    After execute:
    30/03/2010 11:48:29
    In the above query, we convert number to datetime.
    Now I want to convert from Datetime to number.
    i.e., 30/03/2010 11:48:29 = ? (40265.492)
    Thanks
    Nihar

    Hello,
    This would do it :SQL> select to_date('30/03/2010 11:48:29','dd/mm/yyyy hh24:mi:ss') - TO_DATE('01011900','DDMMYYYY') nmbr from dual;
          NMBR
    40265,492
    1 row selected.

  • Change column datatype from varchar2 to number(10) and keep existing data

    Hi,
    I need to change the datatype on a column that already has data in it from a varchar2 to number(10). The data that is already there is not necessarily number data, however I must be able to keep the old data to. We are running 10g. Does anyone have any ideas? Thanks. Here's the current data.
    Current Values for From_Value
    T
    U
    T2
    K
    M
    A
    T
    T1
    O
    E
    S
    NSTU
    4

    Example of keeping the data in the current column and adding a new numeric column for numeric data:
    SQL> drop table t purge;
    Table dropped.
    SQL> create table t(i int, x varchar2(10));
    Table created.
    SQL> insert into t values(1, 'T1');
    1 row created.
    SQL> insert into t values(2, 2);
    1 row created.
    SQL> --
    SQL> alter table t add (xn number);
    Table altered.
    SQL> --
    SQL> begin
      2  for c in (select i, x from t)
      3  loop
      4   begin
      5   update t set xn = to_number(c.x) where i = c.i;
      6   exception
      7    when invalid_number then null;
      8   end;
      9  end loop;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> show errors
    No errors.
    SQL> select * from t;
             I X                  XN
             1 T1
             2 2                   2

  • Take the average of the measured values wich cannot be converted from string to number..

    Hello,
    I have a Keithley 182 Digital Nanometer (K182). I am usins it to measure voltage at high temperature. I want K182 to measure 3 times and then take the avarage of collected data.
    1. First problem is, as you can see from picture, string to number conversion. I tried many ways but I couldn't do it. Values as you see 0,00, and once was
    3,98E-3
    0,00
    392,0
    originan values were
    3,98E-3
    3,95E-3
    3,93E-3
    in table, values generally like this.
    2. I need to take avarege. So i need toindez data, then take avarage. So, I have also problem here...
    Could you please help on thic topic. Thanks in advance.
    Attachments:
    string-number.png ‏19 KB
    string-number-panel.png ‏30 KB

    thank you, I will try this solution. Also I want to do one more thing. So, I am collecting data and putting them in to table let say data are like this
    Temp1     Temp2   Volt
    123,3       234,5      ...
    234,4       567,7
    345,6       789,9
    456,7       678,8
    I want to put data with increment like this given below:
    No  Temp1     Temp2   Volt
    1    123,3       234,5      ...
    2    234,4       567,7    
    3    345,6       789,9
    4    456,7       678,8
    there are no exact number of data. the number of data can change from measurement to measurement (1000, 2000, 500 more or less). How can I program this increment in my system.
    My system is include LakeShore 336 temperature conroller and Keithley 182 Nanovoltmeter. I will set the temperature specified value from room temperature wtih specific ramp rate. Meanwhile I will measure the voltage from sample via K182. So, I can measure both temp, and voltage via taking help from u.

  • Varchar2 to number

    how change the datatype of a col from varchar2 to number????the col is not empty

    Assuming that the column name you want to change the datatype is orig_col follow below steps:
    Add a new column to table say TEMP_COL with Datatype as NUMBER
    ALTER TABLE table_name ADD ( TEMP_COL NUMBER);Update the new column with the values of ORIG_COL
    UPDATE table_name
       SET TEMP_COL   = TO_NUMBER(ORIG_COL); Drop the Original Column
    ALTER TABLE table_name DROP ( ORIG_COL ); Rename the TEMP_COL to ORIG_COL
    ALTER TABLE table_name RENAME TEMP_COL TO ORIG_COL; Create any indexed/constraints which were present on ORIG_COL
    Regards
    Arun
    Edited by: Arun Kumar Gupta on May 23, 2011 10:04 AM

  • Invalid number error when trying to convert a varchar2 to a number.

    I need to extract the middle four numbers from a varchar2(12) and then convert it to a number. The middle four are numbers but the first four can have letters. I've tried
    TO_NUMBER(substr(wptk.ext_wo_num,5,4))
    TO_NUMBER(LPAD(wptk.ext_wo_num,5,4))
    substr(TO_NUMBER(wptk.ext_wo_num) ,5,4)
    cast as number
    I need to get rid of any 0 that are at the beginning of the four numbers. Some of the data has no 0 and some can have up to three 0 at the beginning. Is there a way to do that?
    thanks.

    user10426897 wrote:
    I came back with 56 rows that look like this 1127-0651-E1. I am trying to translate an ingres view into Oracle that has this in the select statement: INT4(LEFT(TRIM(RIGHT(wptk.ext_wo_num,8)),4))You could use regular expressions...
    SQL> with t as (select '065101412354' as num from dual union all
      2             select '065106523237' from dual union all
      3             select '065206523238' from dual union all
      4             select '065606542356' from dual union all
      5             select '080101410218' from dual union all
      6             select '080102520218' from dual union all
      7             select '080106020218' from dual union all
      8             select '080201120219' from dual union all
      9             select '080601111214' from dual union all
    10             select '080801351216' from dual union all
    11             select '080802511216' from dual union all
    12             select '10000133013' from dual union all
    13             select '10000133SC3' from dual union all
    14             select '10000133SP4' from dual union all
    15             select '10000211011' from dual union all
    16             select '10000241011' from dual union all
    17             select '10000601S29' from dual union all
    18             select '10000601SC1' from dual union all
    19             select '10000601SH2' from dual union all
    20             select '10000601SP2' from dual union all
    21             select '10000602A11' from dual union all
    22             select '10000602A50' from dual union all
    23             select '10000602A54' from dual union all
    24             select '10000602A59' from dual union all
    25             select '10000602C06' from dual union all
    26             select '10000602E67' from dual union all
    27             select '10000602M00' from dual union all
    28             select '10000602M01' from dual union all
    29             select '10000602M07' from dual union all
    30             select '1127-0651-E1' from dual)
    31  --
    32  select num, to_number(regexp_replace(num,'^.{4}-?([0-9]{4}).*$','\1')) as num_num
    33  from t
    34  /
    NUM            NUM_NUM
    065101412354       141
    065106523237       652
    065206523238       652
    065606542356       654
    080101410218       141
    080102520218       252
    080106020218       602
    080201120219       112
    080601111214       111
    080801351216       135
    080802511216       251
    10000133013        133
    10000133SC3        133
    10000133SP4        133
    10000211011        211
    10000241011        241
    10000601S29        601
    10000601SC1        601
    10000601SH2        601
    10000601SP2        601
    10000602A11        602
    10000602A50        602
    10000602A54        602
    10000602A59        602
    10000602C06        602
    10000602E67        602
    10000602M00        602
    10000602M01        602
    10000602M07        602
    1127-0651-E1       651
    30 rows selected.
    SQL>

  • Convert from latin iso-1 charset to varchar2

    Hi,
    how can i convert from latin iso-1 charset to varchar2?
    for example the & sign that is & amp;
    Cheers.
    Message was edited by:
    edfimasa
    Message was edited by:
    edfimasa

    You cannot do conversion from ISO 8859-1 to UTF-8 in-place because the UTF-8 version will generally be longer (unless you convert a pure ASCII file, which does not need conversion in the first place). Therefore, you would have to overwrite what you have not read yet. Instead, convert to a new file with a temporary name, drop the original and rename the temporary back to original. This is not that complicated.
    If the problem is that you want to overwrite a file already open by the database, then rename the incoming file first and then convert copying to the target.
    -- Sergiusz

  • Error in Oracle 10 Procedure - converted from SQL Server

    I have converted the folowing script from SQL Server proc to Oracle Proc; it compiles with a warning "30 Hint: Comparision with NULL in 'sp_MyEmployee'"
    When this proc is executed; it generates an error "ORA-00900: invalid SQL statement"
    Please help!
    CREATE OR REPLACE PROCEDURE osp_DMEmployee(v_ahRole IN VARCHAR2 DEFAULT null,
                        v_Exclusion IN varchar2 DEFAULT null) as
    v_MyString varchar2(32767);
    v_spot NUMBER(5,0);
    v_str varchar2(8000);
    v_email varchar2(5000);
    SWV_Exclusion varchar2(5000);
    BEGIN
    SWV_Exclusion := v_Exclusion;
    v_MyString := 'SQLWAYS_EVAL# exprsnlid, dmdescription, dmregion, dmfieldloc, dmbusentity,
                                  dmemployeenum, dmusername, dmtitle, dmemail, ahrole
                             FROM dm_Employee WHERE dmEmail is NOT NULL';
    if v_ahRole is not NULL then
    IF v_ahRole = 'PLANNER' then
    v_MyString := v_MyString || 'SQLWAYS_EVAL# AND (DMTitle like ''%Coord%'' OR DMTitle like ''%Planner%'' OR DMTitle like ''%Svc Leader%'') ';
    end if;
    IF v_ahRole = 'TECHNICIAN' then
    v_MyString := v_MyString || 'SQLWAYS_EVAL# ''' || v_ahRole || 'SQLWAYS_EVAL# is NOT NULL ';
    end if;
    IF v_ahRole = 'SUPERVISOR' then
    v_MyString := v_MyString || 'SQLWAYS_EVAL# ''' || v_ahRole || 'SQLWAYS_EVAL# is NOT NULL ';
    end if;
    end if;     
    IF SWV_Exclusion is NOT NULL then
    /* WHILE SUBSTR(CAST(SWV_Exclusion AS VARCHAR2),1,4000) <> '' LOOP */
    WHILE SWV_Exclusion <> '' LOOP
    v_spot := instr(SWV_Exclusion,',');
    IF v_spot > 0 then
    v_str := SUBSTR(SWV_Exclusion,1,v_spot -1);
    SWV_Exclusion := SUBSTR(SWV_Exclusion,-(LENGTH(SWV_Exclusion) -v_spot));
    ELSE
    v_str := SWV_Exclusion;
    SWV_Exclusion := '';
    end if;
    IF v_email is NOT NULL then
    v_email := v_email || ',' || ' ''' || SUBSTR(v_str,1,100) || ''' ';
    ELSE
    v_email := ' ''' || SUBSTR(v_str,1,100) || ''' ';
    end if;
    END LOOP;
    end if;
    v_MyString := v_MyString || 'SQLWAYS_EVAL# IN (' || v_email || ')';
    v_MyString := v_MyString || 'SQLWAYS_EVAL# ail';
    DBMS_OUTPUT.PUT_LINE(SUBSTR(v_MyString,1,250));
    EXECUTE IMMEDIATE v_MyString;
    RETURN;
    END;

    1) When discussing an error, please copy the actual error message. Usually you will get a line number to assist investigation;
    2) Please refer to the FAQ (upper right corner of page) to show how to preserve code and make your question more readable;
    3) Please ask the question in a forum that deals with the topic - such as "Database - General" (look for "Forum Home" link at top left of page)
    4) Please note that the title of this forum is "Community Feedback and Suggestions (Do Not Post Product-Related Questions Here)"
    (And ... did you display the SQL that you were attempting to execute. Execute Immediate is a last resort style of programming - not nice for most Oracle apps.)

  • Converting varchar list to number

    hi everybody,
    can anyone help me to convert the varchar to number
    ex
    the input arg is varchar in this query below
    select * from student where rollno in ('1,2,3,4');
    in this example the roll no is of type number.when i use to_number function it shows error.
    how can i conver to number list?
    so that the query can change like this
    select * from student where rollno in (1,2,3,4);
    thanks
    Message was edited by:
    user542111

    It worked for me.
    SQL> select to_number('542111') from dual;
    TO_NUMBER('542111')
    542111
    SQL>
    Try to run this (Assumeing rollno is varchar2)
    SQL> select to_number(rollno) from student where rollno in ('1','2','3','4');

  • TO_CHAR to convert date getting 'Invalid number' error

    I am trying to convert a static date value using TO_CHAR function but I can't believe I am not able to do it such a simple conversion.
    //Obviously this is easy and everyone would like to give this as an example and this is what I see everwhere on Google and it works.
    SELECT TO_CHAR(sysdate, 'YYYY-MM-DD') FROM DUAL;
    How can I make it work like this?
    SELECT TO_CHAR('2010-JUN-23', 'YYYY-MM-DD') FROM DUAL;
    I keep getting "Invalid number" error. I changed my constant date to different formats but none works.

    Your first literal is not a date, assuming you didn't set NLS_DATE_FORMAT.
    So the code should have been
    SELECT TO_CHAR(to_date('2010-JUN-23','YYYY-MON-DD'), 'YYYY-MM-DD') FROM DUAL;
    Please note DATEs are always converted to VARCHAR2 when you SELECT them, using NLS_DATE_FORMAT.
    When you use a DATE string literal it ias always implicitly converted to a real date, by using NLS_DATE_FORMAT.
    So if you want all your dates formatted as YYYY-MON-DD, you need to set NLS_DATE_FORMAT to that mask.
    Sybrand Bakker
    Senior Oracle DBA

  • XML: LPX-00200: could not convert from encoding UTF-8 to UCS2

    Hi,
    Greetings!
    I have special character(s) in a column and that character is chr(189) and because of that when i use the xml functions in my query it returns below error.
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00200: could not convert from encoding UTF-8 to UCS2
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 1
    I am using sys_xmlagg and getting above error when i encounter the data as below:
    "Dixon¿s Chicago".
    Note: When ever It encounters the bold character string it fails ... Any help !!!
    And one more thing when i create another record with same data by copy and pasting it works fine and when i did a dump on that column data its different. see the below result of dump.
    Naveen.
    SQL> desc temp_xml;
    Name Null? Type
    TNO NUMBER(4)
    NAME VARCHAR2(255)
    SQL> select name,length(name),dump(replace(name,chr(189),'')) data_dmp from temp_xml;
    NAME LENGTH(NAME) DATA_DMP
    ¿s Chicago 10 Typ=1 Len=12: 239,191,189,115,32,67,104,105,99,97,103,111
    ¿s Chicago 10 Typ=1 Len=11: 194,191,115,32,67,104,105,99,97,103,111
    SQL>
    if you observe the above 2 rows the fist row shows length as 12 and second shows as 11. actually 2nd rows works fine but first gives error. I am not able to see where that hidden character is and not able to remove that character.
    Message was edited by:
    naveenhks

    Hi,
    I have a similar problem:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00200: could not convert from encoding UTF-8 to ISO-8859-1I'm executing the following Select when encountering this error:
    SELECT /*+ INDEX(resource_view XDBHI_IDX) */
               extract(resource_view.res, '/Resource/Contents/*').getClobVal()           AS Dokument
      FROM  resource_view
    WHERE resource_view.any_path LIKE '%PATH_TO_FILE%';I have 5 XML-documents and this error occurs at two ('A' and 'B') of them. When I transfer the same 5 documents from another PC the error occurs at document 'C' and not at 'A' and 'B'.
    Any clue or hint which could explain this behaviour? What NLS parameters can I check in order to help you understand the situation?
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

  • Change Parameter from VarChar2 to CLOB

    Hi,
    I have a function csvToArray which takes a csv string and converts it to an array.
    PROCEDURE csvToArray(p_csvString IN VarChar2,
    p_count OUT PLS_INTEGER,
    p_array OUT ARRAY_T) IS...
    Unfortunately the size of the csvString being passed in exceeds 32K, so I was thinking about changing the type of the csvString from Varchar2 to CLOB,i.e
    PROCEDURE csvToArray(p_csvString IN CLOB,
    p_count OUT PLS_INTEGER,
    p_array OUT ARRAY_T) IS...
    The procedure only uses the string functions instr and substr to find the elements of the csv string to place in an array.
    I've tested the change and it works, but is there anything I should consider with the change to the data type, or will the above always work fine? The extreme max size of p_csvString would be around 150K.
    Database version is 10.2.0.4.0
    Thanks

    Hi,
    This test maybe helpful
    Passed Length 65K test
    create or replace procedure my_pro ( pclob clob)
    is
    begin
      dbms_output.put_line('clob passed LEN:' ||
       dbms_lob.getlength(pclob) );
    end;
    Procedure created.
    SQL> exec my_pro( to_clob(lpad('x',32767,'c')||lpad('x',32767,'c')||'x'));
    clob passed LEN:65535
    PL/SQL procedure successfully completed.SS

  • Converting a VARCHAR to NUMBER

    Hello everyone,
    I wonder if you can help me. I have a VARCHAR column called "COLUMN_X" and the value of this column is: 15.41854 and I'm trying to insert this column into COLUMN_Y of another table, and COLUMN_Y is a NUMBER. When I try to convert COLUMN_X into NUMBER I get an error because there is a blank space after the values on "COLUMN_X". What function can I use to get rid of the space behind the values in "COLUMN_X" so that I can convert it successfully?
    So basically I'm trying to do the following:
    INSERT INTO TABLE_Y
          (COLUMN_Y)                           --Column Y is a NUMBER type
    SELECT TO_NUMBER(COLUMN_X)    --Column X is a VARCHAR type
    FROM TABLE_XThanking you in advance

    user643734 wrote:
    When I try to convert COLUMN_X into NUMBER I get an error because there is a blank space after the values on "COLUMN_X". Are you sure?
    SQL> SELECT TO_NUMBER('15.41853   ') FROM DUAL;
    TO_NUMBER('15.41853')
                 15.41853
    1 row selected.You can do something like this to identify the columns with bad data:
    CREATE FUNCTION bad_number(v IN VARCHAR2)
    RETURN NUMBER
    AS
         x NUMBER;
    BEGIN
         x := TO_NUMBER(v);
         RETURN 1;
    EXCEPTION
         WHEN OTHERS THEN
              RETURN 0;
    END;
    SELECT *
    FROM   table_x
    WHERE  bad_number(column_x) = 0
    ;Example:
    SQL> WITH table_x AS
      2  (  SELECT '15' AS column_x FROM DUAL UNION ALL
      3     SELECT '15.43143 ' AS column_x FROM DUAL UNION ALL
      4     SELECT '15A' AS column_x FROM DUAL
      5  )
      6  SELECT *
      7  FROM   table_x
      8  WHERE  bad_number(column_x) = 0
      9  ;
    COLUMN_X
    15AEdited by: Centinul on Feb 2, 2012 8:32 AM

  • Need to convert the Varchar2 to decimal

    Hi,
    I need to convert source sybase varchar2 record in to decimal record in Target DB2 table by using the function in Oracle data integrator.
    In my source table, column is defined as varchar2 (4) and in target table same column has defined as Decimal (2). So, is there any function to convert the varchar2 data to decimal record.
    thanks,
    keshav.

    Hi SH,
    Thanx so much for your answer!
    Well actually I have managed to do the filters, and right now dealing with the convertion of formats.
    Right now I am working with Oracle DB 11g, and Excel; and what i would like to do is now that is passing from my uploaded excel the info to my Oracle DB would like to control the ways it pases the info.
    Let's say for example, that I have gotten a Field A in my source table (Excel uploaded to ODI), and that on my Orazle Table on Field A i would like to change the data type of the field, or just make sure that the data inserted will always be of certain type? Can I do this with ODI? Could you please give me some advice in how to it? I assume that it should be done on my interface, in the Diagram tab > Target Database > Mapping Area > Implementation Tab > Expression Editor and modify it there, is it?
    As this is mapping from excel, can I just use the excel function? it does not make any sense for me as it is all in Oracle. I am sorry but I am kinda confused now.
    Once again I do really appreciate your help.

Maybe you are looking for

  • IPhoto, how is the best way to back up all my many photos?

    I have on my iMac it is finder 10.5 iPhoto does not allow me to back up to USB only burn?

  • WPC Cannot render container with special characters

    Hi My portal generates error: "Cannot render container : An error occurred while loading the document from the resource content" when i Finish editing my page.  The special characters that I use are words with accents only with capital letters (used

  • PSE does not open the editor from LR 4.4.......a big problem for a lot of people.

    I have PSE 12 and LR 4.4 on iMac 10.9.5.  My LR preference is set to PSE Editor and was done so by LR, I cannot change it.  When I try to edit in PSE, an 8 bit Tiff is created then I get the error message that "there was a problem.......".  In the de

  • Model name length restrictions

    Using trial and error with the Oracle-Jena adaptor, I seem to have discovered an upper limit of 25 characters on the length of RDF model names that Oracle will let you create. Can somebody verify this for me? If so, I'm curious as to why 25 was chose

  • See body of a package that belongs to another schema

    Hello, I'm facing the following issue: We have 2 schemas - apps (oracle aaplications master schema, with dba role) and a custom schema, to which our development team connects. We use pl/sql developer v. 7.1.5 and DB 10gR2. When I connect to the custo