oracleÖÐinsert into selectÓ÷¨
insert into select Óï¾äÓÃÓÚ½«Ò»¸ö±íÖеÄÊý¾Ý²åÈëµ½ÁíÒ»¸ö±í¡£ËüÖ§³Ö²åÈëËùÓÐÁлòÌض¨ÁУ¬²¢¿ÉÒÔͨ¹ý where ×Ó¾äʹÓÃÌõ¼þ¾ÙÐÐɸѡ¡£Í¨¹ýÖ¸¶¨Ä¿µÄ±í¡¢ÁÐÁбíºÍÔ´±í£¬¿ÉÇáËɵشÓÒ»¸ö±í½«Êý¾ÝתÒƵ½ÁíÒ»¸ö±í¡£
Oracle ÖÐµÄ INSERT INTO SELECT Ó÷¨
¼ÄÒ壺
INSERT INTO SELECT Óï¾ä½«Ò»¸ö±íÖеÄÊý¾Ý²åÈëµ½ÁíÒ»¸ö±íÖС£
Óï·¨£º
INSERT INTO SELECT FROM [WHERE ]
µÇ¼ºó¸´ÖÆ
²ÎÊý£º
£ºÒª²åÈëÊý¾ÝµÄÄ¿µÄ±í¡£
£ºÒª²åÈëµÄÁУ¬¿ÉÒÔÖ¸¶¨ËùÓÐÁлòÌض¨ÁС£
£ºÒª´ÓÆä»ñÈ¡Êý¾ÝµÄÔ´±í¡£
[WHERE ]£º¿ÉÑ¡µÄÌõ¼þ£¬ÓÃÓÚ¹ýÂËÔ´±íÖеÄÊý¾Ý¡£
Ó÷¨£º
²åÈëËùÓÐÁУº
ÈôÊÇ ÁÐÁбí ÖÐûÓÐÖ¸¶¨ÁУ¬Ôò»á²åÈëÔ´±íÖеÄËùÓÐÁС£
INSERT INTO target_table SELECT * FROM source_table;
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
²åÈëÌض¨ÁУº
ÈôÊÇ ÁÐÁбí ÖÐÖ¸¶¨ÁËÌض¨ÁУ¬ÔòÖ»²åÈëÖ¸¶¨µÄÁС£
INSERT INTO target_table (col1, col2) SELECT col1, col2 FROM source_table;
µÇ¼ºó¸´ÖÆ
ʹÓÃÌõ¼þ£º
WHERE ×Ó¾ä¿ÉÓÃÓÚ¹ýÂËÔ´±íÖеÄÊý¾Ý£¬Ö»²åÈëÖª×ãÌõ¼þµÄÐС£
INSERT INTO target_table SELECT * FROM source_table WHERE column_name > 10;
µÇ¼ºó¸´ÖÆ
ʾÀý£º
¼ÙÉèÎÒÃÇÓÐÒÔÏÂÁ½¸ö±í£º
source_table: +----+----------+ | id | name | +----+----------+ | 1 | John Doe | | 2 | Jane Smith | | 3 | Mary Jones | +----+----------+ target_table: +----+----------+ | id | name | +----+----------+ | 4 | Bob Smith | | 5 | Sue Brown | +----+----------+
µÇ¼ºó¸´ÖÆ
Òª´Ó source_table ÖвåÈëËùÓÐÐе½ target_table ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÅÌÎÊ£º
INSERT INTO target_table SELECT * FROM source_table;
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
²åÈëºó£¬target_table ½«ÈçÏÂËùʾ£º
+----+----------+ | id | name | +----+----------+ | 4 | Bob Smith | | 5 | Sue Brown | | 1 | John Doe | | 2 | Jane Smith | | 3 | Mary Jones | +----+----------+
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇoracleÖÐinsert into selectÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡