Using TRUNC in timestamps
Sir,
As you know we were using TRUNC function in DATE datatype. But I want to use it with TIMESTAMP datatypes. For example:
select trunc(systimestamp,'hh24:mi:ss') from dual;
The main idea to get some part of given timestamp without using type conversions (i.e. TO_CHAR).
Note that this is useful when you want to ADD or Subtract the time side from timestamp with interval values and comparing them to another timestamps fields or values.
Thank you in advance.
Trunc is not working in 9i
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
2 FROM dual
3 /
SELECT current_timestamp - TRUNC (current_timestamp) time
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
SQL>
But in 10g...
Personal Oracle Database 10g Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
2 FROM dual;
TIME
+000000000 14:53:04.941000
SQL>
Why?
Similar Messages
-
Can we use Trunc,Substr in Excel templates
Hi All,
I have a date xml tag with value like "2012/04/01 00:00:00" i need to show this in excel output as "01-APR-2012".
I am using Excel template, need your help to achieve the same.
I tired to use Trunc,Substr,Format date but nothing is working.
Please give me your valuable inputs to solve this issue.
Thanks
RajehsVarma,
Thanks for the reply, i have already checked the link but it doesn't have syntax to use Trunc,substr etc. functions.
Also date in example is - "1996-02-03T00:00:00.000-07:00" , but in my case date format is different "2012/01/01 00:00:00".
Thanks
Rajesh -
I'm trying to timestamp (RFC 3161) a pdf using my own timestamp server hardware but always get an error: "Certificate invalid for use" (Original text - pt_BR:O certificado não é válido para uso). How can I get more info on what I'm missing or whats wrong with the certificate?
Which Acrobat version are you using? Do you use "Document Timestamp" command? If so, do you get this error during the signing process and the signature is not created or signature is created and you get this error when it is validated? If the latter you can open signature properties, click on the "Advanced Properties" and in the next dialog on timestamp's "Show Certificate". If you get this error during the signing process do you get an alert that shows some cryptic info with a number? If you do provide the content of this alert.
Also which Acrobat version (including minor) are you using? -
How to use TRUNC function with dates in Expression Builder in OBIEE.
Hi There,
How to use TRUNC function with dates in Expression Builder in OBIEE.
TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
Thanks in advanceuse this instead:
TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE) -
Dear all;
I am using trunc(add_months(sysdate, 1 * -12)), which get me 05/18/2010 however what I would like to do is bascially if that date doesnt fall on a monday then get the monday associated with it in that period, so in this case the monday associated with it is 05/17/2010. how do I modify that to get what i want.
Edited by: user13328581 on May 18, 2011 8:36 AMSQL> select trunc(add_months(sysdate, 1 * -12),'IW') from dual
2 /
TRUNC(ADD
17-MAY-10
SQL> OR:
SQL> select next_day(trunc(add_months(sysdate, 1 * -12)) - 7,'monday') from dual
2 /
NEXT_DAY(
17-MAY-10
SQL> SY. -
Doubt on using trunc()
Hi,
I need some clarification over using trunc().
I came across something where I need to pick only month and day from the date column where the format is YYYYMMDD. Can anyone please tell me how to use that and whether any better functions to use than the trunc. And I need to compare that against some date.
like- Suppose if the month and day of my date is between april 3rd and october 30 i need to add one hour otherwise the date should be the same..Could anyone pls help me in this regard??!!
Thanks in advance,
GKsql>select dt,
2 dt + case when to_char(dt, 'mm/dd') between '04/03' and '10/30' then (1/24) else 0 end new_dt
3 from t
4 order by dt;
DT NEW_DT
02/14/2006 08:30:00am 02/14/2006 08:30:00am
04/01/2006 04:00:00pm 04/01/2006 04:00:00pm
04/15/2006 10:00:00am 04/15/2006 11:00:00am
07/04/2006 06:00:00pm 07/04/2006 07:00:00pm
11/10/2006 09:00:00pm 11/10/2006 09:00:00pm -
Using TRUNC function on partitioned column
Hi All,
I have a table as follows:
STEP1
CREATE TABLE TEST_PARTITION
EMP_ID VARCHAR2(10 BYTE),
CREATE_DT DATE,
EMP_RGN_NM VARCHAR2(2 BYTE),
DSPTCH_CNT NUMBER
PARTITION BY RANGE (CREATE_DT)
SUBPARTITION BY LIST(EMP_RGN_NM)
SUBPARTITION TEMPLATE(
SUBPARTITION RGN_E VALUES ('E') ,
SUBPARTITION RGN_MW VALUES ('MW') ,
SUBPARTITION RGN_SW VALUES ('SW') ,
SUBPARTITION RGN_W VALUES ('W') ,
SUBPARTITION RGN_SE VALUES ('SE')
PARTITION aug2008 VALUES LESS THAN (TO_DATE('01-Sep-2008', 'DD-MON-YYYY')),
PARTITION sep2008 VALUES LESS THAN (TO_DATE('01-Oct-2008', 'DD-MON-YYYY')),
PARTITION oth VALUES LESS THAN (MAXVALUE)
ENABLE ROW MOVEMENT;
STEP 2
insert into TEST_PARTITION values(1000,TO_DATE('01-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10)
insert into TEST_PARTITION values(1000,TO_DATE('02-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',20);
insert into TEST_PARTITION values(1000,TO_DATE('03-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',0);
insert into TEST_PARTITION values(1000,TO_DATE('01-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1000,TO_DATE('02-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1000,TO_DATE('01-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('01-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',1);
insert into TEST_PARTITION values(1001,TO_DATE('02-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',2);
insert into TEST_PARTITION values(1001,TO_DATE('03-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',0);
insert into TEST_PARTITION values(1001,TO_DATE('01-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('02-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',5);
insert into TEST_PARTITION values(1001,TO_DATE('01-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('02-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
STEP 3
I need to get all the dispatches on 1st of August and hence issue the statement as follows:
select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE'
Using a function over the partitioned column, will it avaoid partition pruning? I mean will it scan all the partitiones instead of going to specific partition?
I need this urgently since we are having a discussion on this in few minutes from now.
Thanks so much
SaffWhat about a function based index ?
SQL> select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE';
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 32 | 4 (0)| | |
| 1 | PARTITION RANGE ALL | | 1 | 32 | 4 (0)| 1 | 3 |
| 2 | PARTITION LIST SINGLE| | 1 | 32 | 4 (0)| KEY | KEY |
| 3 | TABLE ACCESS FULL | TEST_PARTITION | 1 | 32 | 4 (0)| KEY | KEY |
Note
- 'PLAN_TABLE' is old version
SQL> create index idx on test_partition (TRUNC(CREATE_DT));
Index created.
SQL> select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE';
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Pstart| Pstop |
| 0 | SELECT STATEMENT | | 1 | 32 | 2 (0)| | |
| 1 | TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_PARTITION | 1 | 32 | 2 (0)| ROWID | ROWID |
| 2 | INDEX RANGE SCAN | IDX | 1 | | 1 (0)| | |
Note
- 'PLAN_TABLE' is old version
I need this urgently since we are having a discussion on this in few minutes from now.It is not our problem, but yours.
Nicolas. -
Duplicate Entries in Flashback Table when queried using as of timestamp
Hi All,
Oracle Version : Oracle Server - Enterprise Edition 11.1.0.7
OS: HP-UX PA-RISC (64-bit)
We have a table name DIRECTORY_LISTING_GROUP with HEADER_KEY as primary key.
So when i query like this
SELECT * FROM DIRECTORY_LISTING_GROUP AS OF TIMESTAMP TO_TIMESTAMP('05-NOV-12 10:00:00','DD-MON-YY HH24:MI:SS') WHERE HEADER_KEY=#
Ideally i should get only one row but i m getting two rows which are exactly the same.
Please advicePeter vd Zwan wrote:
Hi,
Maybe it is a primary key now but are you sure it was a primary key at 05-NOV-12 10:00:00 ?If it was not primary key at 05-NOV-12 10:00:00, and now it is,
which implies primary key constraint was added using ALTER TABLE command.
But using ALTER TABLE command would invalidate the undo data for that table. And using the flashback query would generate exception something like "table definition has changed". -
Using trunc as difference measure btwn two dates
I have a SQL query that works smoothly. It takes the difference between sets of dates that are >=0 and <=0. here it is:
SELECT createdate, id, objid, start_date, end_date
FROM greggs_date, HNEMap
where active =1
and trunc (createdate-start_date) >=0 and trunc (createdate-end_date) <=0;
Problem is I can't output the differences. In MS SQL Server you can show the number of days difference with the datediff function named in the SELECT part of the SQL statement not so with trunc used to get date differences. How can this query be rework to show the actual days of difference between start and end from create date.Hi,
robleh7 wrote:
I have a SQL query that works smoothly. It takes the difference between sets of dates that are >=0 and <=0. here it is:
SELECT createdate, id, objid, start_date, end_date
FROM greggs_date, HNEMap
where active =1
and trunc (createdate-start_date) >=0 and trunc (createdate-end_date) <=0;
Problem is I can't output the differences. In MS SQL Server you can show the number of days difference with the datediff function named in the SELECT part of the SQL statement not so with trunc used to get date differences. How can this query be rework to show the actual days of difference between start and end from create date.
Sorry, I don't understand the problem.
TRUNC (createdate - startdate) is just a NUMBER. You can display it just like any other NUMBER.
SELECT k.hiredate AS base_date
, d30.hiredate
, TRUNC (k.hiredate - d30.hiredate) AS dif
FROM scott.emp k
CROSS JOIN scott.emp d30
WHERE k.ename = 'KING'
AND d30.deptno = 30
Output:
BASE_DATE HIREDATE DIF
17-Nov-1981 20-Feb-1981 270
17-Nov-1981 22-Feb-1981 268
17-Nov-1981 28-Sep-1981 50
17-Nov-1981 01-May-1981 200
17-Nov-1981 08-Sep-1981 70
17-Nov-1981 03-Dec-1981 -16
Post a complete test script (including CREATE TABLE and INSERT statements, if needed) and the results you want from that script. -
Problems using "as of timestamp"
Hi Oracle Gurus!
I'm having trouble using select * from as of timestamp.
here is a saml example code:
I use a table like this:
create table tbtest
id number);
then I do the following:
insert into tbtest (ID) values (1);
commit;
select id from tbtest as
of timestamp (SYSTIMESTAMP );
-- I reveice nothing!
-- update id new value = 2'
update tbtest set id=2;
commit;
--select the ID value with timestamp "now"
select id from tbtest as
of timestamp (SYSTIMESTAMP );
--'what''s up here?'
Why I don't receive the correct data?
I've tested it under
Oracle9i Release 9.2.0.4.0 and Oracle9i Release 9.2.0.3.0
with the same results.
Can anyone help me???
Thanx.
MartinTom Kyte has an excellent discussion of this http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:5968150395572#5972747362112
In a nutshell, flashback query with a timestamp will really only get you within +/-5 minutes of your desired point in time. You need to use SCN-based flashback if you need more accuracy than that.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC -
Problems using FP Advise Timestamp
I'm having problems using the timestamp from the FP Advise vi - dates/times way out from current date/time. I am using FP1600 and have FW 3.00.
I've seen some comments re time sync of the FP Server but not sure what this relates to.
Any help would be appreciated.
Thanks,
Niel.Niel,
Sorry for the confusion. The Time Service that the FP-1600 uses is the Lookout Time Synchronization Services. The Lookout Time Syncrhonization services debuted with Lookout 4.0 and shortly thereafter in FieldPoint Explorer 2.0. They are also distributed with later versions of those two products and now with LabVIEW-Data Logging and Supervisory Control module. The set-up of the Time Server is as simple as installing any of the above products. The Time Synchronization Server is installed as a Service and should always be available to any computer or device that is trying to synchronize to it.
A Time Server is a computer that is running the Lookout Time Synchronization Service as installed by any of the above mentioned products. The primary m
ethod of configuring a FP-1600 to use the Time Server is the Time Server IP Address assignment box which is located in the window where all of the FP-1600's ethernet parameters is located. It is strongly recommended that the Time Server be assigned a static IP address as the FP-1600 modules do not support DHCP. If you assign a FP-1600 to look at a particular IP address as it's Time Server, and due to DHCP it's changed it's address, then the FP-1600 is unable to synchronize it's clock. An important note is that even when a FP-1600 fails to synchronize it's clock, the delta's on the time-stamps will still be accurate even though the absolute date/time is incorrect.
Regards,
Aaron -
Using Trunc Function in OBIEE RPD to TRIM DATE
Below is my requirment.How can i achieve this in BMM layer.
CASE WHEN TRUNC(REPORTDATE) <= TRUNC(SYSDATE-2) THEN 1 ELSE 0 ENDTry this
case when cast(REPORTDATE as date)<=cast((current_date-2) as date) then 1 else 0 end
let me know updates
Thanks
http://cool-bi.com
Edited by: Srini VEERAVALLI on May 22, 2013 9:29 AM -
I get this error message saying literal does not match format string every time i type in the simple query below
select trunc(t1.transaction_date) from table_done t1
where trunc(t1.transaction_date, 'YYYY-MM-DD') < '2006-01-01'
and trunc(t1.transaction_date, 'YYYY-MM-DD')>= '2006-12-31';
Kindly note, the main reason, I am doing a trunc is because the date in the table contains hours and mins and I only want to get the years, month and day as string charater for a particular range. Thank you.
I am still new to oracle. thank youIs t1.transaction_date already a DATE data type? If so all you need to do is apply the TRUNC() function with only the column as the argument which will remove the hour, minute and second components. It looks like some of your post got cut off so I'll guess at what it should be.
SELECT TRUNC(t1.transaction_date)
FROM table_done t1
WHERE trunc(t1.transaction_date) BETWEEN TO_DATE('2006-01-01','YYYY-MM-DD') AND TO_DATE('2006-12-31','YYYY-MM-DD')Additionally you shouldn't compare dates to strings as you have done. Always convert the strings to DATEs if you want to compare dates.
If t1.transaction_date isn't a DATE (always store DATEs as DATEs not strings!) then you'll need to apply the TO_DATE() function. -
How to make same binaries using mxmlc, without timestamp?
It seems like mxmlc generates different binary even when the source code is not changed.
for, example,
// Test.as
package
public class Test { }
and when i run mxmlc like this :
mxmlc Test.as -output case1.swf
mxmlc Test.as -output case2.swf
and case1.swf and case2.swf is different!
I found that mxmlc sets metadata and some timestamp in .swf file,
I could get the same binary by "unpacking" .swf, removing timestamp, and manually re-pack it.
( http://stackoverflow.com/questions/5632318/mxmlc-generates-different-binary-on-same-source )
But it'll be happier when there is a special switch which generates same binary data ( That means, if mxmlc removes all timestamp and metadata which generated in compile time ) !
Is there any way to do it, or should i build specialized mxmlc compiler?Have you get some thing about it?
i am confused with this ,too
Email:[email protected] -
Thanks..
SQL> define TNAME='PATIENT_AUD'
SQL> define CNAME='AUD_CREATED_TS'
SQL> define MINGAP=10
WITH aquery
SQL> 2 AS (SELECT &cname after_gap
,LAG (&cname, 1, 0) OVER (ORDER BY &cname) before_gap
FROM &tname)
3 4 5 SELECT before_gap, after_gap, (after_gap - before_gap) delta
FROM aquery
6 7 WHERE before_gap != 0 AND after_gap - before_gap > &mingap;
old 2: AS (SELECT &cname after_gap
new 2: AS (SELECT AUD_CREATED_TS after_gap
old 3: ,LAG (&cname, 1, 0) OVER (ORDER BY &cname) before_gap
new 3: ,LAG (AUD_CREATED_TS, 1, 0) OVER (ORDER BY AUD_CREATED_TS) before_gap
old 4: FROM &tname)
new 4: FROM PATIENT_AUD)
old 7: WHERE before_gap != 0 AND after_gap - before_gap > &mingap
new 7: WHERE before_gap != 0 AND after_gap - before_gap > 10
,LAG (AUD_CREATED_TS, 1, 0) OVER (ORDER BY AUD_CREATED_TS) before_gap
ERROR at line 3:
ORA-00932: inconsistent datatypes: expected TIMESTAMP WITH TIME ZONE got NUMBER
SQL>The LAG "(&cname, 1, &cname-(1/24/60))" was exactly what I needed in some transaction analysis code I am working on. Thanks 807511
If it helps anyone this is what I ended up with :-
Select a few fields from the debug table
, get the end_time from the previous record
, subtract the current record start time from the end time of the prior record
SELECT transaction_type
, trans_time
, validation_time
, transaction_start_time
, transaction_end_time
, LAG(transaction_end_time, 1, transaction_start_time - (1/24/60/1000))
OVER ( ORDER BY transaction_start_time ) AS prior_transaction_end_time
, transaction_start_time -
LAG(transaction_end_time, 1, transaction_start_time - (1/24/60/1000))
OVER ( ORDER BY transaction_start_time ) AS transaction_lag
FROM debug_datasource_tmp_v
WHERE transaction_type = 'PONotification'
ORDER BY 4;
Maybe you are looking for
-
"You shut down your computer because of a problem" message at each starts
hello, yesterday my mac restarts because of a problem, but since every time I turn on my mac or I restart, it tells me the same message ( want to keep open the last open application,or not ?) ( MacBook Pro (Retina, 13 inch, late 2013), 2,4 GHz Intel
-
Hi, I found a LabVIEW code here which can storage data from input signal (e.g.A/I)in SR830 and transfer it by the GPIB. I used function generator to generate a sine wave with frequency:30Hz& Vp-p:100mVolt , conencting to SR830. Clearly ,I got a corre
-
Problem re-allocating server memory in Solaris 10 with 10gR2 ORA-27102
G'day All, We have an AMD-64 equipped server, running Solaris 5.10 for AMD-64 with 16GB of RAM. The machine is a dedicated server for the Oracle instance running on it, which is 10.2.0.1.0 unfortunately the 32bit version. We've been asked to get this
-
I gave my wife my old iPad when I bought an iPad 2. Both devices have the same name. Will this affect backups of our different contents?
-
The Photo Apps with my brand new iPAD2 is not working. 1 . I tried synching pictures using iTunes as explained in the IPAD pdf User Guide and always get the following message: "certain pictures were not copied to the iPAD because it is impossible to