Compare date datatype against timestamp column
Hi,
I have a table "test" with a TIMESTAMP column as "insert_timestamp".
I have an application with a query like
select * from test where insert_timestamp between i_start_date and i_end_date;i_start_date and i_end_date are DATE data type variables.
When I ran this query, it returned results:
select * from test where insert_timestamp between sysdate - 1 and sysdate;My question is if it is ok to compare against a TIMESTAMP column in table using DATE data type variables?.
I am just making sure the app doesn't break during execution due to this.
Thanks in advance
yes you can use...
But with timestamp you get precision till fraction of seconds but not in case of data type...
So if you have data which differ in fraction of seconds like
1.0001 sec,1.0003 sec,1.0004 sec,1.0005 sec,1.0006 sec...
then if i have to get data between 1.0003 and 1.0005 seconds you cannot use a date variable here...
Ravi Kumar
Similar Messages
-
Compare dates in a different columns
Hi All,
How to get the largest date out from different columns.
here is my query....
select * from
(select date1 from table1) a,
(select date2 from table2) b,
(select date3 from table3) c
I want to get the largest date among date1, date2 and date3
thank you in advanceHi,
I think the following query helps to you.....
SELECT GREATEST(a,b,c) FROM(
SELECT
(SELECT MAX(SYSDATE+1) FROM EMP WHERE EMPNO=D.EMPNO) as a,
(SELECT MAX(SYSDATE+2) FROM EMP WHERE EMPNO=D.EMPNO) as b ,
(SELECT MAX(SYSDATE+3) FROM EMP WHERE EMPNO=D.EMPNO )AS C FROM EMP D WHERE EMPNO=7698)Regards
Reddy. -
Logic to compare date with standard timestamp
Hi Experts,
I want to retrieve the data which is "n" moths old.
To compare that I want use only SYSDATE without timestamp.
I want to use standard timestamp '23:59:59' along with SYSDATE.
The condition should be as below.
UPDATE_DATE <= ADD_MONTHS(15/01/2013 23:59:59,-3)
UPDATE_DATE <= ADD_MOTHS(30/01/2013 23:59:59,-4)
UPDATE_DATE<=ADD_MONTHS(sysdate||' '||'23:59:59',-3);Please help me how to implement it.
Thanks in advance.973205 wrote:
Thanks for your reply.
Your query is not meeting my requirement.
It just adding one day after it's adding months.
TRUNC(sysdate) means it will truncate timestamp.
I want to use standard timestamp along with sysdate.
TRUNC(sysdate)||' '||'23:59:59' after that I want to add months.
What you are trying to do is to concatenate a character string to a DATE value - which will not work and is not logical also..
This can be achieved as below - minus 1 second from trunc(sysdate+1)
select trunc(sysdate+1)-(1/(24*60*60)) dt
from dual;
DT
03-Feb-2013 23:59:59 Your requirement is to filter as UPDATE_DATE<=ADD_MONTHS(sysdate||' '||'23:59:59',-3);
This can be done as
UPDATE_DATE<=ADD_MONTHS(trunc(sysdate+1)-(1/(24*60*60)),-3);The same thing can be achieved by replacing "<=" with "<" as
UPDATE_DATE<ADD_MONTHS(trunc(sysdate+1),-3);Edited by: jeneesh on Feb 3, 2013 12:39 PM -
"System error: Move error" on comparing DATE rows with literal timestamps
say, I have a table consisting of a DATE and a TIMESTAMP column:
create table test (
d date,
ts timestamp
now the problem:
when I try to retrieve values using a statement like this (using MaxDB's SQL Studio or via JDBC):
select * from test
where d >= {ts '2007-06-18 12:19:45'}
it produces the following error:
General error;-9111 POS(36) System error: Move error
So, I am not able to compare DATE columns with timestamp values?
In contrast, the following combinations all work flawlessly:
select * from test
where d >= {ts '2007-06-18 12:19:45'}
select * from test
where ts >= {d '2007-06-18'}
select * from test
where ts >= {ts '2007-06-18 12:19:45'}
Thus, the opposite direction (comparing a TIMESTAMP column to a literal date value) apparently poses no problem to the MaxDB database engine.
Unfortunately, I cannot just resort to "truncating" the timestamp values and using the {d ...}-Syntax, because I am using Apache's Torque object-relational mapper which generates the statement like this and feeds the JDBC API with it. Anyway, I deem this a bug in MaxDB, especially with respect to the quite obscure error message.
I can reproduce this issue on both MaxDB 7.5 and 7.6 server, using client software (SQL Studio), version 7.5 and 7.6 as well.
Does anybody know this problem?
TIA,
AlexHi,
this is a new bug and we will fix it with one of the next versions of MaxDB.
You can watch the proceeding in our internal bug tracking system:
http://www.sapdb.org/webpts?wptsdetail=yes&ErrorType=0&ErrorID=1151609
Thank you for reporting it.
Kind regards
Holger -
How to compare the date value with the date datatype column?
Hi,
I am executed a query to get output for the particular date in two different database.
I got output in one db environment, but in the another environment i didnt get the output.
APP_DECISION_DATE column contains date datatype
ex:
SQL> select DECISIONED_STAGE_ID,DECISIONED_STAGE_USER_ID from naap10_application where APP_DECISION_DATE = TO_DATE('23-JAN-07',
'DD-MON-YY'); 2
DECISIONED_STAGE_ID DECISIONED_STAG
2006060106 SYSTEM
DATABASE - II
SQL> select DECISIONED_STAGE_ID,DECISIONED_STAGE_USER_ID from naap10_application where APP_DECISION_DATE=
TO_DATE('31-JAN-2007','DD-MON-RRRR') and application_id=2007010028552;
no rows selected
in the same db i got the output while i used the TO_DATE(APP_DECISION_DATE)
SQL> select DECISIONED_STAGE_ID,DECISIONED_STAGE_USER_ID from naap10_application where TO_DATE(APP_DECISION_DATE)=
TO_DATE('31-JAN-2007','DD-MON-YYYY') and application_id=2007010028552; 2
DECISIONED_STAGE_ID DECISIONED_STAG
2006060113 SYSTEM
is it necessary to use TO_DATE function while i am using the data datatype column in the WHERE CLAUSE?
Thanks in advance.
sivaSorry & thanks sathish,
Now i got the result.
SQL> select DECISIONED_STAGE_ID,DECISIONED_STAGE_USER_ID from naap10_application where APP_DECISION_DATE BETWEEN TO_DATE ('31.01.2007 00:00:00', 'DD.MM.YYYY HH24:MI:SS') AND TO_DATE ('31.01.2007 23:59:59', 'DD.MM.YYYY HH24:MI:SS')
2 and application_id=2007010028552;
DECISIONED_STAGE_ID DECISIONED_STAG
2006060113 SYSTEM
================================
But one doubt,
When i created the column with the date datatype how it gets the time value,
And in one environment db i got the result but in another environment i dont get,
Shall i want to change any session status of date? -
I have data in timestamp format like 10/06/2009 11:59:01 PM EDT. I need to compare it with sysdate after removing the PM EDT etc.
I tried to_date, trunc etc... nothing worked. Is there a way to remove that PM EDT and compare with sysdate.Hi,
What problem you face when you directly compare timestamp column with sysdate?
select cast (systimestamp as timestamp with local time zone) -sysdate from dual;
CAST(SYSTIMESTAMPASTIMESTAMPWITHLOCALTIMEZONE)-SYSDATE
+000000000 00:00:00.481609Regards
Anurag Tibrewal. -
I am transferring data from table A to table B. there is a column in table A with datatype 'timestamp' that has the fraction seconds in the data. However I am using data type 'date' in table B where I am transferring the timestamp data to. I can query the fraction saconds using the hh:mm:ss.ff in table A but when I use it in table B it shows nothing and errors out.
i tried to use the CAST function to query the fraction seconds in table B but it shows zeroes.
question is - is the fraction second being transferred to table B? what can I do to make sure fractions are being transferred from A to B
any help will be appreciatedHi,
question is - is the fraction second being transferred to table B? what can I do to make sure fractions are being transferred from A to BThat is the one of the difference between TIMESTAMP and DATE. TIMESTAMP holds the miliseconds also. To transfer fraction of second you need to convert B table's datatype to TIMESTAMP.
Cheers,
Avinash -
Compare data and return the different columns
Good Afternoon,
I am trying to compare the data in two tables and return only the columns and data where there is a difference.
I have a compare script which checks every column in the two tables against each other, but as there are 200 columns in the tables it is tricky to see which column has a difference.
So in my result set if coulum N is the differenct I would only want to return column N from both tables in the result set.
I hope that this all makes sense?.Easiest way is to use tablediff utility for checking difference between tables
see
http://www.mssqltips.com/sqlservertip/1073/sql-server-tablediff-command-line-utility/
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to get data with out having any date/timestamp columns by year wise
hi,
how can i select years wise rows from tables,if that have not any date/timestamp column.Well Govind it quite depends on what is the data type of that column and the format in which it is stored.
If the data type is varchar2/varchar and all the values are in a uniform format then there is no problem. All you need to use is the to_date function to convert the supplied strings to default date format and then use to_char function to only extract the YY or YYYY or RR or RRRR aspect of the data.
For example: If the column is called 'hire_date' and it's data type is varchar2 and the entries in this column are all in a uniform format, say month,date,year like January,12,1999. What you need to do is convert this string to a default date value using to_date function, like to_date(hire_date,'format_model') In the format model mention the format of the hire_date string. The out put of this function can be fed into to_char to extract the year, like to_char(output_of_to_date,'YYYY')
I hope you got what I meant. Let me know if it was of any use. -
An import updates a date datatype column to sysdate
Hi
I couldn't find anything on this issue in the document.
I did an export of the data of table1 from database A, in table1 I have a column called CREATEDATE and it has a DATE datatype. When I imported it into database B, all rows now have the current SYSDATE in the CREATEDATE column instead of the original content as on db A.
Any clues why an import would treat a DATE column like that? and how I can maintain the original content on an import for a DATE type field???
I do not have a sysdate as the default value for the column.
Your help is appreciated!Sounds like you have a trigger firing. Triggers will fire during an import unless you disable them first. Try disabling all triggers on the tables being imported and see if that eliminates the problem.
-
Put together a TIMESTAMP column and a DATE column?
Anyone,
How can I piece together two columns one with a DATE and one with a TIMESTAMP and get the date with the timestamp.
Ex.
col_A = '4/1/1999 12:00:00.000 AM'
col_B = '1/1/1900 9:24:47.000 AM'
Desired Result
new_val = '4/1/1999 9:24:47.000 AM'
Thanks in advance,
MillerHere is a pruned down version of code:
CREATE OR REPLACE PROCEDURE MAXIMO.load_multiple_eq IS
CURSOR c1 IS
SELECT LOCATION,
ACTSTART,
COMPLETIONDATE,
COMPLETIONTIME,
SCHEDSTARTDATE,
SCHEDSTARTTIME
FROM MAXIMO.NIEHS_FEB_WOEQLIST ;
rec c1%ROWTYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO rec;
EXIT WHEN c1%NOTFOUND;
Insert into MAXIMO.WORKORDER ( WORKORDER.LOCATION ,
WORKORDER.ACTSTART ,
WORKORDER.ACTFINISH ,
WORKORDER.SCHEDSTART ,
WORKORDER.SCHEDFINISH )
Values (
rec.LOCATION, /* LOCATION */
SYSDATE, /* ACTSTART */
TO_TIMESTAMP(TO_CHAR(rec.COMPLETIONDATE,'MM/DD/YYYY')||' '||TO_CHAR(rec.COMPLETIONTIME,'HH.MI.SS AM'),'MM/DD/YYYY HH.MI.SSXFF AM') , /* ACTFINISH */
TO_TIMESTAMP(TO_CHAR(rec.SCHEDSTARTDATE,'MM/DD/YYYY')||' '||TO_CHAR(rec.SCHEDSTARTTIME,'HH.MI.SS AM'),'MM/DD/YYYY HH.MI.SSXFF AM') , /* SCHEDSTART */
rec.SCHEDFINISHDATE /* SCHEDFINISH */ );
END LOOP;
CLOSE c1;
END;Thanks,
Miller -
Data loading: formatting data for timestamp column
Hi All,
I have a table with a timestamp column named as created_date. I want to upload data to that table using data loading page. but there is one problem while uploading data, I have a csv file in which the created_date column data in two different format as follows ,
09/03/2013 03:33am
09/02/2013 03:24pm
the above data throws an error ORA-01821: date format not recognized.
In Data / Table Mapping page, I tried with MM/DD/YYYY HH12:MI:SS AM. What format should i use for am and pm??
Please help me to solve....
Thanks in advance
LakshmiI solved by using the format MM/DD/YYYY HH:MIAM.
Thanks
Lakshmi -
Can you specify format mask for date or timestamp columns
Hi,
Recently when I'm developing a PL/SQL application, I find that any format mismatch between data in table and format mask specified in to_date/to_timestamp function will cause exceptions. However, I'd like to make my application more robust and immune to this kind of problems, and know exactly which format mask to use for exactly what columns in db table.
Is there a way in a table column to specify the format mask for date/timestamp columns such that I can know exactly what format mask to use when doing conversion? Also I don't want to depend on NLS_DATE_FORMAT specification, don't want to make a long case statement to check for every date format allowed by Oracle.
Many thanks.As per my knowledge it can't be possible
casuse if you entered '12/11/2007' date
how oracle know that in date 12'th is the month or 11'th.
The person who entered that date will also have confusions in future.
either you have to fix one date format for your whole application (application configuration).
or you have to store the date format in other column of the table.
In case you set the date column to varchar and store all the dates without format then
in future you may face problems in future while fetching the records, searching etc.
Regards
Singh -
How much space a Date , time , TimeStamp column occupy?
Hi
what is size of a Date , Time and TimeStamp type ?
i mean how much bytes they require ?
ThanksApologies if this posts more than once. I got server errors.
Laurent:
Sysdate and systimestamp are actually different types than a date or timestamp column.
SQL> CREATE TABLE dt (dt DATE, ts TIMESTAMP);
Table created.
SQL> INSERT INTO dt VALUES(sysdate, systimestamp);
1 row created.
SQL> COMMIT;
Commit complete.
DUMP(DT)
Typ=12 Len=7: 120,106,6,2,17,43,10
SQL> SELECT DUMP(ts) FROM dt;
DUMP(TS)
Typ=180 Len=11: 120,106,6,2,17,43,10,28,185,249,48
SQL> SELECT DUMP(sysdate) from dual;
DUMP(SYSDATE)
Typ=13 Len=8: 7,214,6,2,16,50,17,0
SQL> SELECT DUMP(systimestamp) from dual;
DUMP(SYSTIMESTAMP)
Typ=188 Len=20: 7,214,6,2,20,50,30,0,48,111,78,168,252,0,5,0,0,0,0,0I seem to recall reading somewhere that sysdate is actually a representation of the C struct_t time structure, while a date column is Oracle's internal format. It looks like something similar is going on with systimestamp, and with the date and timestamp casts you are doing.
The inserts into the table above were done minutes before the selects, but definitely within the same hour. The byte values have no correlation, between the date field and sysdate, nor between the timestamp field and systimestamp, while the the date and timestamp fields are identical to the second. Similarly, the sysdate and systimestamp dumps are identical to the second.
The vsize function reports the physical storage required for the expression passed. My guess would be that it is implicitly casting sysdate and systimestamp to the equivalent internal representation before calculating the size.
John -
I have the following data flow:
ADO Source
Input Column: Cookies ID: 7371 Datatype: DT_NUMERIC
Output Column: Cookies ID: 7391 Datatype: DT_NUMERIC
DATA CONVERSION TASK
Input Column: Cookies ID: 1311 Datatype: DT_NUMERIC
Output Column: Copy of Cookies ID: 1444 Datatype: DT_I4
SQL Server Destination
Input Column: Copy of Cookies ID: 8733 Datatype: DT_I4
Output Column: Cookies ID: 8323 Datatype: DT_I4
This looks fine to me. Why am I getting the error?
This is SQL Server 2008 and I am working at this point only in BIDS, so it is not a question of dev vs prod server or anything. One environment, running in BIDS. Other similar data flows seems to be working ok. It seems the error is referring to a datatype
mismatch in the source--but how can that be?
Thanks!Actually, I am wrong in that Visakh. I think you are correct.
There are two versions of all tables, one with 15 minute rollups and one with daily rollups. Otherwise the tables are the same--same exact fields. I use a loop with a data flow inside to get data from one version of the rollup and then the other.
The problem is, for some of the fields with larger values the datatype is NUMERIC instead of INTEGER. (This is Cache database). SO:
dailyCookies: Field: CountOne Datatype: NUMERIC
15minCookies: Field: CountOne Datatype: INTEGER
A variable dynamically creates the query so it appends "daily" or "15min" to the beginning of the tables. So on the first loop it does the 15min tables and on the second the daily tables. When I created this particular table I have to plug a default query
in so I used the daily. It picked up the datatype as NUMERIC so when I run the package it loops through 15min first and sees the datatype is INTEGER.
How to deal with this? I suppose I could convert the datatype in the source query, but that would be a hassle to do that for some fields and not others. This tables has hundreds of fields, BTW. Can one source object deal with a change of datatypes? SSIS
is so picky on datatypes compared to other tools....
Thanks,
Maybe you are looking for
-
What does setting "Availability" on my calendar change?
For each event in the calendar on my iPhone 5 (iOS ver 6.1.4) there is an assigned availability for which the default is "Busy" does this effect what types of notifications i recieve during the times slated as "busy" by these events? Is there a way o
-
Standard remote enabled bapi for creation of purchaser contract in srm
Hello Friends Plz tell me is there any standard,remote enabled FM/BAPI in SRM system for creation of purchaser contract. I found BBP_PD_CTR_CREATE. But this is normal FM. I need BAPI like BAPI_CONTRACT_CREATE which there in ECC system. Plz help. Than
-
When I go the the page not all of the tabs will show up so I can not play it on Firefox. I have disabled all of the new add ons I put on it. I have a 64 bit windows does that have anything to do with it?
-
How to open a 16-bit dll in Labview
Hi, I would like to open a vi for a spectrometer (Jobin Yvon 270M), but I get the following error message: "A CIN tried to load a 16-bit dll. This operation is not supported under Labview for Windows 95 or Windows NT. The CIN and DLL must be recompil
-
HT201320 Can receive mail but cannot send it
Cannot send mail