oracle中insert如何帶條件新增資料

2022-03-07 11:25:35 字數 2367 閱讀 7670

1樓:李鵬飛

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 【數值常量】

【希望可以幫到你】

2樓:匿名使用者

insert into tablea (列1,列2,『 』)

加個空格不行嗎?

3樓:匿名使用者

那把列3隨便賦個值就行了

oracle中insert語句怎麼嵌入select

4樓:龍氏風采

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

這裡增加了原始型別的變數和記錄型別的變數

oracle中如何用一條insert into 語句插入多條資料 如: insert into 表 values(多條資料)????????

5樓:匿名使用者

insert into tablea select xx from tableb

select xx from tableb返回的記錄為幾條就插入幾條

6樓:匿名使用者

insert into 表 values(多條資料)???????? 這種方式只能插入一條,要想插入多條就要用

insert into tablea select xx from tableb where 條件,通過條件來控制插入的記錄個數

7樓:

沒有這樣的insert語句,這屬於資料匯入的操作了。即使有這樣的sql語句,效率也是非常低的。

8樓:

那是不可能滴,oracle應該不會支援這樣的,你可以先把這些資料匯入excel表然後再匯入

如何改變oracle中select的結果的預設順序(不加order by)

刪除掉原記錄,bai重新du插入,通常顯示的zhi位置會後移。這要看b前面是dao否有可用的塊,內如果有重新插入的容記錄仍然在b的前面,可以通過插入足夠數量的記錄將b前面的可用塊佔用,然後就會出現在b的後面。如果不考慮開銷,也可以將a刪除後重建表,最後插入a。一個可以重複出現的例子 create t...

access資料庫sql中insert語句中value某個引數用

按如下方式獲得 如,access庫中有以下兩張表 現要將測試表1的資料追加到測試表中內,其中測試表1的name列為引數,age為固容定值20,需要select獲得。可用如下語句 insert into 測試表 name,age select name,20 from 測試表1 追加後的結果 多寫一點...

oracle中如何求百分比

實現 elect case when db psndoc.age 30 then 30歲以上 when db psndoc.age 30 then 30歲及以下 end ranges,count rs 100 round count sum count over 4 percent from bd ...