Oracle SQL 插入多行并返回一些内容
在 Oracle 中,可以通过执行类似查询来插入多行
INSERT ALL
INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;
,并且使用准备好的语句,执行像这样的单个插入
BEGIN INSERT
INTO mytable (column1, column2, column3) VALUES (null, 'val1.2', 'val1.3')
RETURNING column1 INTO ?; END;
将导致返回column1
的值(假设有一个触发器分配一个值插入之前)。
如果可能的话,有没有办法将两者结合起来?意思是,插入多个值,同时仍然通过单个查询返回所有 column1
值(结果集)?
In Oracle, one can insert multiple rows by doing a query like
INSERT ALL
INTO mytable (column1, column2, column3) VALUES ('val1.1', 'val1.2', 'val1.3')
INTO mytable (column1, column2, column3) VALUES ('val2.1', 'val2.2', 'val2.3')
INTO mytable (column1, column2, column3) VALUES ('val3.1', 'val3.2', 'val3.3')
SELECT * FROM dual;
And with a prepared statement, doing a single insert like this one
BEGIN INSERT
INTO mytable (column1, column2, column3) VALUES (null, 'val1.2', 'val1.3')
RETURNING column1 INTO ?; END;
will result in returning column1
's value (supposing there is a trigger assigning a value to it before insert).
Is there a way, if possible at all, to combine both? Meaning, inserting multiple values while still returning all the column1
values (a resultset) with a single query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 文档(至少通过21c版本),返回子句的限制之一:
From the documentation (at least through the 21c version), one of the restrictions to the returning clause: