簡體   English   中英

ORACLE-如何將另一個select語句的結果插入表中,但要進行修改

[英]ORACLE - How to insert into a table from result of another select statement but with modifications

我需要將記錄從同一表上的select語句的輸出插入表中,但需要進行一些修改,以便不違反約束。 這是我嘗試過的

--MyTable as three columns C1,C2,C3

Insert into MyTable
(C1, C2, C3)
values
(
  Select 'New Value', C2, C3
  from
 (
   Select C1,C2,C3 from MyTable
 )
)

但是我得到這個錯誤

SQL Error: ORA-00936: missing expression
00936. 00000 -  "missing expression"
*Cause:    
*Action:

兩個內部的select語句可以正常工作,但不能正常工作。

僅用一個sql語句就能做到這一點嗎?

刪除values關鍵字,然后使用

Insert into MyTable
Select 'New Value', C2, C3
  From MyTable

因為選擇列表中的列數等於表的列數,所以在insert into Mytable部分中無需在表名之后列出列名

只需做:

Insert into MyTable (C1, C2, C3)
  Select 'New Value', C2, C3
  from MyTable;

values和子查詢不是必需的。

暫無
暫無

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

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