問題描述
我正在嘗試使用 FETCH FIRST 1 ROW 在 SQL 中創(chuàng)建一個(gè) UNION ALL 語句,但是當(dāng)我這樣做時(shí),它給了我一個(gè)錯(cuò)誤 MISSING KEYWORD
I'm trying to create a UNION ALL statement in SQL using the FETCH FIRST 1 ROW however when I do that it gives me an error MISSING KEYWORD
這是我的 SQL 的樣子:
Here's what my SQL looks like:
Select * From tabl1 where Date = '04-MAR-2020' FETCH FIRST 1 ROW
UNION ALL
Select * From tabl1 where Date = '05-MAR-2020' FETCH FIRST 1 ROW
是這樣可行的.我希望將其保留為單個(gè)語句,而不是添加 SUBQUERY 或任何此類性質(zhì)的內(nèi)容.
is something like this doable. I would like to keep this as a single statement rather than adding a SUBQUERY or anything of that nature.
推薦答案
只需將每個(gè)部分放在括號(hào)中即可.無論如何都可以在 12.2 中使用:
Just put the each part in parentheses. Works in 12.2, anyway:
( Select * From tabl1 where Date = '04-MAR-2020' FETCH FIRST 1 ROW )
UNION ALL
( Select * From tabl1 where Date = '05-MAR-2020' FETCH FIRST 1 ROW )
我的實(shí)際測試查詢,對(duì)于任何感興趣的人是這樣的:
My actual test query, for anyone interested was this:
(select object_name
from user_objects
where object_type = 'TABLE'
order by object_name
fetch first 1 row only)
UNION ALL
(select object_name
from user_objects
where object_type = 'VIEW'
order by object_name
fetch first 1 row only);
這篇關(guān)于Oracle FETCH FIRST 1 ROW with UNION ALL 語句的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!