【发布时间】:2019-01-31 02:40:39
【问题描述】:
我想将数据插入到两个表中。将是一对多的连接。为此,我当然必须使用外键。
我认为,table1 - ID 列是这个主键的理想选择。但我总是用触发器自动生成它,每一行。所以, 如何在同一个插入查询中将 Table1.ID(自动生成,主键)列放入 table2.Fkey 列?
INSERT ALL INTO table1 ( --here (before this) generated the table1.id column automatically with a trigger.
table1.food,
table1.drink,
table1.shoe
) VALUES (
'apple',
'water',
'slippers'
)
INTO table2 (
fkey,
color
) VALUES (
table1.id, -- I would like table2.fkey == table1.id this gave me error
'blue'
) SELECT
*
FROM
table1
INNER JOIN table2 ON table1.id = table2.fkey;
错误信息:
"00904. 00000 - "%s: invalid identifier""
【问题讨论】:
-
可以用序列来创建id吗?
-
错误消息还应显示 Oracle 认为“无效”的标识符。你能找到它并发回(在你的问题底部添加)吗?
标签: oracle join inner-join sql-insert oracle12c