oracle 中select into是什么意思
這是一個復制表數據的操作。
創建aaa表,這里沒有定義aaa表的字段以及類型,而是用select * from bbb,這就是把bbb里面所有的字段包含類型以及數據都復制到aaa中去。那么就創建了一張和bbb表一樣的aaa表。包括數據等都一樣。只是不包含bbb表中的主鍵以及約束等。
這個地方是不能使用select into來完成的。
select into 是SQLSERVER的語法:同樣的效果select * into aaa from bbb
oracle 中SQL 語句開發語法 SELECT INTO含義
和sqlserver的不一樣
sqlserver或者access中select into 是通過查詢數據來建表
oracle中,這個select into不能在語句中執行,必須要放到存儲過程,函數等等里邊執行
譬如select to_char(sysdate,'yyyy-mm-dd') into v_date from dual;
這個v_date是用來放變量的,在后續的過程中來調用這個變量
但是這個一次只能放一個值,如果值過多的話需要用到游標
你說的非維護語法是啥意思啊?你要有不懂的可以繼續問,但是資料的確不多,都是自己寫的被我放論壇上了
Oracle中insert into select和select into的區別
insert into select可以將select 出來的N行(0到任意數)結果集復制一個新表中,select into
from只能將"一行"結果復制到一個變量中。這樣說吧,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 *me into aa from t_source t1 where id = 1;
dbms_*_line('普通變量 *me= ' || aa);
select t1.* into v_record from t_source t1 where id = 1;
dbms_*_line('記錄變量 *me= ' || v_*me);
end;
這里增加了原始類型的變量和記錄類型的變量
oracle語句insert into select如何加后續插入條件
oracle中有批量插入語句insert into tableA (列1,列2,列3) select 列1,列2 from tableB。現在問題是這樣的,tableA有3列,而通過最后的select語句所能獲得的列只有列1和列2。但列3是非空的,所以插入時必須填寫。
A中有3例,B表中你只能獲得2列,可以用常量占位解決
insert into tableA (列1,列2,列3) select 列1,列2,常量 from tableB
例:如下
insert into tableA (列1,列2,列3) select 列1,列2,'123' from tableB 【字符串常量】
insert into tableA (列1,列2,列3) select 列1,列2,123 from tableB 【數值常量】
轉載請注明出處華閱文章網 » oracle中into語句