How to convert varchar to date datatype while insert or update in table

Hai All
I need to convert to varchar to date.
I have two Tables T1,T2
T1 Structure
Code varchar
Time varchar
Date varchar
T2 Structure
Empname var
Empcode var
Intime date
Outtime date
Intrin date
Introut date
Att_date
Now i need to move Time form T1 to T2 Intime,outtime,intrin,introut according some condition
So now i need to convert Varchar to Date while insert or update
I have tried something
Insert into T1 (code,intime,att_date)values
(code,To_date(Date||time,'dd-mon-yyyy hh24mi'),att_date);
OR While update
Update T2 set Outtime=To_date(Date||time,'dd-mon-yyyy hh24mi') where...
I got an error Ora-01861
Regards
Srikkanth.M

You didn't show any example of your date or time values, butyou might need to add a space between them, like
To_date(Date || ' ' || time,'dd-mon-yyyy hh24mi')

Similar Messages

  • How to convert string into date datatype

    hi! there
    i've a date in string format like MM/dd/yyyy
    eg:String sDate = "01/30/2002";
    and i want to convert this string format into java date format
    same as 01/30/2002 only
    when i write like this
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy");
              String sDate = "1/11/2002";
              java.util.Date oDate = formatter.parse(sDate);
    i'm getting the output
    Fri Jan 11 00:00:00 GMT+05:30 2002
    i just want the out put like 01/30/2002
    plz,help me

    Hi,
    Just use back the SimpleDateFormat object you defined.
    String myDateInStr = formatter.format(oDate);
    this will format a java.util.Date object to a string representation according to the format you specified in the instantiation of SimpleDateFormat object.

  • How to convert varchar to date?

    Hello everyone, I'm new to OBIEE and I'm running into a roadblock...
    I have a date that is stored in a varchar2 column in the physical table, like so: 20071225
    Silly I know, but that's what I'm dealing with.
    Anyway, I want to create a logical column in the business model (using the Administration tool) and convert it to a date so that I can do date arithmetic with it, but TO_DATE doesn't seem to be supported.
    In Oracle SQL would do this (I'm using XE):
    SELECT SYSDATE - TO_DATE('20050101', 'YYYYMMDD') FROM DUAL
    Is there any way to accomplish this same thing in the OBIEE? I see the CAST function, but there doesn't seem to be any way to cast a string to a date?

    The original post is 4 years old - I am sure the poster must have figured it out by this time... obiee 11g supports a To_Datetime function though! thanks!

  • Convert VARCHAR to date - don't know format in advance

    Hi,
    If I want to convert varchar to date, but I don't kniow the format of the varchar in advance. For example, it may be '20-MAY-99', '2009-01-10 10:01:00', but it is not known in advance. How can I convert it to date?
    Many thanks

    You'll have to define a hierarchy of date formats to try. There are some strings that map to many different valid dates depending on the format. The string '01/02/03' might translate to January 2, 2003, January 2, 1903, February 1, 2003, February 1, 1903, February 3, 2001, February 3, 1901, etc.
    Assuming you define a hierarchy of formats, you can write a function that tries each format in turn, i.e.
    CREATE FUNCTION my_to_date( p_string IN VARCHAR2 )
      RETURN DATE
    IS
      l_date_variable DATE;
    BEGIN
      l_date_variable := to_date( p_string, <<format 1>> );
      return l_date_variable;
    EXCEPTION
      WHEN OTHERS THEN
        BEGIN
          l_date_variable := to_date( p_string, <<format 2>> );
          return l_date_variable;
        EXCEPTION
          WHEN OTHERS THEN
    END;You'll need to define the N date formats to try and the order in which to try them.
    Justin

  • I have an unlocked iphone 4s bought from apple. Will be in London and Paris and would like to know if how I can purchase a data plan while on vacaqtion

    I have an unlocked iphone 4s bought from apple. Will be in London and Paris and would like to know if how I can purchase a data plan while on vacaqtion

    Can I still use the phone in Boston when I move there?
    Only on a supported GSM carrier.
    Will there be networks I cant use?
    Yes. CDMA networks.
    As I understand it the 4S supports GSM and CDMA networks worldwide.
    No, you've misunderstood. The GSM iPhone you can buy in Ireland supports GSM networks only i.e. AT&T

  • 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

  • Convert Varchar to Date

    Hi
    im trying to convert varchar to date.
    So, i used To_date ( cilumn, 'DD-MM-YYYY') , Since i have to order the out put in Decending Order i used the same convertion function with Order by clause.
    The problem is ... the out put is not ordered,
    <sql>
    select date_created
    from
    select distinct
    to_date(created_date,'DD-MM-YYYY') as date_created
    from schedule_backup
    order by date_created desc
    <sql>
    out put is
    =================
    DATE_CREA
    26-NOV-09
    23-NOV-09
    19-NOV-09
    16-NOV-09
    11-NOV-09
    04-NOV-09
    30-OCT-09
    11-SEP-09
    04-MAR-10
    01-MAR-10
    25-FEB-10
    DATE_CREA
    22-FEB-10
    17-FEB-10
    15-FEB-10
    11-FEB-10
    09-FEB-10
    03-FEB-10
    27-JAN-10
    20-JAN-10
    15-JAN-10
    04-JAN-10
    thanks
    raj

    Hi, Raj,
    When you store dates in a VARCHAR2 column, you're asking for touble, so it seems that everything is working according to plan.
    Even aside from that, your query works perfectly for me.
    In the output you posted, the order is correct within each year, and you're only showing 2 digits of the year. Are you sure the centuries are right in the schedule_backup table? Perhaps everything that was supposed to be '2010' got enetereed as '1910' or '0010'.
    Post some sample data (CREATE TABLE and INSERT statements) that gets the wrong results with your query.
    For example:
    CREATE TABLE     schedule_backup
    (     created_date     VARCHAR2 (10)
    INSERT INTO schedule_backup (created_date) VALUES ('11-11-2009');
    INSERT INTO schedule_backup (created_date) VALUES ('04-11-2009');
    INSERT INTO schedule_backup (created_date) VALUES ('30-10-2009');
    INSERT INTO schedule_backup (created_date) VALUES ('11-09-2009');
    INSERT INTO schedule_backup (created_date) VALUES ('04-03-2010');
    COMMIT;

  • How to convert files into DAT?

    Does anyone know how to convert files into DAT? Not The other way around please.

    This might do it:
    http://www.videoconverterformac.com/dat-converter-for-mac.html
    but can't imagine why you would want to!

  • My Data is not inserting in Ap standard table while interfacting

    Hi All
    I am new to Oracle apps and i trying to learn oracle interface in AP Module.
    I have inserted data manually in AP_invoices_interface and ap_invoice_lines_interface tables and then i ran the Payables Open Interface Import concurrent program but when i see the output no data get inserted.
    How to see the error happened and how to see what data missed while inserting manually in the interface tables.
    Can any one tell the steps to find the error in concurrent.
    Thanks & Regards
    Srikkanth.M

    solved

  • Wm_Valid: Fail to convert to internal representation error while inserting

    Hi,
    I'm trying to execute an insert via XmlCommand. The table is created with this statement:
    create table testtable4 (testtable4_pk number, mydate date, myts timestamp with time zone, wm_valid wm_period);
    I have a problem while inserting on a simple table with wm_period field. The c# code is the following:
    OracleConnection oraConnection;
    OracleCommand insertCommand;
    string[] KeyColumnsList = null;
    string[] UpdateColumnsList = null;
    string xml1 = "<?xml version=\"1.0\"?>\n" +
    "<ROWSET>\n" +
    "<MYROW num = \"1\">\n" +
    "<TESTTABLE4_PK>1</TESTTABLE4_PK><MYDATE>2012-01-20T00:00:00.00000</MYDATE><MYTS>01-01-11T00:00:00.000000000 +00:00</MYTS>" +
    "</MYROW>\n" +
    "</ROWSET>\n";
    string xml2 = "<?xml version=\"1.0\"?>\n" +
    "<ROWSET>\n" +
    "<MYROW num = \"2\">\n" +
    "<TESTTABLE4_PK>2</TESTTABLE4_PK><MYDATE>2012-01-20T00:00:00.00000</MYDATE><MYTS>01-01-11T00:00:00.000000000 +00:00</MYTS><WM_VALID><VALIDFROM>01-01-11T00:00:00.000000000 +00:00</VALIDFROM></WM_VALID>" +
    "</MYROW>\n" +
    "</ROWSET>\n";
    KeyColumnsList = new string[1];
    KeyColumnsList[0] = "TESTTABLE4_PK";
    UpdateColumnsList = new string[4];
    UpdateColumnsList[0] = "TESTTABLE4_PK";
    UpdateColumnsList[1] = "MYDATE";
    UpdateColumnsList[2] = "MYTS";
    UpdateColumnsList[3] = "WM_VALID";
    try
    string ConnString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + host + ")(PORT=" + port + ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" + sid + ")));User Id=" + username + ";Password=" + password + ";";
    oraConnection = new OracleConnection(ConnString);
    oraConnection.Open();
    using (OracleCommand cmd = new OracleCommand())
    cmd.Connection = oraConnection;
    cmd.CommandText = "alter session set NLS_DATE_FORMAT = 'YYYY-MM-DD\"T\"HH24:MI:SS.SSSSS'";
    cmd.ExecuteNonQuery();
    cmd.CommandText = "alter session set NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD\"T\"HH24:MI:SS.SSSSS'";
    cmd.ExecuteNonQuery();
    cmd.CommandText = "alter session set NLS_TIMESTAMP_TZ_FORMAT = 'YYYY-MM-DD\"T\"HH24:MI:SSXFF TZH:TZM'";
    cmd.ExecuteNonQuery();
    insertCommand = new OracleCommand();
    insertCommand.Connection = oraConnection;
    insertCommand.XmlCommandType = OracleXmlCommandType.Insert;
    insertCommand.XmlSaveProperties.KeyColumnsList = KeyColumnsList;
    insertCommand.XmlSaveProperties.RowTag = "MYROW";
    insertCommand.XmlSaveProperties.Table = "TESTTABLE4";
    insertCommand.XmlSaveProperties.UpdateColumnsList = UpdateColumnsList;
    insertCommand.XmlSaveProperties.Xslt = null;
    insertCommand.XmlSaveProperties.XsltParams = null;
    //this works
    insertCommand.CommandText = xml1;
    insertCommand.ExecuteNonQuery();
    //this fails
    insertCommand.CommandText = xml2;
    insertCommand.ExecuteNonQuery();
    insertCommand.Dispose();
    oraConnection.Close();
    oraConnection.Dispose();
    catch (Exception err)
    this.WriteLogErr("ERROR: " + err.Message);
    With the first ExecuteNonQuery I attempt an insert of a data value and a timestamp with timezone value. The execution is ok (xml1).
    When the second ExecuteNonQuery is run (with the value of wm_valid), the execution fails with this error:
    ERROR: ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: 'java.sql.SQLException: Fail to convert to internal representation: 01-01-11T00:00:00.000000000 +00:00' encountered during processing ROW element 0. All prior XML row changes were rolled back. in the XML document.
    ORA-06512: at "SYS.DBMS_XMLSAVE", line 111
    ORA-06512: at line 1
    The stored procedure at row 111 calls this Java method:
    oracle.xml.sql.dml.OracleXMLStaticSave.insertXML(int, java.lang.String) return int
    The structure of complex data type wm_period is:
    CREATE OR REPLACE TYPE wm_period AS OBJECT (
    validfrom TIMESTAMP WITH TIME ZONE,
    validtill TIMESTAMP WITH TIME ZONE);
    The problem is: I am able to insert a timestamp with timezone value (myts) but I'm not able to insert a wm_valid that contains two values of the same type...
    This works: <MYTS>2011-01-01T00:00:00.00000</MYTS>
    This fails: <WM_VALID><VALIDFROM>2011-01-01T00:00:00.00000</VALIDFROM></WM_VALID>
    I also tried to change the format of NLS_TIMESTAMP_TZ_FORMAT with a lot of various setup, but nothing changed.
    Thanks in advance for your precious help.
    Best Regards,
    Mario.

    Hi jschell ...thnx for ur reply......
    the getString(2) parameter is just avarchar which
    return the error from the procedure, if its ok,then
    the query is executed properly..its just a check I've
    kept to jump into the next step.If the status is OK,
    then I'm retrieving the values from the cursor. I'm
    getting right value for this parameter.I wasn't questioning the logic. I understand what you are doing.
    However JDBC drivers can have problems when items are retrieved out of order.
    You might also try switching driver types. If the thin works and oci doesn't (or visa-versa) then you know it is a driver problem and you will just have to try a work around.

  • How do I find the date of my last vault update?

    How do I find the date of my last vault update? All but one picture in a folder is missing from my library. I want to go back in Time Machine to the date/time of my last update to restore the lost images.

    Thanks, Frank. I was trying to make it too complicated, wasn't I

  • How can I get right data in a cell of JTable when table  enter editing

    how can I get right data in a cell of JTable when table enter editing

    how can I get right data in a cell of JTable when table enter editing

  • Issue with Date Datatype while importing from SQL Server to OBIEE

    Hi,
    We have a column in SQL Server Database with datatype as Date. When we imported this column into the Physical layer of OBIEE rpd,
    the datatype of this column is getting converted to VarChar automatically. Has anyone faced this issue before?
    Please let me know if you have a solution for this.
    Thanks in advance.

    Hi,
    How are you passing this date parameter ?
    Instead of passing this parameter in date format, you can pass this as string and then in PL/SQL package, you can convert this string to date.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to convert string to date based on regional settings

    How can I convert a simple string ("01/04/2003" or "01-04-2003" or "01 April 2003") to a date formatted according to the regional settings?
    For example, if my regional settings is set to "dd mm yyyy", the result will be 01 as dd, 04 as mm and 2003 as yyyy.
    If the regional settings is set to "mm dd yyyy", the result will be 01 as mm, 04 as dd and 2003 as yyyy
    Hope someone can help.
    Thanks in advance.

    I think you have the wrong idea about how Oracle stores dates. Any date in Oracle is stored in a seven byte representation
    SQL> SELECT DUMP(last_hire_dt) FROM emp_t WHERE rownum = 1;
    DUMP(LAST_HIRE_DT)
    Typ=12 Len=7: 119,191,5,6,1,1,1This storage is independent of the NLS date settings. The TO_CHAR(dt,format) and TO_DATE(str,format) functions serve to translate this internal representation into the external presentation supplied by the format. So, if you need to translate a date that is contained in a string into an Oracle date datatype, you need to tell Oracle how to parse the string.
    If the string format matches your NLS_DATE_FORMAT parameter, Oracle will do this implicitly. Otherwise, you need to tell Oracle explicitly which piece is which. For example, is the string (ignoring the problem of two digit years :-) ):
    '02/01/03'
    Feb. 1, 2003, Jan. 2, 2003, or Mar. 1, 2002? If your date format is dd-MON-yyyy as mine is, then:
    SQL> SELECT TO_DATE('02/01/03') FROM dual;
    SELECT TO_DATE('02/01/03') FROM dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL> SELECT TO_DATE('30-Jan-2003') FROM dual;
    TO_DATE('30
    30-JAN-2003HTH
    John

  • Convert varchar(20) date to date that looks like mm/dd/yyyy

    Good afternoon,
    I am a total novice at SQL and have been tasked to change a varchar(20) date column (shows up as m/dd/yy) to show up as mm/dd/yyyy. I've looked at the previous posts, but being a novice, it's difficult to wade through the non-applicable stuff. The column
    that needs to be changed is field2, but I'm not sure how to construct a statement to reflect my objective.
    Thank you in advance. 

    The sample uses a table variable. You can program it the same way for a table:
    DECLARE @t TABLE (dt VARCHAR(20))
    INSERT INTO @t
    VALUES ('1/2/12')
    ,('3/10/10')
    ,('7/23/9')
    ,('aa')
    ,('12/31/99')
    ,('10/20/00')
    ,('10/20/01')
    SET DATEFORMAT mdy
    SELECT dt
    ,CONVERT(VARCHAR(10), CASE
    WHEN isdate(dt) = 0
    THEN NULL
    ELSE cast(dt AS DATE)
    END, 101) AS newDt
    FROM @t;/******** TRY_CONVERT() method ************/
    SELECT dt, newDt=CONVERT(varchar(10),TRY_CONVERT(date,dt),101) FROM @t;
    GO
    dt newDt
    1/2/12 01/02/2012
    3/10/10 03/10/2010
    7/23/9 07/23/2009
    aa NULL
    12/31/99 12/31/1999
    10/20/00 10/20/2000
    10/20/01 10/20/2001
    dt newDt
    1/2/12 01/02/2012
    3/10/10 03/10/2010
    7/23/9 07/23/2009
    aa NULL
    12/31/99 12/31/1999
    10/20/00 10/20/2000
    10/20/01 10/20/2001
    Starting with SQL Server 2012 you can use TRY_CONVERT().
    You can start studying datetime functions here:
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Kalman Toth Database & OLAP Architect
    T-SQL Scripts at sqlusa.com
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for

  • How to Change Default Title and Icon of Forms 5.0 Runtime

    Whenever i run Forms 5.0 runtime , it always shows 'Developer 2000 Forms Runtime for Windows 95/ NT'. If i set a title to the main window then also the above message preceeds my Title of Window. Is there any way to remove that ???? My Application is

  • Possible bug in flash player 9 with video..somewhat urgent help

    Hi, I was making a site based on heavy use of video. The site was working just fine, the videos played well, actionscript ok, etc. Last night I upgraded my flash player, and suddenly the site looks completely broken. Videos now have large pixels and

  • Java is a Partially Object-Oriented Programming (True/False)

    Hi everybody, Many of them saying that Java is not purely Object-Oriented Programming. I am very much confusing on that, so please help me to confirm that "Java is a Partially Object-Oriented Programming Language".

  • S. O. P

    Hi friends , this is shyam can anybody please tell me  what is SOP. And our role in it ? regards shyam

  • Change Appearance Color in Elements 6

    Hi, New to Elements 6 and what a surprise. My eyes can't get used to working with a black background. I'm told there is a slider somewhere that will change the appearance of Elements 6 from Black to Gray in both the editor and organizer similar to El