Converting varchar2 to date format

I've converted date formats many times, but for some reason I'm getting an invalid number error when trying to convert a varchar2 column. I've tried the to_char and to_date function and I get the same result. The column is a date and it is formatted as DD-MON-YYYY, but I want to change it to MM/DD/YYYY. My query is below:
select to_date('fccpdate','MM/DD/YYYY')
from cc_class_scmast_v
When I try to_date I get this:
Error starting at line 1 in command:
select TO_DATE('fccpdate', 'DD-MON-YYYY') from cc_class_scmast_v where fccpdate IS NOT NULL
Error report:
SQL Error: ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action:   Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
When I try to_char I get this:
Error starting at line 1 in command:
select TO_char('fccpdate', 'DD-MON-YYYY') from cc_class_scmast_v where fccpdate IS NOT NULL
Error report:
SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:   
*Action:
I've tried removing the single quotes from my column and that doesn't make a difference. Any help is appreciated.

Hi,
housetiger77 wrote:
I've converted date formats many times, but for some reason I'm getting an invalid number error when trying to convert a varchar2 column. I've tried the to_char and to_date function and I get the same result. The column is a date and it is formatted as DD-MON-YYYY,If the column is a DATE, then it has the same format that all DATEs have, which is nothing like 'DD-MON-YYYY'. Formats like that only apply to strings.
Conversely, if it is formatted as 'DD-MON-YYY', then it is a string, not a DATE.
but I want to change it to MM/DD/YYYY. My query is below:
select to_date('fccpdate','MM/DD/YYYY')
from cc_class_scmast_vTO_DATE (x, 'MM/DD/YYYY') tries to convert the string x into a DATE. Let's say it starts by taking the first 2 characters of x, to get the month. The first 2 charcters of 'fccpdate' are 'fc', which is not a valid number (at least not in base 10), let alone a number between 1 and 12, so TO_DATE raises an error.
When I try to_date I get this:
Error starting at line 1 in command:
select TO_DATE('fccpdate', 'DD-MON-YYYY') from cc_class_scmast_v where fccpdate IS NOT NULL
Error report:
SQL Error: ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action:   Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
When I try to_char I get this:
Error starting at line 1 in command:
select TO_char('fccpdate', 'DD-MON-YYYY') from cc_class_scmast_v where fccpdate IS NOT NULL
Error report:
SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:   
*Action:
I've tried removing the single quotes from my column and that doesn't make a difference. Any help is appreciated.That's a good first step. Literals are enclosed in single-quotes, identifiers (including column names) are not. 'fccpdate' is the literal 8-character string containing 'f', 'c;, another 'c', 'p', 'd', 'a', 't' and 'e'. fccpdate (without single-quotes) can be the name of a column.
If fccpdate is a string, such as '18-JUL-2012', then you can convert it to a DATE using TO_DATE.
TO_DATE (fccpdate, 'DD-MON-YYYY')If you want to display a DATE in a particular format, use
TO_CHAR ( d
        , f
        )where d is a DATE, and f is the format string. In this case, d might be the TO_DATE expression above
TO_CHAR ( TO_DATE (fccpdate, 'DD-MON-YYYY')
        , 'MM/DD/YYYY'
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, 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.
See the forum FAQ {message:id=9360002}

Similar Messages

  • How to Convert Varchar2 to Date format(Timestamp)

    I have a date saved in varchar2 column.
    how can I convert the values into date(including Time stamp), so I can use the date to compare data.
    Ex: I have the value '20-03-2007 05:31:29', but this value is saved as varchar2.
    how can I take from this value the date '20-03-2007 05:31:29' as date format because later i need that date completely to add days, hours and minutes?

    SQL> create table dd (a varchar2(15));
    Table created.
    SQL>
    SQL>
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL> insert into dd values (sysdate);
    1 row created.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select * from dd;
    A
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    6 rows selected.
    SQL>
    SQL>
    SQL> select to_date(a,'dd-mon-yyyy') from dd;
    TO_DATE(A
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    01-OCT-12
    6 rows selected.
    SQL> select to_timestamp(to_date(a,'dd-mon-yyyy'),'dd mon yy hh24.mi.ss' ) from dd;
    TO_TIMESTAMP(TO_DATE(A,'DD-MON-YYYY'),'DDMONYYHH24.MI.SS')
    01-OCT-12 12.00.00 AM
    01-OCT-12 12.00.00 AM
    01-OCT-12 12.00.00 AM
    01-OCT-12 12.00.00 AM
    01-OCT-12 12.00.00 AM
    01-OCT-12 12.00.00 AM
    6 rows selected.
    SQL>
    that's it......

  • Convert to a date format

    Hi,
    I have a table with a date field that comes as varchar2(20byte) with a content like this:
    20/Jan/2011
    and I need it to be converted toa real date format e.g. 20.01.2011.
    Please help,
    Thanks
    Walter

    Hi, Walter,
    user457173 wrote:
    Hi,
    I have a table with a date field that comes as varchar2(20byte) with a content like this:
    20/Jan/2011
    and I need it to be converted toa real date format e.g. 20.01.2011.'20/Jan/2011' is actually just as "real" as '20.01.2011'. Neither is a real DATE; both are strings.
    Please help,
    Thanks
    WalterUse TO_DATE to convert a string into a DATE:
    TO_DATE ( column_x
            , 'DD/Mon/YYYY'
            )Use TO_CHAR to display a DATE in a given format:
    TO_CHAR ( d
            , 'DD.MM.YYYY'
            )d can be any DATE, including the DATE returned by the TO_DATE function, above.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    Edited by: Frank Kulash on Oct 25, 2011 7:57 AM

  • Convert Char to Date format - Evaluate

    Hi,
    Could anyone provide us the Evaluate formula to convert Char to Date format
    2009-06-20 should be converted to 06/20/2009
    Regards,
    Vinay

    Hi,
    Refer the below threads...
    Re: How to convert string to date format?
    how to convert character string into date format????
    Regards,
    Chithra Saravanan

  • I want convert string to date format in Oracle

    Dear All
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'

    >
    Hi Parwez,
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'SELECT TO_DATE('Friday, 02 March 2012 2:44 P.M.', 'DAY, DD MONTH YYYY HH:MI A.M.') from dual;
    As well as what the other poster suggested, look here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
    HTH,
    Paul...

  • How to convert milliseconds to date format in sql query

    Hi All,
    The following code is in java.     
    String yourmilliseconds = "1316673707162";**
    Date resultdate = new Date(Long.parseLong(yourmilliseconds));
    could you plese tell me how to convert milliseconds into date format in query and comparing with another date like(sysdate-3)

    Hello,
    http://stackoverflow.com/questions/3820179/convert-epoch-to-date-in-sqlplus-oracle
    Regards

  • How to convert Milliseconds into Date format

    Hi all,
    I am getting the output of a variable in milliseconds format, how can I convert it into date format
    For ex: I am getting input variable as 1366664691000 and I need to convert it to April 22, 2013 5:04:51 PM EDT ( or of SOA format). is there any function for this in XSL or XPath?
    Thanks,

    It is working fine if i test it in provided site...
    But it is returning "-1366664691001", If i am running it in EM. This is the code in my xsl
    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
    <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
    <mapSources>
    <source type="WSDL">
    <schema location="../JavaProcess.wsdl"/>
    <rootElement name="process" namespace="http://xmlns.oracle.com/SampleApplication/JavaEmbeddingActivity/JavaProcess"/>
    </source>
    </mapSources>
    <mapTargets>
    <target type="WSDL">
    <schema location="../JavaProcess.wsdl"/>
    <rootElement name="processResponse" namespace="http://xmlns.oracle.com/SampleApplication/JavaEmbeddingActivity/JavaProcess"/>
    </target>
    </mapTargets>
    <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.4.0(build 110106.1932.5682) AT [TUE MAY 07 10:21:02 EDT 2013]. -->
    ?>
    <xsl:stylesheet version="1.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
    xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:med="http://schemas.oracle.com/mediator/xpath"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
    xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:bpmn="http://schemas.oracle.com/bpm/xpath"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
    xmlns:client="client"
    exclude-result-prefixes="xsi xsl bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref bpmn ora socket ldap">
    <xsl:template match="/">
    <xsl:variable name="lastMTime" select="1366664691000"/>
    <xsl:copy-of select="$lastMTime"/>
    <client:processResponse>
    <client:result>
    <xsl:value-of select='xsd:dateTime("1970-01-01T00:00:00") + $lastMTime * xsd:dayTimeDuration("PT0.001S")'/>
    </client:result>
    </client:processResponse>
    </xsl:template>
    </xsl:stylesheet>

  • Convert Varchar2 to Date

    Hello
    I have a column value Scaned_date = 2009-09-25 21:41:59.892
    that i need to convert it into Date please suggest i am geeting errors in this
    Thanks

    Hi,
    A user-defined fucntion like this can help you find the bad data:
    CREATE OR REPLACE FUNCTION     to_dt
    (     in_txt          IN     VARCHAR2                    -- to be converted
    ,     in_fmt_txt     IN     VARCHAR2     DEFAULT     'DD-MON-YYYY'     -- optional format
    ,     in_err_dt     IN     DATE          DEFAULT     NULL
    RETURN DATE
    DETERMINISTIC
    AS
    --     to_dt attempts to convert in_txt (assumed to
    --          be in the format of in_fmt_txt) to a DATE.
    --     If the conversion works, to_dt returns the DATE.
    --     If the conversion fails for any reason, to_dt returns in_err_dt.
    BEGIN
         -- Try to convert in_txt to a DATE.  If it works, fine.
         RETURN     TO_DATE (in_txt, in_fmt_txt);
    EXCEPTION     -- If TO_DATE caused an error, then this is not a valid DATE: return in_err_dt
         WHEN OTHERS
         THEN
              RETURN in_err_dt;
    END     to_dt
    /Here's how you might use it:
    SELECT  primary_key
    ,       scanned_date
    FROM    table_x
    WHERE   scanned_date  IS NOT NULL
    AND     to_dt ( SUBSTR (scanned_date, 1, 19)
                   , 'YYYY-MM-DD HH24:MI:SS'
                   )  IS NULL
    ;iIf you need help, post a little sample data (CREATE TABLE and INSERT statements), the results you want to get from that data, and your complete query that gets an error with the sample data.

  • How to convert from ifs date format to sql based dates

    I want to write a sql query using dates, to search an ifs
    database. Ifs stores dates as numbers created using the
    java.util.Date class. These dates are accurate to seconds.
    PLSQL uses a different format.
    What I need is a PLSQL function that converts PLSQL date format
    to and from the java.util.date format.
    This is an example of what I would like to do.
    String classname = "DOCUMENT";
    String whereclause = "CREATEDATE > theNeededFuction(to_date('01-
    Jan-2001', 'DD-Mon-YYYY'),'j')";
    Selector mySelector = new Selector(login.getSession());
    mySelector.setSearchClassname(classname);
    mySelector.setSearchSelection(whereclause);
    I do realize that I could simply convert the date in java, but
    in the long run, I want to use the oracle tools that support
    busness day calulations.
    -Mitch

    Hi Mitch - our ViewSpecification functionality automatically
    includes an Oracle Date column, which is derived from the java
    date values we store. These views are the supported way of
    performing read-only operations against an iFS instance.
    For yor reference, the Oracle date column is derived using the
    following SQL operation (e.g. for createdate):
    to_date('01-JAN-1970', 'DD-MON-YYYY') + (createdate/86400000)
    regards,
    dave

  • How to convert COLUMN_WID to date format mm/dd/yyy

    Hi Experts,
    How do I convert the COLUMN_WID (ex. 20121120) to date format mm/dd/yyy (ex. 11/20/2012) using the RPD in BMM Layer?
    Hope that I convey my questions clearly.
    Thanks,

    Hi,
    By Analysis:Go to edit analysis -->date(YYYYMMDD) column properties--->select Data format tab -->
    enable Override Default Data Format check box and select date format as "Custom" then
    Custom Date Formate mm/dd/yyy then test it
    Also you can do it via evaluate function (analysis/RPD)
    Thanks
    Deva

  • How to convert string to date format?

    Hi All,
    String is in following format: 2006-12-07 i.e yyyy-mm-dd
    I want it in 07.12.2006 date format.
    which function module should i used to convert it?
    Regards,
    Nilima

    an other way to do this :
    Code
    DATA :
    ld_text(20) TYPE c,
    ld_date TYPE datum.
    ld_text = '2006-12-07'.
    REPLACE ALL OCCURENCES OF '-' IN ld_text WITH ''.
    WRITE ld_text TO ld_date.
    WRITE ld_date.

  • VARCHAR2 to DATE format

    I would like to know what is the best way to convert the following string '2001-10-26T21:32:52+02:00' into a DATE format.
    Thank you.

    You could use to_timestamp_tz:
    http://www.oracle.com/pls/db102/search?remark=quick_search&word=to_timestamp_tz&tab_id=&format=ranked
    SQL> -- generating sample data:
    SQL> with t as (
      2  select '2001-10-26T21:32:52+02:00' str from dual
      3  )
      4  --
      5  -- actual query:
      6  --
      7  select to_timestamp_tz(replace(str, 'T', chr(32)), 'yyyy-mm-dd hh24:mi:ss tzr') dt
      8  from   t;
    DT
    26-OCT-01 09.32.52.000000000 PM +02:00
    1 row selected.

  • Convert the current date format.

    Hi All,
    I am working on database 11g. My nls_data_format is 'DD/MM/YYYY'.
    SQL> SELECT SYSDATE FROM DUAL;
    SYSDATE
    21-04-2009
    I would like to get the data format as 'MM/DD/YYYY'. I am using the to_date function but getting the error.
    SELECT TO_DATE(SYSDATE,'MM-DD-YYYY') FROM DUAL; Also after adding the to_char I am not getting the correct data format. Could any one suggest how I can get the data in correct format.? Also I changed the nls_date_format, still getting the same date formt.
    Thanks
    SUN

    User SUN@ wrote:
    Thank you for your replay.
    I want in date mode, not in charector, because after that I am doing calculation on these dates.
    Thanks
    SUNSo, don't worry about the format!
    If you've got a date that's in DATE format, you don't need to worry about what that format is; it's purely internal to Oracle. Since we're not an Oracle database, any time we refer to a date, we do so as a string (eg. 20th April 2009, 20/04/2009, etc). Any time Oracle outputs a date to us, it must convert the date into a string so us humans can understand it - it does this either through the explicit to_char() function that we specify or implicitly according to the nls_date_format parameter.
    So, you only need to worry about formatting dates:
    a) when you convert a date-as-a-string to Oracle's DATE format (eg. to_date('01/01/2009', 'dd/mm/yyyy') )
    b) when you're displaying a date (eg. to_char(sysdate, 'dd/mm/yyyy') )
    If you're manipulating dates, you can leave them in the same format: eg, sysdate + 2, add_months(your_date_col, 3), trunc(your_date_col), etc

  • Convert varchar2 to date in oracle

    how to covert varchar2 (30) to date fromat
    example '01/01/2007' to 01/01/2007
    thanks in advance
    Reddy

    I want to insert into my new table the data in the
    form DD-MON-RRRRIf your new table has the data type as DATE then you don't insert dates in any particular format, you just insert values that are DATE datatypes.
    The format is only important when you view the data.
    e.g.
    SQL> create table dt (mydate DATE);
    Table created.
    SQL> insert into dt values (to_date('01/01/2008','DD/MM/YYYY'));
    1 row created.
    SQL> insert into dt values (to_date('01-FEB-2008','DD-MON-YYYY'));
    1 row created.
    SQL> insert into dt values (to_date('20080402','YYYYMMDD'));
    1 row created.
    SQL> select * from dt;
    MYDATE
    01/01/2008 00:00:00
    01/02/2008 00:00:00
    02/04/2008 00:00:00
    SQL> alter session set nls_date_format='DD-MON-YYYY';
    Session altered.
    SQL> select * from dt;
    MYDATE
    01-JAN-2008
    01-FEB-2008
    02-APR-2008
    SQL>Edit:
    Sorry, forgot to say...
    This just demonstrates that any format of string can be inserted into a date column if the format string is specified correctly and it also demonstrates that what is stored is just a date, the format of which is determined by the settings of the tool you are using to retrieve the data (unless you specify e.g. to_char(date_column, 'DD-MON-YYYY') in the SELECT statement to convert it to a string again manually)
    Message was edited by:
    BluShadow

  • Convert Varchar2 datatype Date Value To Date Datatype

    Hello,
    I have a date value like the following as varchar2 datatype.
    31-DEC-10 08.40.53 AMI would like to convert this to_date as date datatype.
    How could I do this?

    Use the right format mask?
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions183.htm#SQLRF06132
    SQL> select to_date('31-DEC-10 08.40.53 AM', 'dd-mon-yy hh.mi.ss am')
      2  from  dual;
    TO_DATE('31-DEC-100
    31-12-2010 08:40:53
    1 row selected.
    SQL> declare
      2    dt date;
      3  begin
      4    dt := to_date('31-DEC-10 08.40.53 AM', 'dd-mon-yy hh.mi.ss am');
      5    dbms_output.put_line(to_char(dt, 'dd-mm-yyyy hh24:mi:ss'));
      6  end;
      7  /
    31-12-2010 08:40:53
    PL/SQL procedure successfully completed.

Maybe you are looking for

  • Not able to get the actual plan from trace file

    Hi all I have a Db package and want to get actual execution plan of all the statements in that pakcage it does provides the plan for System's statements but does not displays the plan for Sql statements DB version 9.2.0 using the following sequence o

  • I have V1 video app on my iPhone and on my iPad but can't get the videos to merge when backed up to the icloud.

    My V1 video app is use on my iPhone and iPad but I can not get them to merge when I back up to the iCloud. I want to be able to take the video of a swing with the iPhone and play it back on the iPad. What am I missing?

  • Header data not coming from vendor master when creating SA using BAPI

    Hello, I am creating SA using BAPI_SA_CREATE. I am passing the vendor code and other header related data in the header table of the BAPI. SA is created successfully with all the data that is passed to the BAPI. Now if the payment term and inco terms

  • Rescue & Recovery vs Win 7 Pro Backup

    Anyone have any strong preferences either way?  Tempted to go R&R but in the past I had bug issues and problems restoring.  Win 7 seems simple and from the brief explination menu  it appears you can recover individual files.  T61p win7 pro 64bit back

  • WebCenter Content | Batch Loader

    Hi All, We have to checkin 1 million (approx) scanned document in WebCenter Content 11g. We are planning to use WebCenter Content Batch Loader feature for this. Is there any limitation with Batch Loader in terms of volume, performance. Also is there