如何将一个小查询从SQL Server转换为Oracle,我不知道如何将其等效物应用于保留的词语中?
我一直与SQL Server合作,现在我想学习Oracle,如何将此小查询从SQL Server转换为Oracle?
我在此查询中有错误:
with cte as, OFFSET @start ROWS FETCH ,
and exists(select 1 from cte where cte.id_city = h.id_city),
(dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to)
我不知道Oracle等效物是什么。
这是我的完整查询
CREATE OR REPLACE
PACKAGE PKG_HOME AS
CREATE PROCEDURE SP_HOME_DATA (
from in timestamp,
to in timestamp,
start number,
page number
)
AS
BEGIN
with cte as (
select isnull(h.id_city,'') as id_city
from main_bdd.home h
left join second_bdd.owner.clients cl on cl.idHome = h.idHome
where ((dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to))
order by h.datehome asc
OFFSET @start ROWS FETCH NEXT @page ROWS ONLY
)
select
isnull(h.id_city,'') as id_city
isnull(h.last_ubication,'') as last_ubication
from main_bdd.home h
left join second_bdd.owner.clients cl on cl.idHome = h.idHome
where ((dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to))
AND exists(select 1 from cte where cte.id_city = h.id_city)
order by h.datehome asc
END;
END PKG_HOME;
I have always worked with SQL Server and now I want to learn Oracle, how can I convert this little query from SQL Server to Oracle?
I have errors in this query:
with cte as, OFFSET @start ROWS FETCH ,
and exists(select 1 from cte where cte.id_city = h.id_city),
(dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to)
I don't know what the Oracle equivalent will be.
This is my full query
CREATE OR REPLACE
PACKAGE PKG_HOME AS
CREATE PROCEDURE SP_HOME_DATA (
from in timestamp,
to in timestamp,
start number,
page number
)
AS
BEGIN
with cte as (
select isnull(h.id_city,'') as id_city
from main_bdd.home h
left join second_bdd.owner.clients cl on cl.idHome = h.idHome
where ((dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to))
order by h.datehome asc
OFFSET @start ROWS FETCH NEXT @page ROWS ONLY
)
select
isnull(h.id_city,'') as id_city
isnull(h.last_ubication,'') as last_ubication
from main_bdd.home h
left join second_bdd.owner.clients cl on cl.idHome = h.idHome
where ((dateadd(second, h.days, h.datehome) >= @from and dateadd(second, h.days, h.datehome) <= @to))
AND exists(select 1 from cte where cte.id_city = h.id_city)
order by h.datehome asc
END;
END PKG_HOME;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要类似的东西(尽管
second_bdd.owner.clients
看起来不错,因为它应该为schema_name.table_name
schema_name.table_name.something_else_else_else ):注意:在Oracle
'''
和null
是相同的代码> ISNULL 函数)与value
没有任何包装功能。db&lt;&gt; fiddle
You want something like (although
second_bdd.owner.clients
looks wrong as it should beschema_name.table_name
and notschema_name.table_name.something_else
):Note: In Oracle
''
andNULL
are identical so usingCOALESCE(value, '')
(the Oracle equivalent of theISNULL
function) is identical tovalue
without any wrapped function.db<>fiddle here