In Oracle, copy the data of a table to another object. Usually there are two methods: insert into select and select into from.
The former can copy N rows (0 to any number) from the select statement to a new table, and the latter can only copy the "one row" result to a variable. In this case, select into is a value assignment statement of PL/SQL language. The former is a standard SQL statement.
By doing a simple test, we can easily see the difference between the two.
First, we create two tables, one as the source table and the other as the target table.
- Create TableT_source (
- Id numberPrimary Key,
- Testname varchar2 (20 ),
- CreatetimeDate,
- Flag varchar2 (10)
- );
- Create TableT_target (
- Id numberPrimary Key,
- Testname varchar2 (20 ),
- CreatetimeDate,
- Flag varchar2 (10)
- );
Next, insert the test data.
- Insert IntoT_sourceValues(1,'Test data 1... 1', Sysdate-2,'N');
- Insert IntoT_sourceValues(2,'Test data 1... 2', Sysdate-2,'N');
- Insert IntoT_sourceValues(3,'Test data 1... 3', Sysdate-2,'N');
- Commit;
Test the insert into select operation.
- Insert IntoTest2Select*FromT_sourceWhereId = 1;
- Commit;
Test the select into operation.
Because select into is a copy statement in plsql, it is the same as: =.
- Create Or Replace ProcedureSp_sync_testIs
- Aa varchar2 (100 );
- V_record t_source % rowtype;
- Begin
- SelectT1.testnameIntoAaFromT_source t1WhereId = 1;
- Dbms_output.put_line ('Normal variable t1.testname ='| Aa );
- SelectT1 .*IntoV_recordFromT_source t1WhereId = 1;
- Dbms_output.put_line ('Record variable t1.testname ='| V_record.testname );
- End;
The original type variables and record type variables are added for your understanding.