[英]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.