11.2.0.1.0 SQL date + timestamp select interesting result

Please take a look at the following select and its result.
SQL> SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
CURRENT_DATE
CURRENT_TIMESTAMP
17-JUN-10 12.44.09.664153 PM +00:00
2010.06.17. 12:44:09
17-JUN-10 12.44.09.000000 PM +00:00
Interesting result, but why? The third column will always be truncated to second.
Is it the expected behaviour?

bernyo wrote:
Please take a look at the following select and its result.
SQL> SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
CURRENT_DATE
CURRENT_TIMESTAMP
17-JUN-10 12.44.09.664153 PM +00:00
2010.06.17. 12:44:09
17-JUN-10 12.44.09.000000 PM +00:00
Interesting result, but why? The third column will always be truncated to second.
Is it the expected behaviour?No, it's possibly a bug if it's reproducable.
Works ok on 10g...
SQL> SELECT CURRENT_TIMESTAMP, CURRENT_DATE, CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP                                                           CURRENT_DATE        CURRENT_TIMESTAMP
17-JUN-10 13.51.40.148000 +01:00                                            17/06/2010 13:51:40 17-JUN-10 13.51.40.148000 +01:00
SQL>

Similar Messages

  • SQL-Date before 1970?

    Hi,
    How can i store Date-Objects past 1970?
    The Date or Timestamp-constructor don't support this.
    Is there any solution instead of storing the date as a string?
    Regards

    I think you can do this passing negative values to the constructor of Date, Timestamp classes that accept a long argument.
    You can use SimpleDateFormat to parse string dates with predefined formats to get date (java.util.Date) objects. And then you can use those date objects to obtain java.sql.Date / timestamp objects.

  • Fail to convert to internal representation: oracle.sql.DATE

    I'm using the oracle 8.1.7 jdbc driver against oracle 8.1.7 running on NT, and I get the exception message below when I attempt to insert an jpub object structure into a prepared statement.
    All date objects have been constructed from a timestamp object, using the oracle.sql.DATE Timestamp constructor. So I'm surprised to get this error given the timestamp object was successfully constructed.
    I've tried session date formats of 'yyyy-mm-dd hh24:mi:ss' and 'mm/dd/yyyy hh24:mi:ss', with no success.
    I can call stringValue on oracle.sql.DATE and it returns a valid date.
    Can someone confirm that they have been able to use the oracle.sql.DATE class to insert a date correctly into the database? Its seems a silly question to ask but you have to start somewhere!
    Exception : Fail to convert to internal representation: oracle.sql.DATE@3c144e8a
    Stack trace : java.sql.SQLException: Fail to convert to internal representation: oracle.sql.DATE@3c144e8a
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:210)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:829)
    at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:261)
    at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:385)
    at oracle.sql.StructDescriptor.toArray(StructDescriptor.java:560)
    at oracle.sql.STRUCT.<init>(STRUCT.java:95)
    at oracle.jpub.runtime.MutableStruct.toDatum(MutableStruct.java:65)
    null

    The JPub/JDBC runtime is converting your Java object into Oracle-specific representation (all data is put in oracle.sql.XXXX format). The top level object is an oracle.sql.STRUCT, the attributes of which are represented as an array of oracle.sql.Datum objects - in your case an oracle.sql.NUMBER and an oracle.sql.DATE. However, the error does occur in the StructDescriptor which describes the SQL type and the shape of the object. Is the error dependent on the data values? Might null values not be dealt with, correctly?
    One thing to try to do is create such an oracle.sql.STRUCT object from scratch with the same attribute values and insert/manipulate that using SQL.
    I have not dealt with TAR's. If you send me a self-contained test case, I'll check it against the current development version of JDBC. (At least you'll know if the next JDBC release fixes this issue :-) I might also file a bug.

  • Conversions between java.util.Date, java.util.Timestamp and java.sql dates

    I am coding a hoilday booking system using JSP to interact with a SQL Server database. On my JSP form which retrieves the information I have a little javascript pop-up date selector which appears to be returning a Timestamp value although the string value is visable in the entry field. Can I pass this to a javabean as a Timestamp, so far I have only passed strings? Also I then have to enter it in the database and so will need to convert it to an sql date type but I dont know which one is best. Previous to using the Timestamp returning calendar I was just entering text and parsing it to a util.Date in the bean and then converting that to an sql.Date for entry in the database. That worked fine but I want to use the pop-up any ideas? Also my bean won't compile if I declare java.util.Timestamp t;(cannot resolve symbol Timestamp !) even though I have imported util.

    First of all, java.util.Timestamp does not exist. You probably need java.sql.Timestamp.
    java.sql.Date and java.sql.Timestamp inherit from java.util.Date. So converting from java.sql.Date or java.sql.Timestamp to java.util.Date is easy, you don't have to do anything.
    To convert a java.util.Date to a java.sql.Timestamp, do something like this:
    import java.sql.Timestamp;
    import java.util.Date;
    Date date = new Date();
    Timestamp ts = new Timestamp(date.getTime());Jesper

  • Java.sql.Date vs java.util.Date vs. java.util.Calendar

    All I want to do is create a java.sql.Date subclass which has the Date(String) constructor, some checks for values and a few other additional methods and that avoids deprecation warnings/errors.
    I am trying to write a wrapper for the java.sql.Date class that would allow a user to create a Date object using the methods:
    Date date1 = new Date(2003, 10, 7);ORDate date2 = new Date("2003-10-07");I am creating classes that mimic MySQL (and eventually other databases) column types in order to allow for data checking since MySQL does not force checks or throw errors as, say, Oracle can be set up to do. All the types EXCEPT the Date, Datetime, Timestamp and Time types for MySQL map nicely to and from java.sql.* objects through wrappers of one sort or another.
    Unfortunately, java.sql.Date, java.sql.Timestamp, java.sql.Time are not so friendly and very confusing.
    One of my problems is that new java.sql.Date(int,int,int); and new java.util.Date(int,int,int); are both deprecated, so if I use them, I get deprecation warnings (errors) on compile.
    Example:
    public class Date extends java.sql.Date implements RangedColumn {
      public static final String RANGE = "FROM '1000-01-01' to '8099-12-31'";
      public static final String TYPE = "DATE";
       * Minimum date allowed by <strong>MySQL</strong>. NOTE: This is a MySQL
       * limitation. Java allows dates from '0000-01-01' while MySQL only supports
       * dates from '1000-01-01'.
      public static final Date MIN_DATE = new Date(1000 + 1900,1,1);
       * Maximum date allowed by <strong>Java</strong>. NOTE: This is a Java limitation, not a MySQL
       * limitation. MySQL allows dates up to '9999-12-31' while Java only supports
       * dates to '8099-12-31'.
      public static final Date MAX_DATE = new Date(8099 + 1900,12,31);
      protected int _precision = 0;
      private java.sql.Date _date = null;
      public Date(int year, int month, int date) {
        // Deprecated, so I get deprecation warnings from the next line:
        super(year,month,date);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public Date(String s) {
        super(0l);
        // Start Cut-and-paste from java.sql.Date.valueOf(String s)
        int year;
        int month;
        int day;
        int firstDash;
        int secondDash;
        if (s == null) throw new java.lang.IllegalArgumentException();
        firstDash = s.indexOf('-');
        secondDash = s.indexOf('-', firstDash+1);
        if ((firstDash > 0) & (secondDash > 0) & (secondDash < s.length()-1)) {
          year = Integer.parseInt(s.substring(0, firstDash)) - 1900;
          month = Integer.parseInt(s.substring(firstDash+1, secondDash)) - 1;
          day = Integer.parseInt(s.substring(secondDash+1));
        } else {
          throw new java.lang.IllegalArgumentException();
        // End Cut-and-paste from java.sql.Date.valueOf(String s)
        // Next three lines are deprecated, causing warnings.
        this.setYear(year);
        this.setMonth(month);
        this.setDate(day);
        if(! isWithinRange(this))
          throw new ValueOutOfRangeException((RangedColumn)this, "" + this);
      public static boolean isWithinRange(Date date) {
        if(date.before(MIN_DATE))
          return false;
        if(date.after(MAX_DATE))
          return false;
        return true;
      public String getRange() { return RANGE; }
      public int getPrecision() { return _precision; }
      public String getType() { return TYPE; }
    }This works well, but it's deprecated. I don't see how I can use a java.util.Calendar object in stead without either essentially re-writing java.sql.Date almost entirely or losing the ability to be able to use java.sql.PreparedStatement.get[set]Date(int pos, java.sql.Date date);
    So at this point, I am at a loss.
    The deprecation documentation for constructor new Date(int,int,int)says "instead use the constructor Date(long date)", which I can't do unless I do a bunch of expensive String -> [Calendar/Date] -> Milliseconds conversions, and then I can't use "super()", so I'm back to re-writing the class again.
    I can't use setters like java.sql.Date.setYear(int) or java.util.setMonth(int) because they are deprecated too: "replaced by Calendar.set(Calendar.DAY_OF_MONTH, int date)". Well GREAT, I can't go from a Date object to a Calendar object, so how am I supposed to use the "Calendar.set(...)" method!?!? From where I'm sitting, this whole Date deprecation thing seems like a step backward not forward, especially in the java.sql.* realm.
    To prove my point, the non-deprecated method java.sql.Date.valueOf(String) USES the DEPRECATED constructor java.util.Date(int,int,int).
    So, how do I create a java.sql.Date subclass which has the Date(String) constructor that avoids deprecation warnings/errors?
    That's all I really want.
    HELP!

    I appreciate your help, but what I was hoping to accomplish was to have two constructors for my java.sql.Date subclass, one that took (int,int,int) and one that took ("yyyy-MM-dd"). From what I gather from your answers, you don't think it's possible. I would have to have a static instantiator method like:public static java.sql.Date createDate (int year, int month, int date) { ... } OR public static java.sql.Date createDate (String dateString) { ... }Is that correct?
    If it is, I have to go back to the drawing board since it breaks my constructor paradigm for all of my 20 or so other MySQL column objects and, well, that's not acceptable, so I might just keep my deprecations for now.
    -G

  • Problem Writing java.sql.Date to MS Access

    I have a relatively simple application that is for my own use (not distributed on an enterprise-wide basis). As I don't have an IT staff, I'm using a rudimentary Java front-end (v1.3.1) and a Microsoft Access backend.
    I seem to have trouble using INSERT/UPDATE statements with the MS Access Date/Time data type. Below is an example of code being used (id is defined as Text, amount is a Number and timestamp is Date/Time):
    conn = DriverManager.getConnection("jdbc:odbc:markets", "", "");
    conn.setAutoCommit(true);
    String sql = "INSERT INTO temp (id, amount, timestamp) VALUES (?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(sql);
    String id = args[0];
    int len = id.length();
    java.sql.Date dt = new java.sql.Date(new java.util.Date().getTime());
    stmt.setString(1, id);
    stmt.setDouble(2, id.length());
    // I think the problem is here - the JDBC driver doesn't properly map dates to Access???
    stmt.setDate(3, dt);
    stmt.execute();
    stmt.close();
    conn.close();And I get the following error:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access
    Driver] Syntax error in INSERT INTO statement.
            at sun.jdbc.odbc.JdbcOdbc.createSQLException (JdbcOdbc.java:6879)
            at sun.jdbc.odbc.JdbcOdbc.standardError (JdbcOdbc.java:7036)
            at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect (JdbcOdbc.java:3065)
            at sun.jdbc.odbc.JdbcOdbcStatement.execute (JdbcOdbcStatement.java:338)
            at TestWritingDate.main(TestWritingDate.java:31) I'm virtually certain this is a translation problem with
    the java.sql.Date and the JDBC driver. But I can't seem
    to overcome this. Any help is DESPERATELY needed.
    Thanks.
    Matt

    That was it....thanks...didn't even consider that....perhaps I should start using class names that are already in use too :-). Thanks again...

  • DB Adapter Custom Select SQL with Timestamps

    Hi,
    I am facing an issue with the DB Adapter Custom select sql: here is my scenario:
    I am trying to select diff records from the database between user input start time & the sysdate. for this i am trying to use Execute Pure SQL option database adapter.
    I am framing the SQL as below:
    select  * from tablename1,tablename2 where tablename1.id = tablename1.id  and column1 like #userinput1 and tablename1.request_timestamp between to_date(#Userinput_requestTime) and sysdate
    My question is whether the query
    tablename1.request_timestamp between to_date(#Userinput_requestTime) and sysdate
    is correct or not? I even given a try to_date(#Userinput_requestTime,'DD-MON-YY HH24:mi:ss') and sysdate 
    that too not worked ,
    I have created OSB business service using the generated adapter and the input i am giving it as '04-MAR-15 03.36.23.368179000 PM -06:00' and the input is of type xs:string .
    i am getting errors like java.sql.SQLDataException: ORA-01830: date format picture ends before converting entire input string
    Whether my custom sql is correct or not ? please help me in resolving this issue.
    THanks,
    SV

    if
    tablename1.request_timestamp
    is timestamp then you need to compare as
    timestamp beetween timestamp and timestamp
    so convert date to timestamp by CAST as example
    check How to convert DATE to TIMESTAMP

  • SQL Date ?

    folks
    one of my table has a datetime column(sybase db), Now i am trying to populate by using
    Calendar cal = Calendar.getInstance();
    cal.set(2005, 02, 03);
    java.util.Date sDate = cal.getTime();
    how do i convert this java.util.Date to java.sql.Date
    any help with the code is helpful
    thanks
    mathew

    new java.sql.Date(sDate.getTime());Are you sure you want to use a sql.Date and not a sql.Timestamp?

  • SQL Date Issue...

    Hi,
    I am trying to enter values into the db. The data type for the column is "datetime".
    I have the value in the format "2008-10-03 07:50:10.0" and if i do this, i am just left with the date. Time gets truncated.
    java.util.Date uploadDate = photo.getUploadDate();
                   java.sql.Date sqlUploadDate= null;
                   if(uploadDate!=null){
                        sqlUploadDate = new java.sql.Date(uploadDate.getTime());
                   stmt.setDate(6,sqlUploadDate);
    When i try to print uploadDate i get following : 2008-10-03 07:50:10.0
    When i try to print sqlUploadDate i get following : 2008-10-03
    Please suggest how can i also pass time along with the date in "sqlUploadDate".
    Please let me know if i am not clear enough.
    Thanks
    Deepti

    Hey guys.. i got it working..
    I did this if(uploadDate!=null){
                        t = new java.sql.Timestamp(uploadDate.getTime());
                   stmt.setTimestamp(6,t);
    and i am getting what i needed..
    Thanks for you response though...
    Thanks
    Deepti

  • Convert string into java.sql.Date

    Hi,
    I want to convert a date in string form into java.sql.Date to persist into the database column with Date as its datatype in Oracle. I'm trying as follows:
    import java.sql.Date;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class DateTest
    public static void main(String[] args)
    String strDate = "2002-07-16 14:45:01";
         System.out.println("strDate = "+strDate);
    Date aDate = null;
    try
    if(strDate != null && !strDate.trim().equals(""))
         SimpleDateFormat aSDF = new SimpleDateFormat();
         aSDF.applyPattern("yyyy-MM-dd hh:mm:ss");
         java.util.Date utilDate = aSDF.parse(strDate);
    System.out.println("utildate = "+utilDate);
         aDate = new Date(utilDate.getTime());
         aDate.setTime(utilDate.getTime());      
         System.out.println("aDate = "+aDate);
    catch (ParseException e)
    System.out.println("Unable to parse the date - "+strDate);
    catch (Exception ex)
    ex.printStackTrace();
    System.out.println("Caught Exception :"+ex.getMessage());
    It gives the output as :
    strDate = 2002-07-16 14:45:01
    utildate = Tue Jul 16 14:45:01 IST 2002
    aDate = 2002-07-16
    If I put this value into the database table, I can see only the date. Time part is missing. Is this the problem with java.sql.Date or Oracle datatype Date? Please help me asap.
    Thanks in advance.
    Regards,
    Rajapriya.R.

    If I put this value into the database table, I can
    see only the date. Time part is missing. Is this the
    problem with java.sql.Date or Oracle datatype Date?This is not a problem, this is the defined behaviour of the Date type. RTFAPI and have a look at Timestamp, while you're at it.

  • Convert String to java UTC date then to sql date

    Hi,
    I am trying to convert string (MM/dd/yyyy format) to UTC date time and store in the database.
    This is what I did:
    String dateAsString = "10/01/2007";
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    formatter.setLenient(false);
    java.util.date dateValue = formatter.parse(dateAsString, new ParsePosition(0));
    dateValue will be Sun Sep 30 20:00:00 EDT 2007 in UTC.
    Now I need to store this date and time to MS SQL database.
    I used the following code:
    java.sql.Date sqlDateValue = new java.sql.Date(parsedToDate.getTime());
    But this code give only the date, not time 2007-09-30
    Can anybody tell me how I can change this java date to sql date (or datetime?) so that I can get both date and time.
    Thanks,
    semaj

    semaj07 wrote:
    Hi,
    I am trying to convert string (MM/dd/yyyy format) to UTC date time and store in the database.
    This is what I did:
    String dateAsString = "10/01/2007";
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    formatter.setLenient(false);
    java.util.date dateValue = formatter.parse(dateAsString, new ParsePosition(0));
    dateValue will be Sun Sep 30 20:00:00 EDT 2007 in UTC.
    Now I need to store this date and time to MS SQL database.
    I used the following code:
    java.sql.Date sqlDateValue = new java.sql.Date(parsedToDate.getTime());
    But this code give only the date, not time 2007-09-30
    Can anybody tell me how I can change this java date to sql date (or datetime?) so that I can get both date and time.
    Thanks,
    semajTake a look at java.sql.Timestamp:
    http://java.sun.com/javase/6/docs/api/java/sql/Timestamp.html
    Edited by: hungyee98 on Oct 17, 2007 8:57 AM

  • How to combine sql.Date with sql.Time into one?

    I have a database where I keep dates and times separately, and getting date only and time only out of a java.util.Date is no problem thanks to the classes java.sql.Date and java.sql.Time. However, I need to read these values back in, put them back together, and then do date comparisons with java.util.GregorianCalendar. I tried just adding the millisecond long values together but that didn't seem to work, and I've tried setting the year, month, date, hours, minutes and seconds individually into a GregorianCalendar but I haven't figured that out yet. Certain queries work out better keeping the date and time separate in the database and it takes less bytes than a timestamp, so please don't suggest I use a timestamp!
    Thanks for your help!
    Stephen

    You can add the milliseconds (ms), but you need to use just part of it. For this example, let X be one more than the maximum number of units in time and also the minimum number of units in date. If we were using hours instead of ms X would be 24.
    t = total ms from time
    d = total ms from date
    T = new combined time
    T = ((d / X) * X) + (T % X);Add (the date, rounded to the nearest day) and (the portion of time which is less than a day).

  • PreparedStatement.setDate(new java.sql.Date(long))

    Anyone knows how to set insert a Date with Time, Day, Year into a database? I have tried using the preparedStatement.setDate(new java.sql.Date(long)) but it only inserts yyyy mm dd but I want to include time too.
    Anyone knows how here? Please advice.

    how to create an instance of Timestamp?
    new java.sql.Timestamp(????)
    What to put in the parameter?I think that I might have answered that in another one of your posts, if not could you elaborate your problem
    http://forum.java.sun.com/thread.jsp?forum=31&thread=165123

  • How to get a current date timestamp ?

    Hi,
    I need to get the current date timestamp in a format DDMMYY HH:MM:SS.mmmm and store it in an Oracle column which is declared as of type DATE.
    Also i need to store this timestamp in a string format.
    Please give your inputs in this regard, which is appreciated.
    Regards

    Dates dont' have formats. String represenations of dates do.
    If you have a DB column that is of char or varchar type but represents a date/time, you should change your data model so that the column type is date or time or timestamp. If you can't do that, and need to put a date into a particular format, use java.text.SimpleDateFormat.
    To get the current date and time, look at System.currentTimeMillis, java.util.Date, java.sql.Date, java.sql.Timestamp.
    To put one of these into a database, use PreparedStatement. For example, a timestamp would be something like this: PreparedStatement ps = con.prepareStatement("insert into some_table (some_timestamp) values(?)");
    Timestamp ts = new TimeStamp(...);
    ps.setTimestamp(1, ts);
    ps.excuteUpdate();

  • SQL date format

    Hi,
    Assume the records in a legacy oracle data base have an attributes called date which has the format as 'Dy DD-Mon-YYYY HH24:MI:SS' (e.g. 21-Apr-1998 21:18:27).
    In my Java application, assume that I provide a GUI for users to input date as
    "DD-MM-YYYY" (e.g. 21-04-1998).
    How can I make a SQL statement to find all records of the date "21-Apr-1998"?
    Regards,
    Pengyou

    Hi,
    I would like to clarify my question
    The oracle table that I have has a date column of the
    format (oracle default one)
    as 'DD-Mon-YYYY HH24:MI:SS' (e.g. 21-Apr-1998
    21:18:27).Just to be sure.....
    The type of the column is "date". It is NOT "varchar", "varchar2", "char" or something else.
    If so then the the column does not have a format. It is value that does not change regardless of format. What you see is the result of an oracle tool (probably sqlplus) converting it to that format.
    And as discussed you use prepared statement.
    However you MUST use a range check since you have a timestamp (not a date) and you want to compare it to a date.
    So the java would look something like this....
      String sql = "select field1 from mytable where adate >= ? and adate < ?";
      SimpleFormatDate dt = ....
      java.util.Date d = dt.parse("...");
      java.sql.Date t1 = new java.sql.Timestamp(d.getTime());
      java.sql.Date t2 = // Use calendar to add one day
      PreparedStatement ps = ...(sql)
      ps.setDate(t1);
      ps.setDate(t2);
      ResultSet rs = ps.executeQuery();Note that you MUST use exclusion and inclusion at either end (">=" and "<"). If you don't then you run the risk of including something twice or excluding something.
    And the above is explained in numerous other posts.

Maybe you are looking for

  • Browse animation effects causing Bridge to freeze

    Every time I select browse effects from the animation menu, Adobe Bridge launches (as expected). When I navigate to the "Text/Blurs" folder and open it, Bridge freezes. I know I can add an effect to my text without resorting to Bridge, but I'm follow

  • Help with Photoshop Elements 10 after system restore

    Hi I need some help and guidance. I have successfully installed my Photoshop Elements 10 twice now; once on my own; and following a MS Vista System Restore; with the help of Adobe support . I then worked on it for a day and all was well. But unbeknow

  • Photos in iphone 4s photo stream not sync all with macbook air in iCloud

    why the photos in my iphone  photo stream not sync all to macbook via icloud?  Its like when i have 20 photos in iphone photo stream, then only 15 photos sync to macbook. Under one apple ID, do not understand why is that.  Is anybody else have the sa

  • IDOC Posting Program for Vendor Master

    Hi Guys, Please give me the Sample Posting Program Vendor master Idoc. Thanks a lot in advance. Prabhu.r

  • How to do submit with parameter?

    Hi, I would like to pass some data from Program A to Program B. How do i do a submit statement with parameter from Program A to pass data to Program B. How do i grab the data from Program B that was pass by Program A? Regards, Rayden