How to truncate a timestamp data type

I can't count the number of requests that I have written over the years where the trunc (date) was a very useful function. However, I can't find a way to accomplish the same thing when dealing with a timestamp data type. According to the 10 g reference SQL, function 'tronque()' is supposed to take care of timestamp types. However, my 10.2.0.4 database always converts the result to type date.

Here's what I'm trying to basically do:

SQL > select count (*)
sys.aud $2
3 where ntimestamp # > sys_extract_utc (trunc (systimestamp))
6 m
where ntimestamp # > sys_extract_utc (trunc (systimestamp))
*
ERROR at line 3:
ORA-30175: invalid type for an argument

I was able to find a way to get a truncated time stamp:

SQL > select cast (trunc (sysdate) timestamp with local time zone)
2 double
3.

CAST (TRUNC(SYSDATE,'DAY') ASTIMESTAMPWITHLOCALTIMEZONE)
---------------------------------------------------------------------------
JULY 27 09 12.00.00.000000 AM

However, this is a powerful approach ugly. Am I missing something? Any help is appreciated!

Stan

Hello

You can do it.

SQL> select
  2  cast(
  3          trunc(sysdate)
  4          as timestamp)
  5  from dual
  6  /

CAST(TRUNC(SYSDATE)ASTIMESTAMP)
-----------------------------------------
27-JUL-09 12.00.00.000000 AM

HTH
SS

Tags: Database

Similar Questions

  • DATE in TIMESTAMP data type conversion

    Hello

    My question is this:

    1. I have a variable of type DATE, which I attribute the value of SYSDATE
     mydatevar DATE:= SYSDATE;
    2. I want to find * «today» *, truncated to DATE
      TRUNC (mydatevar, 'DD')
    TRUNC function returns the DATE data type. So I get to the point for example 2 *'2010-01-13 00:00:00 ' *.

    3. I want to assign the value of the point 2, to a variable of type TIMESTAMP
      mytimestampvar TIMESTAMP := mydatevar;
    implicitly that will convert the variable DATE to TIMESTAMP.

    Problem: when converting (implicit and explicit conversion with a format mask), I lose hours "00" and "00" minutes and receive something like this: "10 January 13 * 12 *. 00.00.000000000 AM.

    Question: How can I convert a DATE to TIMESTAMP keeping the hours and minutes zeros?

    Why I need this conversion: I have a table with one "column1" TIMESTAMP column (0) and I take only the rows of the table, where 'column1' is in the range of today 12:00 in the morning until now (what time it is).

    Features of the database NLS:
    PARAMETER                           VALUE
    NLS_LANGUAGE                           AMERICAN
    NLS_TERRITORY                   AMERICA
    NLS_CURRENCY     $
    NLS_ISO_CURRENCY                    AMERICA
    NLS_NUMERIC_CHARACTERS     .,
    NLS_CHARACTERSET                    AL32UTF8
    NLS_CALENDAR                            GREGORIAN
    NLS_DATE_FORMAT                    DD-MON-RR
    NLS_DATE_LANGUAGE            AMERICAN
    NLS_SORT     BINARY
    NLS_TIME_FORMAT                     HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT             DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT     DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                             BINARY
    NLS_LENGTH_SEMANTICS               BYTE
    NLS_NCHAR_CONV_EXCP             FALSE
    NLS_NCHAR_CHARACTERSET     AL16UTF16
    NLS_RDBMS_VERSION             10.2.0.4.0
    Session settings are the same.

    DBTIMEZONE is "+ 02:00".

    Verdi wrote:
    Problem: when converting (implicit and explicit conversion with a format mask), I lose hours "00" and "00" minutes and receive something like this: "10 January 13 * 12 *. 00.00.000000000 AM.

    I don't think you lose necessarily any information whatsoever. It is probably more a function of your NLS_TIMESTAMP_FORMAT and NLS_DATE_FORMAT. For example, your NLS_DATE_FORMAT could be default setup for a HH24 (24 hours) which would report to midnight as hours of "00". However, it seems that your NLS_TIMESTAMP_FORMAT is configured with "HH" format with a Meridian indicator that means 12 hours time.

    Your comparisons should use date/timestamp data types anyway, so as long as the input value is correctly converted to date type that shouldn't matter in any case.

    You can see what is actually stored by using the DUMP function:

    SQL> SELECT  DUMP(TO_TIMESTAMP(TO_CHAR(TRUNC(SYSDATE,'DD'),'MM/DD/YYYY HH:MI:SS AM'))) AS TSTAMP
      2  ,       DUMP(TRUNC(SYSDATE,'DD')) AS DT
      3  FROM DUAL
      4  /
    
    TSTAMP                                                                      DT
    --------------------------------------------------------------------------- --------------------------------------------------
    Typ=187 Len=20: 218,7,1,13,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0                  Typ=13 Len=8: 218,7,1,13,0,0,0,0
    

    As you can see the TSTAMP and DT store almost the same values (218,7,1,13), but the TSTAMP has more precision because of fractions of a second.

    HTH!

    Published by: Centinul on January 13, 2010 07:23

  • timestamp data type column

    Hi guys,.

    I want to extract information from a column that contains the timestamp data type.

    something like that

    loged_date between the 09/03/2015 09/03/2015 and 09:00 20:00

    and it does not work.

    Would be very happy to help.

    Hello

    SQL lover wrote:

    Hi guys,.

    I want to extract information from a column that contains the timestamp data type.

    something like that

    loged_date between the 09/03/2015 09/03/2015 and 09:00 20:00

    and it does not work.

    Would be very happy to help.

    Whenever you have a question, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the exact results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    Maybe you want something like:

    loged_date between TO_TIMESTAMP (' March 9, 2015 09:00 ")

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

    )

    and TO_TIMESTAMP (March 9, 2015 20:00 ')

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

    )

  • Timestamp data type is wrong

    The code attached is supposed to focus on a cluster and read the name and the data type of each control of the cluster.  When I put a timestamp control in the cluster it returns its data in the form of wave type, I thought timestamp has its own data type.  I need to get the type of correct data I use this to a database.  I need to be able to tell the difference between a timestamp data type and a waveform, because I do not want to insert a data with waveform data type in the database in the form of stamp and I do not want to insert a time stamp in a place where the waveform data must be.  Any ideas?

    One of the subVIs is password protected, and it is the one that generates the error.

    Using the properties class ID and the name class seems to work OK, producing ID = 60 and the class name = AbsTime for the timestamp and ID = 47 and name = WaveformData for waveform control.

    Lynn

  • How to determine if a data type is used in the comic book?

    Background:
    I am currently planning to install GoldenGate proof of Concept and have questions about the data types supported by the capture mode (pg 1-5, 1-6 in the installation guide). Is not in itself a matter of GoldenGate.

    Our source and target databases are 11.2.0.2
    The GG server will be 11.2.0.3
    I'm new to the environment and want to confirm that we needn't upgrade the source and target the DBs to 11.2.0.3 in order to use the integrated capture mode. This forces me to know if 3 specific types of data are used in the comics. The problem is, Oracle docs aren't clear to me, when they refer to 3 specific data types.

    Here's the question:

    Does anyone know how I can confirm that the following 3 data types are used in the DB by querying the dictionary: "XML stored in binary form',"XML stored as object-relational","abstract data Type "?

    If I select the types of data separate from dba_tab_columns, I see no data enumerated type that indicates, for example, that an XML string is stored as a ' binary '.

    For me, when Oracle made reference to a "stored as binary XML" on page 1-6 on the installation guide, I guess that makes Oracle refers to a BLOB that contains an XML reference, but I can't be sure.

    Someone has an idea that they could share? I just want to confirm that we do not have to upgrade our source and target DBs at 11.2.0.3 by searching in the database is possible to confirm that the above 3 data types are not used by the application.

    Thanks in advance for any help.
    Tony G

    You should find XML columns stored in binary form or CLOB using the DBA_XML_TAB_COLS view referenced in http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb01int.htm#g644983.

    You should find XML tables using storage relational object in the view DBA_OBJECT_TABLES with:

    select
    owner,
    table_name,
    table_type
    from
    dba_object_tables
    where
    table_type='XMLTYPE';
    

    To abstract data type, you can query DBA_TAB_COLUMNS using ADT as literal for DATA_TYPE column:

    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    
    SQL> drop table t purge;
    
    Table dropped.
    
    SQL> drop type adt;
    
    Type dropped.
    
    SQL> --
    SQL> create type adt is object
      2  (
      3   c1 number,
      4   c2 varchar2(30)
      5  ) final
      6  /
    
    Type created.
    
    SQL> show errors
    No errors.
    SQL> create table t
      2  (
      3  c adt
      4  )
      5  /
    
    Table created.
    
    SQL> show errors
    No errors.
    SQL> --
    SQL> column table_name format a10
    SQL> column column_name format a10
    SQL> column data_type format a10
    SQL> select
      2  table_name,
      3  column_name,
      4  data_type
      5  from user_tab_columns
      6  where
      7  table_name='T';
    
    TABLE_NAME COLUMN_NAM DATA_TYPE
    ---------- ---------- ----------
    T          C          ADT
    

    Edited by: P. Forstmann on 8 Apr. 2013 20:28

    Edited by: P. Forstmann on 8 Apr. 2013 21:05

  • date and timestamp data type lengths

    Hello

    Documentation, says the following:

    : Date parameter valid [...]. The size is fixed to 7 bytes. This data type contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. There can be no fractions of a second or a zone.

    TIMESTAMP [(fractional_seconds_precision)]
    Year, [...] setting. The size is 7 or 11 bytes, depending on the precision. This data type contains the datetime fields YEAR, MONTH, DAY, HOUR, MINUTE, and SECOND. It contains fractions of a second, but does not have a time zone.

    However, if I create a table as follows:

    create table t9 (timestamp (3) c1, c2 date);

    and do:

    insert into values t9 (systimestamp, sysdate);
    commit;

    Select length (c1), (c2) length, lengthb (c1), (c2) lengthb of t9.

    I get


    LENGTH (C1) (C2) LENGTH LENGTHB (C1) (C2) LENGTHB
    ---------- ---------- ----------- -----------
    21 8 21 8

    Can someone please explain this to me?

    Thank you

    I think you want to do this to check the time.

    ME_XE?select dump(c1) as c1, dump(c2) as c2 from t9;
    
    C1                             C2
    ------------------------------ ------------------------------
    Typ=180 Len=11: 120,110,4,19,1 Typ=12 Len=7: 120,110,4,19,16,
    6,30,31,13,105,58,64           30,31
    
    1 row selected.
    
    Elapsed: 00:00:00.17
    ME_XE?
    
  • How to create a custom data type

    Hello

    I'm using Labview 2009 and I am trying to create a custom data type and link it to the global variable that will be deployed in cRIO 9073. I couldn't find a method to achieve this. Please suggest a way to do this.

    Thank you

    Guilhem

    Right-click on a control and go to advanced-> customize.  This will open the control editor.  Change the type of a control to a Type def.  Customize if necessary and save the control.

  • How do I edit/change data type on the report which has been selected by mistake


    Hello

    I've created a report in the APEX and a column is in error because the data type of a supposed to be a varchar2 column, but somehow the report was created with a data type Date. I want to change the data type without re-creating the whole report. Can anyone help? I tried to edit the report but could not be able to understand.

    Help...

    I found a solution for this, I thank you.

  • How to use the LOB data type?

    I can't create a table with the LOB data type.

    Do I need an additional parameter in sys.odbc.ini?

    My dsn information is

    [tpch]

    Driver=/home/TimesTen/TimesTen/tt1121/lib/libtten.so

    Data store = / home/timesten/TimesTen/tt1121/tpch/tpch

    LogDir = / home/timesten/TimesTen/tt1121/tpch/logs

    PermSize = 4096

    TempSize = 2048

    PLSQL = 1

    LOB = 1

    DatabaseCharacterSet = US7ASCII

    -bash-4, $ 1 ttdaemonadmin-version

    TimesTen Release 11.2.1.2.0

    There is no LOB = 1 attribute; Please, delete it from your definition ODBC to avoid potential errors.

    LOB support has been added in the major version 11.2.2 TimesTen. So you use 11.2.1 LOB is not available. If you want to use LOB data, then you must upgrade to 11.2.2.

    Chris

  • How to query on the data type date.

    Hello

    I have a RCVDDT column that is the DATE data type. With the help of this I need to query the records where RCVDDT < = (SYSDATETIME - 2 hours), need all the records that are 2 hours or more.


    I am using this query:

    Select * from tablename where RCVDDT < = to_date ((sysdate-INTERVALLE heure '2'), 'yyyy-mm-dd HH24:MI:SS') order by RCVDDT desc



    Thanks in advance,
    Sree-

    A very common mistake is to apply some TO_DATE() against sysdate. Sysdate is a date already and who apply TO_DATE() can really ruin your results. In addition your syntax for TO_DATE(), even if necessary, is not correct because it relies on the default date format, which will also allow you to sorrow.

    Select * from tablename where RCVDDT<= sysdate="">

  • How to make your custom data type used in your QListDataModel to QML?

    I have QListDataModel filled with objects of a custom class carying data and defined with Q_DECLARE_METATYPE. So far, it works however I can't access the data in qml:

    e.g. text: ListItemData.Name
    

    I read that this can be solved by letting QML know your custom class/type, but how to do this?

    See

    https://developer.BlackBerry.com/native/documentation/Cascades/dev/integrating_cpp_qml/

    example:

    qmlRegisterType("com.isec7.materials", 1, 0, "Account");
    
  • How to compare a long data type with a varchar2 data type?

    I need to select these views in my database that contains some passages.
    To do this, I wrote this query

    Select * from user_views
    where lower (text) like '% "| Cast ('text to compare' as long). '%'

    but this gives exception: ora-00932

    Can you please help how to do that?

    May be give this a try.
    
    select object_name
         , view_text
      from (
              select object_name
                   , dbms_metadata.get_ddl('VIEW', object_name, user) view_text
                from user_objects
               where object_type = 'VIEW'
           )
     where lower(view_text) like '%text to compare%';
    
  • How to display "ename" (varchar2 data type) in Initcap, lower- or uppercase...

    Hello

    I am new to ORACLE DBA and just started my training...

    I know how to put in the form of "Columns" using sqlplus, but my question is how can I display "ename" (from EMP table) at the TOP, bottom or Initcap case using "SELECT *"...?

    I know that i can make it in writing for example select statement

    Select

    EmpNo,

    Lower (ename),

    etc.

    etc.

    Of

    EMP;

    and the above statement show me the ename result is converted to lowercase.

    But suppose that if table has too many columns and I want to just change columen name in initcap so how can I do. I don't mean every column in my select as above.

    is it possible that I can use the format column command with "Select *" statement.

    for example

    Col ename as initcap

    Select * from emp;

    ...????????

    Something like that? It will show all the coulmns of emp and INITCAP column (ename)

    SELECT e.*, INITCAP (ename) initcap_ename e emp;

  • For the complex data type, how to generate the Dll with compatible interface to C/C++

    Hello

    I used the Labview FPGA module to develop test equipment. Now, I need to write a driver that is to be a Dll with compatible interface to C/C++ for this equipment. So that my client who is familiar with C/C++ can call the driver without any study on labview. But I had a few problem on how to convert labview for C/C++ data complex data type. To clearly explain to my question, I have attached a simple example. (see attachment) I try to generate a Dll for the attached example VI and get the the function prototype at the head of the files as below:

    ' void OpenFpgaReference (LStrHandle * RIODevice, TD1 * errorIn, LVRefNum * FPGAVIReferenceOut, TD1 * errorOut).

    As you have known, the type of data "LStrHandle * RIODevice" and "LVRefNum * FPGAVIReferenceOut" Labview data format are. C/C++ do not have this kind of data type and can not reconige it. As a result, I can't call the Dll of C/C++ programming language. How to convert these two data type of labview for the C/C++ compatible data format, and then build the Dll? Anyone know about this?

    The answer is really apprecaited! Thank you in advanced.

    Ivan.Chen wrote:

    As I found in the following article:

    http://digital.NI.com/public.nsf/WebSearch/FB001AA027C8998386256AAD006C142D?OpenDocument

    LVRefNum is the name of resource of LabVIEW VISA or refnum, and "it is impossible to convert LabVIEW VISA name of resource or refnum VISession valid ID."
    This means that external code modules can not access & control the session VISA which is open by labview. But for my purposes, I will not attempt to access this VISA extenal code(C/C++) session. I just hope that save this session VISA in the external code once I opened it in Labview dll; and pass it to the labview dll when needed. While I have not need to login again when I need to control the device. Is it possible to do?

    A LVRefNum is really just a single int32 value. Its meaning is useless for other environments than those who created it so that you Michael not any what in C/C++ caller but pass it back to other functions in your DLL, but this often isn't a problem at all.

    You can take the following statement of the LabVIEW extcode.h headers and add them to your delabviewed header files to make it work in such a way.

    #define Private (T) typedef struct T # _t {void * p ;} * T}

    Private (LVRefNum);

    The LStrHandle you must set a standard C string instead in your export DLL and document what is the size of the string buffer should have if it is an output parameter.

    TD1 error clusters should also be divided into their parameters (C compatible) separate for all items or just to the left of suite entirely.

    Rolf Kalbermatter

  • How can I find what is the data type of a column of a Table in oracle or SQL?

    (a) what happens if I want to know the type of data in a specific column in the Table.

    (b) how to find the column data types?

    Can someone help me please. I am new to oracle and try to learn a few tricks

    Hello

    How to do

    SQL > desc

    SQL> desc emp
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     EMPNO                                     NOT NULL NUMBER(4)
     ENAME                                              VARCHAR2(10)
     JOB                                                VARCHAR2(9)
     MGR                                                NUMBER(4)
     HIREDATE                                           DATE
     SAL                                                NUMBER(7,2)
     COMM                                               NUMBER(7,2)
     DEPTNO                                             NUMBER(2)
    

Maybe you are looking for

  • Questions current Mail App

    I'm having a problem with my Apple Mail program that I wrote about here before, but also talked to press two times now, without resolution. The problem is that the Apple frequently (but not always) displays new messages as 'old', as if there is a pro

  • Lock problem, P10-792 and intel 2200BG wireless

    My 792 P10 is not equipped with Wireless Lan Mini-PCI card and it doen't have the on / off wireless switch, but it is possible to add a mini-pci wireless card. I installed the Intel 2200BG mini-pci wireless card. The drivers are installed in windows

  • 11 update utility and drivers for Windows 7

    If you are interested in trying out Windows 7 on your laptop, you should get the new drivers who were just (although the publication dates are listed as 02/09/09 and 03/09/09. ALL Windows 7 drivers and utilities have been replaced with the exception

  • iPhone 5 s. problem SMS. Tap the screen blocked text

    Above the keyboard, there is a gray "audio box"? This means that I don't see what I am typing until it is sent.Is anyone know what it is and how you turn?

  • Cannot scan with Photosmart C5580

    Photosmart C5580, Windows XP Professional SP3 USB connection, Error messages: Everything by asking an analysis: "Can't find scan.msi" translates into a failed attempt to sweep. In addition, "error 1706: no valid source could be found for the analysis