在Oracle中,我试图使用下面的代码将CTE的输出插入临时表,但是它给出了错误。我不想提前创建临时表,应该使用CTE中的列名和数据类型动态创建。
with cte as (
select ORDER_ID, STATUS_ID, CALL_DATE, SHIP_DATE,
UPDATE_USER_ID, UPDATE_TIMESTAMP,
row_number() over(partition by ORDER_ID order by update_timestamp desc) as rowno
FROM ORDER_HISTORY
where ORDER_ID in (1001,1002, 1003)
)
create table temp_recent_order as
select * from cte where rowno=1
答案 0 :(得分:3)
只需替换create table
语句的顺序,如下所示:
create table temp_recent_order as
with cte as (
select ORDER_ID,
STATUS_ID,
CALL_DATE,
SHIP_DATE,
UPDATE_USER_ID,
UPDATE_TIMESTAMP,
row_number() over(partition by ORDER_ID order by update_timestamp desc) as rowno
from ORDER_HISTORY
where ORDER_ID in (1001, 1002, 1003)
)
select * from cte where rowno=1;