The INSERT INTO SELECT statement is used to insert data from one table into another table. It supports inserting all columns or specific columns and can filter using conditions via WHERE clause. Data can be easily transferred from one table to another by specifying the target table, column list, and source table.
INSERT INTO SELECT usage in Oracle
Meaning:
The INSERT INTO SELECT statement will Data from one table is inserted into another table.
Syntax:
<code>INSERT INTO
SELECT
FROM
[WHERE ]</code>
Parameters:
##:The target table to insert data into.
: The columns to be inserted, you can specify all columns or specific columns.
: The source table from which to obtain data.
[WHERE ]: Optional conditions used to filter data in the source table.
Usage:
Insert all columns:
If
column If no columns are specified in list , all columns in the source table will be inserted.
<code>INSERT INTO target_table
SELECT *
FROM source_table;</code>
Insert specific columns:
If specific columns are specified in the
column list, only the specified columns will be inserted .
<code>INSERT INTO target_table (col1, col2)
SELECT col1, col2
FROM source_table;</code>
Using conditions:
WHERE clause can be used to filter the data in the source table and insert only those that meet the conditions OK.
<code>INSERT INTO target_table
SELECT *
FROM source_table
WHERE column_name > 10;</code>
Example:
Suppose we have the following two tables:
<code>source_table:
+----+----------+
| id | name |
+----+----------+
| 1 | John Doe |
| 2 | Jane Smith |
| 3 | Mary Jones |
+----+----------+
target_table:
+----+----------+
| id | name |
+----+----------+
| 4 | Bob Smith |
| 5 | Sue Brown |
+----+----------+</code>
To be obtained from
source_table To insert all rows into target_table, we can use the following query:
<code>INSERT INTO target_table
SELECT *
FROM source_table;</code>
After insertion,
target_table will look like this:
<code>+----+----------+
| id | name |
+----+----------+
| 4 | Bob Smith |
| 5 | Sue Brown |
| 1 | John Doe |
| 2 | Jane Smith |
| 3 | Mary Jones |
+----+----------+</code>
The above is the detailed content of How to use insert into select in oracle. For more information, please follow other related articles on the PHP Chinese website!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.