Friday, February 17, 2012

dbms_utility.get_time equivalent in sql server

Hi,
I need to convert the following oracle syntax to sql server:
timevar number;
timevar := dbms_utility.get_time;
This prints : 50989467
I aware of the function getDate() or current_timestamp but they display only the dates and if I convert them to float then the results are not same. Any pointers will be appreciated.
Srik

Hi,

I believe the dbms_utility.get_time routine is used mainly for timing loops. It returns the # of 100ths of a second since "some arbitrary epoch". Therefore, it doesn't have much meaning outside of marking elapsed time.

The SQL Server datetime data type has a resolution of 3.33 milliseconds. You can use the DATEDIFF() built-in function to return the elapsed # of milliseconds between two datetime values. Therefore, it may be something you can use in a way that is similar to Oracle's dbms_utility.get_time routine. Please note that the return type of the DATEDIFF() built-in function is a 32-bit signed integer, which means the the maximum possible elapsed time in millisecond units is equivalent to 24 days, 20 hours, 31 minutes and 23.647 seconds. Anything beyond that will cause an arithmetic overflow.

Here is a sample usage.

declare @.now datetime, @.then datetime
select @.then = getdate()
waitfor delay '000:00:02'
select @.now = getdate()
select datediff(millisecond, @.then, @.now)

Let us know if this answers your question and works for you.

Clifford Dibble
Program Manager, SQL Server

|||Thanks a lot for your response: I have a procedure which stores the dbms_utility.get_time into a localvariable and passes this variable to another procedure. For eg:
timevar number;
timevar := dbms_utility.get_time;
myproc(timevar);

any equivalent syntax will be useful.|||As far as I know, there is nothing directly equivalent to dbms_utility.get_timedbms_utility.getime in T-SQL. You will need to synthesize it using the technique shown in the prior post or you will need to cast the datetime bits using an expression like this:

select cast(cast(getdate() as binary(8)) as bigint)

Regards,
Clifford Dibble
Program Manager, SQL Server

No comments:

Post a Comment