August 3, 2017 at 12:21 pm
Hello all,
I have a SQL function that I'm trying to convert to Oracle and am having a tough time figuring out some of the SQL code to begin with. This is the function:
(RIGHT('0' + LTRIM(STR(@Time/3600)),2) + RIGHT('0' + LTRIM(STR((@Time%3600)/60)),2))
The function takes a number value (which is actually number of seconds after midnight) and converts it to a time that all of us can understand. It's the %3600 that is confusing me. As far as I know the % is a wildcard but I don't see how it works in this calculation. I don't understand how/what the second "RIGHT" statement (with the %) is doing (which makes it difficult to try to reconstruct in Oracle).
Can anyone explain what that part is doing so I can find Oracle code to do the same thing?
Any help would be much appreciated!
Thanks
August 3, 2017 at 12:35 pm
it's the Modulus operator
0 / 3 = 3 (integer returned, as 3 goes into ten three times, with one left over
10 % 3 returns 1(the remainder)
in oracle i believe it is 10 MOD 3
Lowell
August 3, 2017 at 12:55 pm
Wouldn't it be easier to just use the function designed specifically for this purpose?
SELECT CAST(DATEADD(SECOND, @time, '00:00') AS TIME(0))
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
August 3, 2017 at 1:29 pm
Thanks everyone. I didn't know the name of the operator, but ended up figuring out that it did something with the remainder as well. Good to know the actual name!
And I also figured out an Oracle translation, if anyone is interested:
to_char( trunc(sysdate) + numtodsinterval(E.Time, 'second') ,'hh24:mi:ss' ) AS Time
Again, thanks to both Drew and Lowell!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply