...And now the query for getting the differences in minutes between the timestamps:
...
Difference between which two timestamps?
It obviously is not the difference between "updatets" and "insertts", because "insertts" is not being used in your query.
If you are trying to find out the difference between "updatets" and "sysdate" (or current time), then consider the output of the query:
The "updatets" shows a timestamp of 24-Jan-2013 and sysdate would be some day around 18-Apr-2013 (wherever you are on the planet Earth as of now). So the difference should be about 84 days, or 84*24*60 = 302400 minutes.
Since SYSDATE is like a "running target", let's use a fixed date to see how the query behaves. I'll use the date "2/24/2013 13:48:41" as my "current date" in the following query:
Now, the difference between "24-JAN-2013 13:49:40" and "24-FEB-2013 13:48:41" is about 30 days, or approximately 30*24*60 = 43200 minutes but the query above returns exactly 1 minute as the difference.
The fallacy in the logic would be clear if you see what is being done here. Each date is converted to minutes from the start of its own month.
So "24-JAN-2013 13:49:40" is 35389 minutes from "1-JAN-2013".
And "24-FEB-2013 13:48:41" is 35388 minutes from "1-FEB-2013".
And so the difference is 1 minute.
So if the two dates ("updatets" and SYSDATE) lie in the same month, then you'll start counting from the same date (beginning of that month) and in that case your query will work. Otherwise it won't.
For example, if the "updatets" is, say, "31-MAR-2013 23:59:59" and you run your query just one second later (when the month has changed), then the result will be incorrect.
In Oracle, the difference between two DATEs is the number of days between them. If the difference has a fractional part, then that corresponds to the number of minutes and seconds in addition to the days in between. So, the difference in minutes between two DATEs is given by this expression -
Using this information, the query could be written thusly -
Another example where the difference is about 1 minute:
I used the CAST function because the datatype of "updatets" is TIMESTAMP.
Accordingly, your query would be -
Last edited by durden_tyler; 04-18-2013 at 03:10 AM..
Hello All,
I hope I'm posting this in the right section.
I have zero sql query writing skill, in fact, I've never done it before, but for some reason, a request came across my desk to get information from one of our databases. I have about 200 ticket numbers that have no information attached,... (8 Replies)
Hi All ,
I have tried many times am getting syntax error on 'UNION'
can anybody tell me ...
INSERT INTO table1
(
Type
, num_items
, num_letters
, total_value
)
(select
type='1',
num_items,
num_letters=count(*),
total_value=sum(letter_value)
from
table2
where
num_items = 1 (1 Reply)
Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database.
I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :(
What should I do? I'm not sure that... (2 Replies)
I used the following code
code
select * from tablename where columnname
Instead of printing the expected output it prints all the files in the present directory since there is a "*" in the code. Is there any way to overcome the problem?
Thanks
Ananth (2 Replies)
Hi Everyone,
Can anyone pls help me out......with my requirement, i am struggling since 3 days. Please find the requirement below
my file contains below data
R1|Array/Network Resistor - VIP|V_RES_CLASS|V_MOUNT_FEATURE|SURFACE MOUNT|AND|8533.10.00.20|8533.10.00.20|
R1|Array/Network Resistor... (9 Replies)
Hi ,
I used the below script to get the sql data into csv file using unix scripting.
I m getting the output into an output file but the output file is not displayed in a separe columns .
#!/bin/ksh
export FILE_PATH=/maav/home/xyz/abc/
rm $FILE_PATH/sample.csv
sqlplus -s... (2 Replies)
Hello Everyone,
I am looking to write a script that will run on many machines in a network at the same time. They need to write a result to a common location. I plan to use a SQLlite database as this common writing point. But the concern I have is how SQLlite will react to multiple writes that... (1 Reply)
Hi ...
I am doing a switch user and then rsh and then running a sql query .
I am successfull in rsh and logging into the database , but my query doesnt run ..
Here's the command :
su - linus -c "rsh -l linus psmf ORACLE_SID=SMP;export ORACLE_SID;sqlplus... (1 Reply)
I have a script that looks for all jobs that contain a particular calendar.
Some of the calendars have '&' in them and sql freaks out when it encounters that.. is there a way around this?
I have tried:
select job_name from job where run_calendar='1&15dom'
select job_name from job... (3 Replies)