![](/img/trans.png)
[英]Java code to insert data into a table by retrieving the result from another query
[英]How to insert rows dynamically from a select query to another table in java?
我有一個選擇查詢(使用准備好的語句),它返回一個結果集。 例如,查詢可以是:
SELECT * FROM TABLE;
而且我想將此查詢的結果插入到另一個表中,將選擇查詢存儲在數據庫中,並且通常將是一個聯接查詢,所以我不知道表的確切列,它對於每一行的可能性結果集以以下形式插入行:
INSERT INTO TABLE VALUES ('THE VALUES FROM THE SELECTED ROW IN THE RESULTSET');
您可以在一個陳述中同時做這兩個事情:
insert into TableB (Col1, col2, col3, col4, etc..)
select Col1, col2, col3, col4, etc.. from Table A where Col5='condition'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.