Oracle in SELECT into and insert into ... Select Difference

Source: Internet
Author: User

In Oracle, data from one table is copied to another object. There are usually two ways of doing this: INSERT into select and select into from.

The former can copy a select of n rows (0 to any number) result set into a new table, which can only copy the "one row" result into a variable. Let's say, select INTO is an assignment statement for 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 one as the target table.

Create TableT_source (ID Number Primary Key, TestNamevarchar2( -), Createtime date, flagvarchar2(Ten)   ); Create TableT_target (ID Number Primary Key, TestNamevarchar2( -), Createtime date, flagvarchar2(Ten)   );  

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 INSERT INTO Select operation

Insert  into Select *  from where id=1;    Commit

Test the SELECT INTO operation
Because select INTO is a copy statement in a Plsql language, the same as: = The target of the implementation.

Create or Replace procedureSp_sync_test isAAvarchar2( -); V_record T_source%RowType; begin    SelectT1.testname intoAa fromT_source T1whereId= 1; Dbms_output.put_line ('Common variable t1.testname=' ||AA); SelectT1.*  intoV_record fromT_source T1whereId= 1; Dbms_output.put_line ('record variable t1.testname=' ||v_record.testname); End; 

The variables of the primitive type and the record type are added here for easy understanding.

Oracle in SELECT into and insert into ... Select Difference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.