Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

help to convert sql server query to oracle

637490May 5 2008 — edited May 5 2008
There are 2 tables:
table1 with columns t1,t2,t3,latency
table2 with columns filename, time1,time2,time3

Query on sql server:
insert into table1(t1,t2,t3,latency)
select
time1,
time2,
time3,
abs(case when (time2-time3 ) <0 then

case when isdate(dbo.to_date(substring(filename,len(filename)-charindex
('!',Reverse(filename),1)+2,14))=1 then
cast(datediff(second,dbo.to_date(substring(filename,len(filename)-charindex
('!',Reverse(filename),1)+2,14)),'YYYY- MM-DD HH:MI:SS'),time2)/60 as float)
else
cast(datediff(second,time1,time2)/60 as float)
end

else

cast(datediff(second,time3,time2)/60 as float)
end)
latency
from table2


I converted it like this on oracle:
insert into table1(t1,t2,t3,latency)
select
time1,
time2,
time3,
(if(time2-time3 < 0)
then
select reverse(filename) into revname from dual;
select to_date(substr(filename,length(filename)-instr(revname,'!')+2,14),'YYYYMMDDHH24MISS') into arrdate from dual;
(time2-arrdate)*24*60;
exception
when others then
(time2-time1)*24*60;
else
(time2-time3)*24*60;
end if) latency
from table2;

This doesnot work as if-then-else condition inside select statement is giving error.
if I write a function for that, function cannot be called inside query.
Procedure can be called, but it will not return value.

Can anyone please let me know how to convert this query into oracle?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2008
Added on May 5 2008
3 comments
754 views