473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

difference between now and sysdate

pradeepjain
563 512MB
hi,
I got this definitions from mysql official site

now() - returns the current date and time.

SYSDATE() returns the time at which it executes

This differs from the behavior for NOW(), which returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.)

i did not get the actual meaning and when to use sysdate instead of now?
Mar 27 '10 #1
1 15810
Atli
5,058 Expert 4TB
Hey.

Imagine having a stored procedure that inserts a billion rows into a table. Each row is supposed to have an identical time-stamp. The problem is that inserting a billion rows would take a lot of time.

If you use the SYSDATE() function, it would use the time when each individual INERT statement is executed, which means the rows would not have an identical time-stamp, because each statement is not executed at the same time.

To fix that, you can use the NOW() function. Instead of using the exact time when it is executed, it uses the time when the stored procedure was started, so the rows would all have the same time-stamp.

The example in the SYSDATE() manual entry explains this pretty well:
Expand|Select|Wrap|Line Numbers
  1. mysql> SELECT NOW(), SLEEP(2), NOW();
  2. +---------------------+----------+---------------------+
  3. | NOW()               | SLEEP(2) | NOW()               |
  4. +---------------------+----------+---------------------+
  5. | 2006-04-12 13:47:36 |        0 | 2006-04-12 13:47:36 |
  6. +---------------------+----------+---------------------+
  7.  
  8. mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE();
  9. +---------------------+----------+---------------------+
  10. | SYSDATE()           | SLEEP(2) | SYSDATE()           |
  11. +---------------------+----------+---------------------+
  12. | 2006-04-12 13:47:44 |        0 | 2006-04-12 13:47:46 |
  13. +---------------------+----------+---------------------+
  14.  
In the top query, using the NOW() function, both return the same time even though they are executed two seconds a part. - In the bottom query, however, using the SYSDATE() function, they return the exact time when they are executed, two seconds a part.
Mar 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WroteForLuck | last post by:
I am trying to write a simple SQL statement which will take a string (startdate) in the format DDMMYYYY and compare it to a date stored in an Oracle database. My SQL is as follows: <% "select...
1
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
0
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
4
by: sajan | last post by:
Hi, I new to python. I'm trying to make changes to an existing python code . The code has an if condition something like if datetime(*(time.strptime(creation_date, '%d-%b-%y'))) <...
5
rsrinivasan
by: rsrinivasan | last post by:
Hi, When i Execute this query, I got the result as 29-MAY-07 select sysdate from dual; But i want 29-MAY-2007. What is the query for it? Thanks,
1
by: sajithamol | last post by:
What is the difference between current_date & sysdate function?
12
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
3
by: premkumarsp1 | last post by:
hi in the oracle sysdate, time is coming wrongly. THe date and time in the OS from where i am accessing oracle and in the OS where oracle is installed is correct. I want to know how to update time...
1
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.