sqlldr: using RTRIM date format conversion

Hi all

I need assistance with date formats using sqlldr to load.
I did some research on the internet, but not really good to find examples that help in my case clear.

I am trying to load data from another source into our Oracle database, however, the field 'date' includes additional characters that I am dealing with.
For reference, I'm under Oracle 11.2 on Linux 5.7.

First, the entry of the actual date is:
April 18, 2013 8:50:44 AM EDT
I tried to get in a few ways but could not load until I physically removed the "AM EDT' the input string.
My first question is if there is a way to RTRIM and get rid of these extra characters.
Or maybe I just need a way to convert the "AM EDT" our standard date format.

My controlfile has the following:
LASTCHANGEDAT date "Month dd, YYYY HH MI SS",
This will load the data, but only if I'm hard on the 'AM EDT' of the actual data entry which is not feasible.


Also, how I would manage that comes as the date: April 18, 2013 21:50:44 CEST

Also, I tried the following, but it gives me a different error:


LASTCHANGEDAT "to_date(:LASTCHANGEDAT,'DD-MON-YYYY HH24:MI:SS')",

gives me error:

Record 1: Rejected - Error on table NTWKREP.INTERFACE, column LASTCHANGEDAT.
ORA-01858: a non-numeric character was found where a numeric was expected
Published by: 974632 on April 22, 2013 12:41

You only need a control file and it's okay if you are using AM or PM in the control file. Using AM or PM just said to expect one or the other in this position and will take care of both of them. Please see the demo below that shows that either am or pm in the control file works with am and pm in the data.

SCOTT@orcl_11gR2> host type test.ctl
load data
infile *
into table test_tab
fields terminated by '|'
(lastchangedat1 timestamp with time zone "Mon dd, yyyy hh:mi:ss am tzd",
lastchangedat2 timestamp with time zone "Mon dd, yyyy hh:mi:ss pm tzd")
begindata:
April 18, 2013 8:50:44 AM EDT|April 19, 2013 9:51:45 PM EDT
April 20, 2013 10:52:46 PM EDT|April 21, 2013 11:53:47 AM EDT

SCOTT@orcl_11gR2> create table test_tab
  2    (lastchangedat1  date,
  3     lastchangedat2  date)
  4  /

Table created.

SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test.ctl log=test.log

SQL*Loader: Release 11.2.0.1.0 - Production on Tue Apr 23 10:09:59 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 2

SCOTT@orcl_11gR2> select * from test_tab
  2  /

LASTCHANGEDAT1          LASTCHANGEDAT2
----------------------- -----------------------
18-apr-2013 08:50:44 am 19-apr-2013 09:51:45 pm
20-apr-2013 10:52:46 pm 21-apr-2013 11:53:47 am

2 rows selected.

Tags: Database

Similar Questions

  • varchar2 to the date format conversion

    I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY, but I want to change it to DD/MM/YYYY. My query is below:

    Select to_date('fccpdate','MM/DD/YYYY')
    of cc_class_scmast_v

    When I try to_date I get this:

    Error from the 1 in the command line:
    Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
    01858 00000 - "a non-digit character found here where was waiting for a digital".
    * Cause: Input data to convert using a date format model has been
    incorrect answer. The input data did not contain a number where is a number
    required by the format model.
    * Action: Fix the input data or the date format model to ensure that the
    elements correspond to the number and the type. And then try the operation again.



    When I try to_char I get this:

    Error from the 1 in the command line:
    Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01722: invalid number
    01722 00000 - "invalid number."
    * Cause:
    * Action:


    I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.

    Hello

    housetiger77 wrote:
    I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY,

    If the column is a DATE, then it has the same format that all DATEs, which is nothing like 'DD-MON-YYYY '. Formats like which apply only to chains.
    Conversely, if it is in the format "DD-MON-YYY", then it is a string, not a DATE.

    but I want to change to DD/MM/YYYY. My query is below:

    Select to_date('fccpdate','MM/DD/YYYY')
    of cc_class_scmast_v

    To_date (x, "MM/DD/YYYY") tries to convert the string x in a DATE. Let's say it starts by taking the first 2 characters of x, for the month. The first 2 characters of 'fccpdate' are "fc", which is not a valid number (at least not in base 10), not to mention a number from 1 to 12, TO_DATE so will raise an error.

    When I try to_date I get this:

    Error from the 1 in the command line:
    Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
    01858 00000 - "a non-digit character found here where was waiting for a digital".
    * Cause: Input data to convert using a date format model has been
    incorrect answer. The input data did not contain a number where is a number
    required by the format model.
    * Action: Fix the input data or the date format model to ensure that the
    elements correspond to the number and the type. And then try the operation again.

    When I try to_char I get this:

    Error from the 1 in the command line:
    Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01722: invalid number
    01722 00000 - "invalid number."
    * Cause:
    * Action:

    I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.

    It's a good first step. Literals are enclosed in single quotes are not identifiers (including the column names). "fccpdate" is the literal string of 8 characters containing 'f', ' c; Another 'c', 'p' 'd', 'a', 't' and 'e'. " fccpdate (without the single quotes) can be the name of a column.

    If fccpdate is a string, as July 18, 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 is perhaps the TO_DATE expression above

    TO_CHAR ( TO_DATE (fccpdate, 'DD-MON-YYYY')
            , 'MM/DD/YYYY'
            )
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • Date format conversion - am/pm

    I want to insert below in a table, the column is type 'DATE '.

    but in the following case which is at 12:00, it removes the time part and returns ony the part date how he converted with a portion of time. (without using 24-hour format)
    See the queries

    SELECT to_date('01/11/2011 11:59:00 am','dd/MM/yyyy hh:mi:ss am')
    OF the double
    Back: 11/01/2011 11:59

    SELECT to_date('01/11/2011 12:00:00 am','dd/MM/yyyy hh:mi:ss am')
    OF the double
    Back: 11/01/2011

    SELECT to_date('01/11/2011 12:01:00 am','dd/MM/yyyy hh:mi:ss am')
    OF the double
    Back: 11/01/2011 12:01:00 AM

    I can get it at the TO_CHAR conversion but there is a problem when inserting a DATE column type?

    SELECT to_char (to_date('01/11/2011 12:00:00 am','dd/MM/yyyy hh:mi:ss am'),' dd/MM/YYYY HH: mi: ss am')
    OF the double

    user483578 wrote:
    Thanks everyone... It was like that... and worked well

    DECLARE
    x varchar2 (50);

    BEGIN

    SELECT to_char (to_date (11 January 2011 12:00 ',' dd/MM/yyyy hh), ' dd/MM/yyyy HH')
    X
    DOUBLE;

    INSERT INTO my VALUES (to_date (x,' dd/MM/yyyy hh));

    END;

    ?

    It's the same what do I do...

    BEGIN
      INSERT INTO ma VALUES(to_date('01/11/2011 12:00:00','dd/MM/yyyy hh:mi:ss'));
    END;
    

    There is no need to convert a string date and then back to a string and then insert this string by converting it back to a date once again.

  • date format conversion

    Hello

    I have the date format in the table as below and now I need to convert the date format YYYY-MM-DD hh: mm :)

    data type of column is varchar2 (20)

    1993-06-24 - 14.15.06.785408 (note: hours, minutes, seconds, milliseconds are separated by.) (dot)

    1991-11-05 - 11.32.17.045702

    Can someone help me please.

    Thank you!

    Hello

    3058870 wrote:

    Hello

    I have the date format in the table as below and now I need to convert the date format YYYY-MM-DD hh: mm :)

    data type of column is varchar2 (20)

    1993-06-24 - 14.15.06.785408 (note: hours, minutes, seconds, milliseconds are separated by.) (dot)

    1991-11-05 - 11.32.17.045702

    Can someone help me please.

    Thank you!

    Do not store information on dates in a VARCHAR2 column. It's simply to request data not valid, complicated, inefficient code and runtime errors.  The columns DATE, or, if necessary, fractions of a second TIMESTAMP.

    To convert strings from one format to another, you can always use TO_DATE to convert any format they are dates and then use TO_CHAR to generate a new string, in any desired output format.

    In this case, it seems that you just want to lose the split second, change the 3rd indent to a space and change points to colons.  You can do the following:

    SUBSTR (datatype, 1, 10).

    ' '                      ||

    REPLACE (SUBSTR (datatype, 12, 8)

    , '.'

    , ':'

    )

    If you would care to post CREATE TABLE and INSERT statements for some sample data and accurate results, you want from these data, then I could test this.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

    You could do all the work in a single call REGEXP_REPLACE, but it is probably more complicated and less effective.

  • Use the date Format

    Hi all

    I have question,

    "If I get the data of an input parameter 10 December 2013 08:41:53.

    How can I convert the format of date,-> "DD-MM-YYYY".

    Thanks for the help of You ' r

    Hello

    If you have a string str = 10 December 2013 08:41:53 ', you can call TO_DATE to create a DATE from it:

    To_date (str, "MM/DD/YYYY HH24:MI:SS")

    (Assuming that "12" is the month and '10' is the day).

    Once you have a DATE (let's call it dt), you can view it in any format you want using TO_CHAR:

    To_char (dt, "DD-MM-YYYY")

    If you wish, you can nest one of these functions inside each other, like this:

    SELECT TO_CHAR (TO_DATE (' DECEMBER 10, 2013 08:41:53 '))

    , "MM/DD/YYYY HH24:MI:SS.

    )

    'DD-MM-YYYY ".

    ), Exit

    DOUBLE;

    Output:

    OUTPUT

    ----------

    10/12/2013

  • Date format Conversion MM/DD/YYYY month day, year

    Hi all

    Is there a BEEP function that converts the DD/MM/YYYY month day, year?

    for example.

    08/10/2010 convert to 8 October 2010

    Thank you very much!

    Since your date is not in canonical format, you cannot format dates directly.
    You will have to do with workarounds.
    Try to use
    ,

    Here, I assume that your date is delivered in the format MM/DD/YYYY

  • How to use the date with the report parameter format

    Hi all

    How to use the date format with this tag function,

    <? param@begin:P_FROM_DATE? > <? $P_FROM_DATE? >

    This date of form source of report and setting is coming as this 2012/11/01 00:00:00.

    So now I need this in MY-DD-YYYY marker. I tried like this..? param@begin:P_FROM_DATE? > <? $format - date: P_FROM_DATE; ' DD-MON-YYYY '? >

    but its giving error. Can someone pls how to convert to the format of date custom.

    Thanks and greetings
    Srikkanth.M

    Problem solved.

    REF this link

    Date Format of XML

  • Date of issue - conversion to date and the date of conversion in months

    I have some data in a text file for SQLLDR from a SQL SERVER.

    In date columns are YYYY-MM-DD format eg-2011-01-03 00:00:00

    but in oracle, we use DD-MM-RRRR.

    Don't know why the SD and MM are get interchanged. Help, please.

    It's my for sqlldr control file:
    LOAD DATA 
    INFILE 'F:\NV\Permits\SQLLDR\permits.txt'
    REPLACE 
    INTO TABLE lot.p_permit
    FIELDS Terminated by "~" TRAILING NULLCOLS
    (
     CP_PermitID  "TRIM (:CP_PermitID)",
     CP_SubmitDate "to_date(to_date(substr(:CP_SubmitDate, 1,19),'RRRR-MM-DD HH24:MI:SS'),'DD-MM-RRRR')",
     CP_IssueDate "to_date(to_date(substr(:CP_IssueDate, 1,19),'RRRR-MM-DD HH24:MI:SS'),'DD-MM-RRRR')")

    You convert date to date. First TO_DATE

    TO_DATE (substr (: CP_IssueDate, 1.19), "DD-MM-RRRR HH24:MI:SS")

    Converts correctly 19 characters of the CP_IssueDate string to date. Now, look at what is happening with the other. To_date first argument is string. Since to_date (substr (: CP_IssueDate, 1.19), "DD-MM-RRRR HH24:MI:SS") are dates:

    TO_DATE (to_date (substr (: CP_SubmitDate, 1.19), 'DD-MM-RRRR HH24:MI:SS'), "DD-MM-RRRR")

    implicitly converts the to_date (substr (: CP_IssueDate, 1.19), "DD-MM-RRRR HH24:MI:SS") to a string using default date format, then converts it back to the date using the format "DD-MM-RRRR. Of course if the default date format is not "DD-MM-RRRR" you can either get an incorrect date or a mistake. In any case, use:

    LOAD DATA
    INFILE 'F:\NV\Permits\SQLLDR\permits.txt'
    REPLACE
    INTO TABLE lot.p_permit
    FIELDS Terminated by "~" TRAILING NULLCOLS
    (
     CP_PermitID  "TRIM (:CP_PermitID)",
     CP_SubmitDate "to_date(substr(:CP_SubmitDate,1,10),'YYYY-MM-DD')",
     CP_IssueDate "to_date(substr(:CP_IssueDate,1,10),'YYYY-MM-DD')"
    )
    

    SY.

    Published by: Solomon Yakobson August 1, 2011 16:45

  • How do I change the date format in the section of the United States to the United Kingdom

    As in the question.

    Hello

    I had a glance in this and have found that Thunderbird uses the date format of your computer system. If you change it, it should be reflected in Thunderbird.

    I hope this helps, but if not, please come back here and we can look at another solution for you.

  • convert date format period

    Hi all

    Here are my existing query which I run another tool to extract data from oracle-

    Select * from transactionTbl

    WHERE

    DATE > = TO_DATE (' $(vAppStartDate)', "DD/MM/YYYY")

    AND DATE < = TO_DATE (' $(vAppEndDate)', "DD/MM/YYYY")

    variables-

    -vAppStartDate = 06/01/2014

    -vAppEndDate = 30/06/2015

    Rather than use the Date column in the WHERE condition, I want to use PeriodID of column existing in the same table, to make the query faster.

    The period column is in below format.

    PeriodID format-> 201294 //means 2012Q 4. So 9 means Q

    Since I'm on variables, the values are always to the date format, so my requirement is first change variable date from periods of format.

    I wrote the pseudo-code, because I of course know how to convert date format periodID. Q also means in the periodID 9.

    Select * from transactionTbl

    WHERE

    PeriodID > = period_function (TO_DATE (July 1, 14 ',' DD/MM/YYYY '), 'YYYYxx')

    AND PeriodID > = period_function (TO_DATE (July 1, 15 ',' DD/MM/YYYY '), 'YYYYxx')

    Please help me with the query.

    Thank you!

    Calling a user-defined function is likely to slow down your query.

    What's the problem with just using regular date formatting strings for example

    SQL > select to_char (to_date('15/09/2014','DD/MM/YYYY'), 'YYYY "9" Q') of double;
    TO_CHA
    ------
    201493

    1 selected line.

  • Date formatting to_char - truncate issue zeros

    Hello

    I have used this date formatting in an APEX application, but I noticed that the problem also occurs when you run a simple script in the database.

    The query is:

    Select

    TO_CHAR (sysdate, 'fmDay, GFMD fmMonth AAAA HH:MIPM'),

    TO_CHAR (sysdate, ' HH:MIPM of MON-DD-YYYY "")

    of the double

    The problem occurs when the minutes have a zero in it, in the example that I have attached, it was 14:05, and it shows as 14:05

    https://plus.Google.com/u/0/photos/104459804528712563956/albums/5958573459391223345/5958573462256341170?PID=595857346225...

    Is there a reason that this is happening? I am unable to use the combination I've used? I really want the full date with month and day names.

    Version of DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

    Amanda.

    Just add fm with the time format:

    SQL > select

    2 to_char (sysdate, 'fmDay, GFMD fmMonth AAAA fmHH:MIPM')

    3 double;

    TO_CHAR (SYSDATE,'FMDAY, FMDDFMMONTHYY)

    ------------------------------------

    Wednesday, December 18, 2013 09:03

    Concerning

    Girish Sharma

  • Java date format

    Hello world

    I have a piece of code like below for date format conversion.
    DateFormat formatter1 ; 
    DateFormat formatter2 ; 
    Date date = new Date(); 
    
    formatter1 = new SimpleDateFormat("yyyy-mm-dd");
    date = formatter1.parse("1952-12-10"); 
    System.out.println("before format, date is " + date);
    
    formatter2 = new SimpleDateFormat("dd-MMM-yy");
    formatter2.format(date);
    System.out.println("after format, date is " +formatter2.format(date));
    I would change from 1952-12-10 became 10 December 52, however, I get the below output:

    before the format, the date is Thu Jan 10 00:12:00 MYT 1952
    After format, date is January 10, 52

    AAAA-MM-JJ is probably meant for formatter1.

  • Date formats and rawValue

    Hello

    Is there a way to change the default rawValue of a date field. It seems that my default locale (Australia) D/MM/YY. I would like to make it appear as DD MMM YYYY.

    I'm also trying to add it to a text field, for inclusion in mid-sentence, once a date has been selected, using the datefield.rawValue. The text field seems to show only in the form YYYY-MM-DD.

    Thanks in advance for any help or discussion of this problem.

    See you soon,.

    Greig

    Hello

    You can use a model to display the date format in the way that you want.

    date{DD-MMMM-YYYY}
    

    To use the date formatting in another area see the formattedValue instead of the rawValue.

    var d = datefield.formattedValue;
    
  • Data format of hyperlink

    I want to be in a position of the column in the query to access a certain URL, for example, suppose I have a column in the database containing data from URL in there, and I want the user to be able to access the URL for the report. I know I can use the data format 'Hyperlink', but I don't want the URL is displayed in this column, I want, for example, the value of 'Visit website' to appear and when the user clicks on this link, the underlying URL would be open in a separate window.

    somehow, I'm not able to view code... just text

    Replace "visit our Web site.

    '|| Cast (DealHeader.AnotherColumntobeshown as varchar (50)). »

    How your url is stored in the database column? Mine is stored as
    http://server/...

  • Is there a way to use data formats i.e. Go Mo Ko in numbers?

    Is there a way to use data formats i.e. Go Mo Ko in numbers?

    I am trying to add the size of the library files to estimate the needs of the HD. If I had the files on my system I could just put them in a folder and the operating system would be to calculate them for me, but I don't have them yet. I have a list of files and their size in GB.

    Someone has it worked?

    I suggest the following:

    Create a second table called "convert".

    In this table, enter the first column as show (pasted here so you can copy)

    Value

    Divide by

    suffix

    0

    1

    b

    400

    1024

    Ko

    1000000

    1048576

    MB

    1000000000

    1073741824

    GB

    1000000000000

    1099511627776

    TB

    Appropriate now in the table 1 use the conversion table to change the size of the files in the format:

    "C2 = ROUND (B2÷VLOOKUP (B2, Convert::A:C, 2, 1), 2) &" "& VLOOKUP(B2,Convert::A:C,3,1)".

    It's shorthand dethrone select cell C2, then type (or copy and paste it here) the formula:

    "= ROUND (B2÷VLOOKUP (B2, Convert::A:C, 2, 1), 2) &" "& VLOOKUP(B2,Convert::A:C,3,1)".

    Select cell C2, copy

    Select cells C2 at the end of the C column, paste

Maybe you are looking for

  • Add a maximum of added following reverse order of selection 12.4

    In all cases if not see this? Select a few songs to add to the next game, they get added in the reverse order.  It worked the way we should expect 12.3. Play the next still work correctly; Add several song and added to until the next in their order i

  • How can I remove referenced originals within photos

    As Aperture is is no longer in charge I thought it was time to move on to the Photos. I just migrate my library of Aperture for photo and have now discovered what is for me a hugh problem. I do not have all of my original photo inside the application

  • Equium L40-10 X: Atheros AR5007EG adapter firmware update

    Does anyone know if it is possible to update the firmware on the Atheros AR5007EG Wireless Network adapt to be able to use WPA WEP encryption is weak and easily broken?

  • NVIDIA nForce Networking Controller problem.

    In my "Device Manager" and on the tab "Network adapters", my NVIDIA nForce Networking Controller has a /! ------beside him. Here is what it says under "device status". "This device cannot start. (Code 10) I tried the 'check for solutions', but came u

  • A VPN client / ASA cannot access the Internet.

    VPN clients can get to the servers internal/DMZ but not Internet. This is the partial config of the SAA. TIA Pool VPN 10.17.70.0 DMZ 192.168.100.0 172.0.0.0 internal ------------------------------------- nonatdmz list of allowed ip extended access an