當前位置:首頁 » 編程語言 » plsqlselectinto

plsqlselectinto

發布時間: 2023-01-06 12:24:58

A. Oracle中insert into select和select into的區別

Oracle中insert into select和select into的區別:(select into 就相當於賦值語句,insert into是復制語句),在Oracle中,將一張表的數據復制到另外一個對象中。

通常會有這兩種方法:insert into select 和 select into from。前者可以將select 出來的N行(0到任意數)結果集復制一個新表中,後者只能將"一行"結果復制到一個變數中。這樣說吧,select into是PL/sql language 的賦值語句。而前者是標準的SQL語句。

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

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

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)
);

2、接著,插入測試數據;

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 procere 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;

3、這里增加了原始類型的變數和記錄類型的變數,便於大家理解。

B. 小白初學PL/SQL 中關於SELECT INTO的問題如何解答

這就是基本的語法啊,select 。。。into。。。from 就是一個語法格式,沒什麼特別的。
其實你可以這樣考慮。在存儲過程中使用select的目的本身就是查詢數據,既然要查詢出來,那麼肯定是要使用的,要想在過程中使用,就需要藉助載體來獲取到select查出的結果。這就是【變數】。通常有幾種,單純類型的變數,比如varchar2,number等等,還有就是集合,比如record,索引表等等。
殊途同歸,不論使用什麼樣的變數來獲取值,都需要通過select into從資料庫中把想要的只查詢出來,直接賦值或者循環賦值。
至於你說的sql server中沒有這種語法,其實是不對的,sql server不是沒有,只不過是寫法不同罷了。sql server中的語法格式是:select @變數 = 列名 from 表名,其實和oracle的select into都是一個道理,只是寫法形式上不同。
希望對你有幫助。

C. PLSQL中復製表select * into b from a where 11這句話中where 11在這里怎麼理解

首先oracle里不適合你這個語法oracle里復製表的語法是create b as select * from a where 11這里11 代表只復製表結構,而不復制里邊的數據因為11是個false,也就是為假,所以就不復制數據只復製表結構了如果後邊改成1=1...

熱點內容
隨機啟動腳本 發布:2025-07-05 16:10:30 瀏覽:534
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:30
linux485 發布:2025-07-05 14:38:28 瀏覽:310
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:760
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:436
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:722
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:246
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:696
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:288
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:837