簡體   English   中英

如何在 SQL 中結合 WITH 語句和 INSERT INTO

[英]how to combine a WITH statement and an INSERT INTO in SQL

我有一個帶有 with 子句的 sql 語句,我想將結果寫入帶有插入的表中。 我嘗試過的 with 和 insert into 的任何組合都會給我一條錯誤消息。 我想做的最小例子:

create table temp as (quarter decimal(5));

insert into temp (
with bla as (select 2021 as year from dummy)
select 10*year + 1 as quarter from bla
) 

將 with 語句放在 insert into 之外也不起作用。

對於 Oracle,您需要以下語法:

insert into temp (quarter)
with bla (year) as (
  select 2021 as year from dual
)
select 10*year + 1 as quarter from bla;

你的CREATE TABLE語句應該是:

create table temp (quarter decimal(5));

db<> 在這里擺弄

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM