If a job is supposed to be run based on:
* */2 * * *
When should this job be run?
Thanks.
If your cron job is like the following
* */2 * * *
It is run every minute of every 2nd hour, every day.
From crontab man page,
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
A field may be an asterisk (*), which always stands for all values from "first-last".
Related
I have an issue importing date from a Tririga database into a SQL database. Mainly I cant convert the date properly and it looks like is not the commont format I have seen around.
Eg date value incomming 775724400000
Running something like select to_date('765187200000', 'DDMMYYYYHH24MISS') my_date FROM dual;
give me an error
ORA-01847: day of month must be between 1 and last day of month
01847. 00000 - "day of month must be between 1 and last day of month"
I found the following info from this link seems to be also from tririga
link_help
And the size of the number are about 10 digits meanwhile this one is 12 and I know for fact this dates should be from the past 10 years (most of them)
I can't seem to find anything that gives me an answer how to convert this into proper dates.
Any suggestions?
The input number appears to be "epoch", a count of milliseconds elapsed since 1 January 1970 GMT (UTC).
To convert to date is not difficult:
select date '1970-01-01' + (775724400000 / 86400000) as dt from dual;
DT
--------------------
1994-Aug-01 07:00:00
Note the hard-coded literals: date '1970-01-01' (epoch is by definition measured from midnight on this date) and 86400000. By one of the definitions (in the previous version of the International System of Units and Weights), a second is 1/86400 of a median day. In Oracle, date arithmetic is based on the number 1 representing one day, so to convert your milliseconds to days you must divide your input by 86400 * 1000.
The most delicate question has to do with time zones (and possibly daylight saving time, also related to time zone). In most cases, epoch is measured from midnight on 1 January 1970 GMT, not from midnight on 1 January 1970 in local time. Do you need to adjust for that? Only you and your business users can answer that question.
(As an aside, the number you provided does NOT represent a date in the past 10 years - not even close.)
I have this SQL query
SELECT TOALIAS, COUNT(*), TO_CHAR(TIMESTAMP,'DD/MM/YYYY HH12:MI') AS TIMESTAMP
FROM TABLE1
WHERE TIMESTAMP >= SYSDATE - 15/(24*60)
AND STATUS = 1
GROUP BY TOALIAS, TO_CHAR(TIMESTAMP,'DD/MM/YYYY HH12:MI');
I am using TOAD 12.9. I want to create a job and run this query every 15 minutes and insert the data into Table2(these records will be automatically pushed as an SMS message by an application).
I also have access to create a cron job. I found this one on Stack Overflow
0 0/15 * 1/1 * ? * /home/testdata/script/sample.sql
Can I create a cron job; let it connect to database and run a query from Table1 and insert into Table2 every 15 minutes?
*/15 * * * * command
this is the way to make cronjob to run every 15 mins.
I think you'd better to write a shell script to connect to your database. Other wise you may get authentication error.
First event deletes all rows from a table:
CREATE DEFINER=`frontdes_user`#`localhost` EVENT `DELETE_flux_receptie` ON SCHEDULE EVERY 1 DAY STARTS '2015-09-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO DELETE FROM `flux_receptie`
Second event deletes the id column from the same table:
CREATE DEFINER=`frontdes_user`#`localhost` EVENT `delete_id` ON SCHEDULE EVERY 1 DAY STARTS '2015-09-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO ALTER TABLE `flux_receptie` DROP `id`
Third event adds id column into the same table:
CREATE DEFINER=`frontdes_user`#`localhost` EVENT `add_id` ON SCHEDULE EVERY 1 DAY STARTS '2015-09-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO ALTER TABLE `flux_receptie` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)
I want these events to run daily:
First one daily at 06:30, the second one daily at 06:35 and the third daily at 06:40.
Can anyone help me please with the correct schedule? Best regards, Bogdan.
If you have access to your machine you can use cronJob, the basic format of a crontab schedule consists of 6 fields, placed on a single line and separated by spaces, formatted as follows:
minute hour day month day-of-week command-line-to-execute
first create a script:
First script
#!/bin/bash
mysql --user=[username] --password=[password] --database=[db name] --execute="CREATE DEFINER=`frontdes_user`#`localhost` EVENT `DELETE_flux_receptie` ON SCHEDULE EVERY 1 DAY STARTS '2015-09-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO DELETE FROM `flux_receptie`"
Second script
#!/bin/bash
mysql --user=[username] --password=[password] --database=[db name] --execute="CREATE DEFINER=`frontdes_user`#`localhost` EVENT `delete_id` ON SCHEDULE EVERY 1 DAY STARTS '2015-09-06 00:00:00' ON COMPLETION PRESERVE ENABLE DO ALTER TABLE `flux_receptie` DROP `id`"
Third script
#!/bin/bash
mysql --user=[username] --password=[password] --database=[db name] --execute="ALTER TABLE `flux_receptie` ADD `id` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)"
then create 3 cron using crontab -e
crontab -e
30 6 * * * /path/of/scriptOne
35 6 * * * /path/of/scriptTwo
40 6 * * * /path/of/scriptThree
I have the following Oracle query
SELECT *
FROM table
WHERE date_opened
BETWEEN ((TO_DATE('2011-08-01', 'yyyy-mm-dd') - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400))
AND ((TO_DATE('2011-08-31', 'yyyy-mm-dd') - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400))
that nearly works but it doesn't include the dates records that are dated 2011-08-31. Any ideas? It has probably got something to do with how I am converting my date strings...
UPDATE: I really should have said that the date is actually a UNIX timestamp. That is why I am using the 86400 and 01-JAN-1970
Thank you :)
If the upper bound of an interval is not included in your results, then it's likely that you're building an "exclusive" filter with respect to the upper bound. So just add one day to the upper bound. I.e.
AND ((TO_DATE(...) - to_date(...) + 1) * (86400)) - 1
In Oracle, +1 will add one day when used in date time arithmetic.
Note: BETWEEN .. AND creates an inclusive filter, as Ollie stated, but your arithmetic may change that behaviour by transforming things to seconds
You don't include anything that happened after midnight the last day.
try:
AND ((TO_DATE('2011-09-01', 'yyyy-mm-dd') - to_date('01-JAN-1970','DD-MON-YYYY')) * (86400) - 1)
You only want to compare the date without the timestamp implicit in Oracle dates.
WHERE trunc(date_opened) BETWEEN . . .
I have a query to run on oracle that gives output as sid,serial#,transaction start time,sql_id,transaction id.
What I need to do is, whenever a transaction's start time is more than 1 hour behind the system time, I need to run another query with that sql_id and send it as an email.
How do I compare this time output from ORACLE sql and compare it with the system time?
I need to automate this process and add it to the cron on UNIX.
Please help!
The function SYSDATE returns the current system date. When you subtract two dates, you get a difference measured in days. Multiply by 24 and you get a difference in terms of hours.
SELECT *
FROM v$transaction
WHERE (sysdate - start_date)*24 > 1
will give you the transactions that started more than 1 hour ago. You can also use interval arithmetic if you find that clearer.
SELECT *
FROM v$transaction
WHERE sysdate - interval '1' hour > start_date