日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle中insert into select和select into的区别

發布時間:2025/3/11 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle中insert into select和select into的区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章轉自:http://www.linuxidc.com/Linux/2012-09/70984.htm

在Oracle中,將一張表的數據復制到另外一個對象中。通常會有這兩種方法:insert into select ?和 select into from。


前者可以將select 出來的N行(0到任意數)結果集復制一個新表中,后者只能將"一行"結果復制到一個變量中。這樣說吧,select into是PL/SQL language 的賦值語句。而前者是標準的SQL語句。

做一個簡單測試,我們就可以很容易地看出兩者的差別。

首先,我們創建兩個表,一個作為源表,一個作為目標表。

create table t_source( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) ); create table t_target( id number primary key, testname varchar2(20), createtime date, flag varchar2(10) );
接著,插入測試數據

insert into t_source values(1,'測試數據1....1',sysdate-2,'N'); insert into t_source values(2,'測試數據1....2',sysdate-2,'N'); insert into t_source values(3,'測試數據1....3',sysdate-2,'N'); commit;
測試insert into select 操作

insert into test2 select * from t_source where id=1; commit;
測試select into 操作
因為select into是一個plsql語言中的復制語句,和:=實現的目標一樣。

create or replace procedure sp_sync_test is aa varchar2(100); v_record t_source%rowtype; begin select t1.testname into aa from t_source t1 where id = 1; dbms_output.put_line('普通變量 t1.testname= ' || aa); select t1.* into v_record from t_source t1 where id = 1; dbms_output.put_line('記錄變量 t1.testname= ' || v_record.testname); end;

這里增加了原始類型的變量和記錄類型的變量,便于大家理解。


注:最后加一點,如果想創建一個和已經存在的表相同的表,可以使用如下方法:

create table test as?select * from emp;


//清除數據
truncate table test;

總結

以上是生活随笔為你收集整理的Oracle中insert into select和select into的区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。