Compare date from recordset
Hi.
Im trying to compare a date from oracle to see if it's more than 24 hours old or not. If I get the date with
rs.getDate(meta.getColumnName(4));
My result is : 2007-05-23
If i use
rs.getString(meta.getColumnName(4));
My result is: 2007-05-23 10:21:12.0
How can i try
if(rs.getDate(meta.getColumnName(4)) is lesser than 24 hours)
You know what i meen :)
Sincerly
Rothsten
Well here is a simple code snippet which might help you....
long timedifference = rs.getDate(column_name2).getTime() - rs.getDate(column_name1).getTime();
// day = 24 hrs , 1hr = 3600 sec,1 sec = 1000 milli sec
long millisec_per_day = 24*3600*1000;
if( timedifference > millisec_per_day)
System.out.println("More than a day");
else if( timedifference < millisec_per_day)
System.out.println("Less than a day");
else if( timedifference == millisec_per_day)
System.out.println("Exactly a day");
NOTE: The following snippet may not be a perfect solution when it comes to implementation part (as many ppl do it with Calendar and others).
Hope this might help :)
REGARDS,
RaHuL
Similar Messages
-
Hello, I am trying to compare data from one and the same table. In short I have:
NAME DTM CHARGE
Atanas 8/18/2012 9:33:23 AM 100
Atanas 8/18/2012 9:33:23 AM 101
Niki 8/18/2012 9:33:43 AM 200
Niki 8/17/2012 9:34:10 AM 100
Niki 8/18/2012 9:33:43 AM 201
Niki 8/17/2012 9:34:10 AM 101
Atanas 8/17/2012 9:34:29 AM 50
Atanas 8/17/2012 9:34:29 AM 51
Joro 8/18/2012 12:10:12 PM 400
Joro 8/17/2012 12:10:21 PM 300
Joro 8/18/2012 12:10:12 PM 401
Joro 8/17/2012 12:10:21 PM 301
And I want to sum CHARGE for each DTM for each NAME and present the difference in an additional column, the output should be like that:
NAME DTM CHARGE DTM CHARGE DIFFERENCE
Atanas 8/17/2012 9:33:23 AM 101 8/18/2012 9:33:23 AM 201 - 100
Niki 8/17/2012 9:33:23 AM 201 8/18/2012 9:33:23 AM 401 - 200
Joro 8/17/2012 9:33:23 AM 601 8/18/2012 9:33:23 AM 801 200
the DTM will be always /sysdate - 2/ and /sysdate - 1/,
Thanks in advance!It is not clear what you are trying to do, but it looks like:
with sample_table as (
select 'Atanas' name,to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am') dtm,100 charge from dual union all
select 'Atanas',to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),200 from dual union all
select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),100 from dual union all
select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),201 from dual union all
select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),50 from dual union all
select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),51 from dual union all
select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),400 from dual union all
select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),300 from dual union all
select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),401 from dual union all
select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),301 from dual
select nvl(s1.name,s2.name) name,
s1.dtm,
s1.charge,
s2.dtm,
s2.charge,
s2.charge - s1.charge diff
from (
select name,
dtm,
sum(charge) charge
from sample_table
where dtm >= trunc(sysdate) - 1
and dtm < trunc(sysdate)
group by name,
dtm
) s1
full join
select name,
dtm,
sum(charge) charge
from sample_table
where dtm >= trunc(sysdate)
and dtm < trunc(sysdate) + 1
group by name,
dtm
) s2
on s1.name = s2.name
NAME DTM CHARGE DTM CHARGE DIFF
Atanas 17-AUG-12 101 18-AUG-12 201 100
Niki 17-AUG-12 201 18-AUG-12 401 200
Joro 17-AUG-12 601 18-AUG-12 801 200
SQL> SY. -
How to compare data from 2 different time periods
Hi folks,
I have a question on approach to a problem. I want to be able to compare data from a common db, but for 2 different time periods. For example I want to see the number of occurences of an instance in my data for today and compare it against occurences a week ago today. What's the best approach for this kind of problem? Is this done with 2 separate queries from 2 sub reports and then compared some how? Any comments on this approach or an other are appreciated.
TIA bvdFollow these steps:
1) Bring your first time period in your main report. This will be your first query.
2) Bring your second time period in a subreport. This will be your second query.
3) Bring the values from your subreport into your main report using shared variables.
4) Lastly, compare the results using formulas in your main report.
I hope this information proves useful.
Regards,
Zack H. -
Question - Comparing data from 2 databases
I'm new to Oracle - I'm trying to compare data from 2 separate databases.
I'm trying to get data from both databases based on a common TRACKING_NUMBER. The issue is that in one database there are additional 0s in front of the Tracking_Number.
So I'm trying to find out what I can put in my query to remove those zero's in front of the tracking number. I have the query below - it's very long.
SELECT DISTINCT cm.TRACKING_NUMBER_TYPE AS HType,
TRUNC(cm.CREATED_DATE) as CodeMoveDate,
SUBSTR(cm.CODE_MOVE_DESC, 1, 50) AS Description,
cm.TRACKING_NUMBER AS TrackingNumber,
rq.Plant_Name as Location,
jr_eur.Assignee as Tracker,
TRUNC(MAX(jr_spec.Journal_Date)) as Date_Spec,
TRUNC(MAX(jr_app.Journal_Date)) as Date_Approved,
TRUNC(MAX(jr_ut.Journal_Date)) as Date_Unit,
TRUNC(MAX(jr_qa.Journal_Date)) as Date_Assurance,
TRUNC(MAX(jr_eur.Journal_Date)) as Date_Enduser,
TRUNC(MAX(jr_gv.Journal_Date)) as Date_Gatekeeper,
TRUNC(MAX(jr_prod.Journal_Date)) as Date_Move,
TRUNC(MAX(jr_eun.Journal_Date)) as Date_Notification,
TRUNC(MAX(jr_pver.Journal_Date)) as Date_Production,
TRUNC(MAX(jr_udoc.Journal_Date)) as Date_Documentation
FROM PROJMAN.PM_CODE_MOVES_V cm,
PROJMAN.PM_Requests_V rq,
PROJMAN.PM_Journals_V jr_spec,
PROJMAN.PM_Journals_V jr_app,
PROJMAN.PM_Journals_V jr_ut,
PROJMAN.PM_Journals_V jr_qa,
PROJMAN.PM_Journals_V jr_eur,
PROJMAN.PM_Journals_V jr_gv,
PROJMAN.PM_Journals_V jr_prod,
PROJMAN.PM_Journals_V jr_eun,
PROJMAN.PM_Journals_V jr_pver,
PROJMAN.PM_Journals_V jr_udoc
WHERE cm.TRACKING_NUMBER = LTRIM(rq.Request_ID(+))
AND cm.TRACKING_NUMBER = jr_spec.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_app.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_ut.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_qa.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_eur.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_gv.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_prod.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_eun.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_pver.Request_ID(+)
AND cm.TRACKING_NUMBER = jr_udoc.Request_ID(+)
AND jr_spec.Journal_Status(+) = 'Spec Doc'
AND jr_app.Journal_Status(+) = 'Approved'
AND jr_ut.Journal_Status(+) = 'Unit Test'
AND jr_qa.Journal_Status(+) = 'Quality Assurance'
AND jr_eur.Journal_Status(+) = 'End User Review'
AND jr_gv.Journal_Status(+) = 'Gatekeeper Verificat'
AND jr_prod.Journal_Status(+) = 'Move to Production'
AND jr_eun.Journal_Status(+) = 'End User Notificatio'
AND jr_pver.Journal_Status(+) = 'Production Verificat'
AND jr_udoc.Journal_Status(+) = 'User Documentation'
AND cm.TRACKING_NUMBER_TYPE = 'H'
and cm.CREATED_DATE >{d '2006-12-31'}
GROUP BY
cm.TRACKING_NUMBER_TYPE,
TRUNC(cm.CREATED_DATE),
cm.CODE_MOVE_DESC,
cm.TRACKING_NUMBER,
rq.Plant_Name,
jr_eur.Assignee
ORDER BY TRUNC(cm.CREATED_DATE)I recommend using a product.
I used to write scripts and procedures, but no more!
Reason is: you save time. A lot of time. You pay few hunderes $ once for the product.
If you do it yourself, you waste half-days doing it properly.
A good tool for database compare is Comparenicus (www.compareniucs.com).
I'm using it for 6 months now and it saves me a lot of time. -
Load All Data From RecordSet to JTable
How Load All Data From RecordSet to JTable by JTable to be base on Applet
Create one table model and setValueAt your data
-
Comparing data from two tables
My PL/SQL is very limited, however, I need to write some code that compares data stored in two different Oracle tables and then writes the differences to a third table. Both tables have primary keys that I will use to ensure I am comparing like for like. These tables could be large.
Any help on the best way to do this, or any code examples would be very appreciated.One fairly efficient way of doing this is with set operators. The following code is untested - but looks right ;). It also assumes you want to know the provenance of the rows; if not, just zap the literal from each SELECT statement.
INSERT INTO diff_tab SELECT * FROM
( (SELECT 'tab1nottab2' AS provenance, t1.col1, t1.col2 FROM tab1 t1
MINUS
SELECT 'tab1nottab2', t2.col_a, t2.col_b FROM tab2 t2)
UNION ALL
(SELECT 'tab2nottab1', t2.col_a, t2.col_b FROM tab2 t2
MINUS
SELECT 'tab2nottab1', t1.col1, t1.col2 FROM tab1 t1)
/Cheers, APC -
How compare data from 2 different ODS and then load data to Cube
Hello, everybody,
I have 2 ODS ZINFO_1 and ZINFO_2. These ODS contain data:
ZINFO_1
document number; item number; amount
10004;1;200
10004;3;330
10004;4;650
10005;1;110
ZINFO_2
document number; item number; amount
10004;1;700
10004;4;430
After comparison ODS ZINFO_1 with ZINFO_2, into InfoCube ZICINFO_3 I have get data from ODS ZINFO_1 that document number and item number is not equal to ZINFO_2 ODSs document number and item number.
Data in InfoCube ZICINFO_3 should be:
ZICINFO_3
document number; item number; amount
10004;3;330
10005;1;110
Could you give me suggestions how do this?
Thanks in advance.
Best Regards,
Arunas StonysMost of the time you write a routine in the update rule and you want to read a table or ODS to look up for that particular field you are intersted in, if you are doing reading the table or DSO in the update rule, it will execute for each and every record, but you do reading the table in the start routine which will get executed for each data package and in your update rule, you read the internal table to put your logic.
The Start rouline can be as follows
Please do modify this routline for ur requirement
Another situation where I am loading DATA from DSO 1 to DSO 2 and looking for Records from DSO3 and DSO4.
DSO1---->DSO2(looking up data from DSO3 and DSO4 to update to DSO2).
NOw in the start routine I define 2 internal tables for DSO3 and DSO4 having sturctures like DSO3 and DSO4(with only useful fields and key fields,becoz u may not need all the fields from dSO3 and DSO4 afterall)
Now I am loading data in those interanal tables by using SELECT Query in START routine.
Now In various transformatino rule for populating different target fields I am reading those internal tables(itab_dso3 and itab_dso4) putting the read and where condition like
Code for field Z(of DSO2)
Read fieldX fieldY fields Z from itab_dso3 into wa_dso3 with key fieldsX=source_fields-fieldsx fieldY=source_fields-fieldsy.
if sy-subrc eq 0.
result = wa_dso3-fieldz
endif.
(here i am reading the itab loaded in start routine and reading it with the help of two source fields(dso1 fields fieldX and fieldY ) and comparing them with DSO3 .If there is a match then I am udpating fieldz of DSO2 with fieldZ from DSO3.)
Please do assign points if it is needful.
Thanks in advance.
Best WIshes,
VVenkat. -
Compare date from snapshot tables
I have mothly snapshot tables in oracle database 10gR2 that I loaded in discoverer 10gR2 as it as business users want to query monthly data. Fine.
Now business users want to compare two months data something like:
'snap_date jan-2009' 'site_id for jan-2009' 'site_status for jan-2009' 'snap_date feb-2009' 'site_id for feb-2009' 'site_status for feb-2009'
01/31/2009 a0001P active 02/28/2009 a0001P inactive
01/31/2009 b0001P active 02/28/2009 deleted -
01/31/2009 c0001L active 02/28/2009 c0001L active
01/31/2009 - - 02/28/2009 z0001P active
They want to see it like:
'site_id' 'site_status for jan-2009' 'site_status for feb-2009'
a0001P active inactive
b0001P active site deleted
c0001L active active
z0001P no site found active
Please suggest, how can I achieve this in discoverer?
Two snap_dates can be any dates from last five years on which already snap_shot has been taken and added to the snapshot table.
Thanks.
Edited by: vkumar on Mar 17, 2009 2:17 PMHi Rod,
Actually this is just one table having snapshot data for different months like:
'snap_date' 'site_id' 'site_status'
01/31/2009 a0001P active
01/31/2009 b0001P active
01/31/2009 c0001L active
02/28/2009 a0001P inactive
02/28/2009 c0001L active
02/28/2009 z0001P active
From this table I want to compare data for different dates with respect to site_id?
Thanks.
Edited by: vkumar on Mar 19, 2009 10:44 AM
Edited by: vkumar on Mar 19, 2009 10:44 AM -
Hi All,
This is a JDBC-Prooxy scenario. I used a JDBC sender adapter to pick records from the table and used a proxy to to pass the data to R/3 and called a fuction module in R/3. The scenario worked fine as expected.
Now the problem is there is another table in the database which contains the history. Now I need to compare the records in 2 tables and pass the data to R/3 if a record does not exist in second table(This can be done by a select querry), but if a record exists I need to check for "amount" field again. If the amount in history file is lesser, the record has to be passed with the amount(difference between the first table and history table). If the amount is also same, I should not send the record to R/3.
How can I achieve this? Where can I do these comparisons and pass the data to R/3?
Thanks in Advance.
Regards,
Jai Shankar.Jai,
The solution would like this,
1. Receive -- To select data from Table 1
2. Send Synch -- To select data from table 2 ( refer my blog )
3. Transforamtion ( n:1 ) -- combine the data from step 1 and step 2 and do the mappinng . Set some field to determine if the IDOC should be sent or not.
4. Switch -- Check for the data and then send the IDOC if needed else terminate the BPM anbd process flow.
Regards,
Bhavesh -
Hi all
I have a little problem regarding the use of arrays and obtaining the integer value from an index of one of the columns. I need to implement a program that reads data from serial ports. There are four serial ports and it is assumed that independant sets of data will be retrieved from each of these. I need my program to continuously loop and check to see if the data has changed at any of the serial ports (i've got this part working). The way it can be manually determined is if the file is opened and at the top of the data there is the error number which is incremented every time the data is changed. I have put the data into a 2D array for later use and have then put just the first column into a single array in the hope of bein
g able to convert it to an integer or some form that can be compared. I need the highest error number for each peripheral to be stored (probably need separate loops/case for each serial port? - multitasking?) and when the data is next sent, i need to be able to compare it to see if the error number has changed and if it hasn't just continue looping and if it has make the new value the highest (in which case the rest of the data needs to manipulated and automatically updated in the database). I have been thrown head first into this project and to this date had only been a casual Labview programmer (V6i)
Can anyone help?
Ive attached the snippet that is for comapring the data only if anyone can build upon it (or scrap it!)
Thanks
Ridge
Attachments:
Array.vi 31 KBTo compare the error is easy,attached is a little modification to your vi with shift register and Array max and min function. I'm not sure if this is the only problem.
Attachments:
Array[1].vi 38 KB -
Compare data from 2 text files and output match
Hi all,
I need some advice.
Firstly in BinaryCode.txt the data is as such:
Replace BinaryCode0 1 0 0 0 0 0 0 0 0
Replace BinaryCode0 1 0 0 0 0 0 0 0 1
Replace BinaryCode1 1 1 1 0 1 1 1 1 1
Replace BinaryCode1 1 0 0 0 0 0 0 0 0
the first line in the text file is the header. So I need to check if the names in the second column (BinaryCode0 or BinaryCode1)appear in the Timed_Sets.txt file.
The data in Timed_Sets.txt is as such:
BinaryCode0,6,40,.........................
BinaryCode0,7,40,.........................
BCName1,0,20,.............................
BCName1,1,20,.............................
For example since BinaryCode0 is a match I will output the entire row in Timed_Set.txt to another array.
I have been working on a program but I don't get the expected output.
The text files and the VI are attached.
I appreciate your kind assistance in the matter.
Thank You
Regards
kart
Solved!
Go to Solution.
Attachments:
BinaryCode.txt 1 KB
compare text files.vi 15 KB
Timed_Sets.txt 2 KBIf I understood correctly what the output should be then what you basically need to do is to walk through the column in BinaryCode.txt and for each unique value pull out the corresponding rows from Timed_Sets.txt. There's a variety of ways to do this, depending on how much data you have and whether or not you can use any kind of prior knowledge as to the actual file content (such as the names of the keys being searched). Attached is one way. Modify as needed.
Attachments:
compare text files MOD.vi 27 KB -
Select column by comparing data from another column
I have a table of products by their price.
Product
Price
bag
1000
gloves
200
socks
400
hat
100
need to select all products where price is greater than price of "gloves"...
Dhananjay ReleSelect * from Table1
where Price > (Select Max(price) from Table1
where Product = 'gloves');
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com -
How to compare dates from a hashmap
I have a HashMap which has java.util.Date objects as keys. I want to compare these dates with a constant date object. When I do a map.getKey() it retunrs me a java.lang.Object. I wanted to know how do I compare this to a java.util.Date??
Map myMap = new HashMap();
myMap.put(java.util.Date, value);
Date dateToBeTested = new Date(myMap.getKey()); // I know this is deprecated.
Also, using SimpleDateFomat did not help me. The date format in the map is Sun Sep 07 23:59:59 2008 CDT & somehow SimpleDateFormat.parse does not recognize it. Can someone tell me what else can I do here?pradeep_chanda wrote:
I have a HashMap which has java.util.Date objects as keys. I want to compare these dates with a constant date object. When I do a map.getKey() it retunrs me a java.lang.Object. I wanted to know how do I compare this to a java.util.Date??Cast it to a Date, but if you follow the Generics suggestion by ejp, this is not needed.
>
Map myMap = new HashMap();
myMap.put(java.util.Date, value);
Date dateToBeTested = new Date(myMap.getKey()); // I know this is deprecated.
Also, using SimpleDateFomat did not help me. The date format in the map is Sun Sep 07 23:59:59 2008 CDT & somehow SimpleDateFormat.parse does not recognize it. Can someone tell me what else can I do here?Dates do not have a format, a String representation of a Date, does, but a Date does not. Are you using Date objects as the keys or String objects?
Also, why do you need to compare them? If you simply need to find out whether a certain Date is used as a key, there are methods especially for that. If you need the sorted list of keys, then simply retrieve the key set and sort it.
What exactly is it that you are trying to accomplish? -
Compare date from xml data to new Date() in Repeater
Hi All
I am using repeater and while those following 2 display the
same
(when reaching the current day)
<mx:Label text="{new Date().getDate().toString()}"/>
<mx:Label text="{r.currentItem.dayofmonth}"/>
the following line display nothing
<mx:Label
visible="{r.currentItem.dayofmonth==new
Date().getDay().toString()?
true:false}" text="{new Date().getDate().toString()}"/>
Why? and how can I fix this?
mordsmWhy is it not displaying, because of the text or because of
the visible?
Also, when working with repeater, I advise creating a custom
component and repeat that. Pass in the entire currentItem on a
public property. If you implement the property using getter/setter
function pairs, you can debug the dataflow easily. (note, Property
values are set on a component before its initialize or
creationComplete events fire)
Handlers can access the entire dataProvider item in its
native dataType through the event.currentTarget property. -
Comparing data in different resultsets
Hi everybody!
I am working on an web application involving some EAI, as a requirement i need to compare data from two different sources (databases to be precise) and fill a XML based on certain rules. I wish to know if there is a way to compare two ResultSet objects (with almost similar data) directly, or the only way to do is compare each value seperately.
Also please suggest from efficiency point of view if its viable to store data from resultSet to a certain struc kind of object and then comparing, as it would involve lots of overhead compared to directly comparing the two resultsets.
TIA
Abhisheki have to compare various columns of each row and assign flags in output xml as to note if data is inconsistant, though i am taking measures so as to get the rows in the same order in both result sets, but the primary purpose of this comparison is indeed to check data integrity between both the sources.
Maybe you are looking for
-
Android res/layout Folder not included in the APK file (but included in the ANE)
I'm having a problem with resources on an Adobe ANE Android extension: android.content.res.Resources@NotFoundException: id.viewView I have a xml layout file, which is included in the ANE file (checking by unzipping the ANE file and looking into MET
-
Ghost Images - Pages to PDF, Kinko's Printing
I could really use some help here. I am trying to print about 8 pages of images & text in the Extreme Template. When I export the file to PDF everything looks fine, I then took it to kinko's to be printed on card stock and binded and when they did th
-
Oracle 10g XE migrate from 32bit to 64bit becomes slower
Oracle 10g XE migrate from 32bit to 64bit becomes slower Currently we have a database using Oracle 10g XE R2 (Oracle Database 10g Express Edition Release 10.2.0.1.0) on a linux 32bit server. And recently we did migrate it to another 64bit linux serve
-
Hi Industry gurus I am confused.suppose there is question"How can I extend all material to a new plant? This question belong to technical side or function side and why? I will appreciate the response for the same.
-
Download error - stopped er -100000
When trying to download a purchase I continually get the message shown in the subject line. Any ideas what to do???