ORACLE 批量插入 Insert 詳解

2021-10-03 16:32:27 字數 2614 閱讀 3639

假設有一張表student

-- 學生表

create table student

( id varchar2(11

) primary key,

name varchar2(32

) not null

, *** varchar2(3

) not null

, age smallint,

tel varchar(16

))

其中中代表可選;<>代表必須;table_column的數量必須和column_value一致,並且資料型別要相匹配

單條自定義記錄插入

命令格式:

insert into table [(

,...)

]values([

,...]

)//示例:insertinto student(id, name, ***, age, tel) values ('13', 'jack', '男', 13, '13345674567')

2.多條自定義記錄插入

命令格式1:

insert all

into [(

,...)

]values([

,...]

)[ into [(

,...)

]values([

,...])]

...select [,

...]

from dual;

//示例:insert all into student(id, name, ***, age, tel)

into student

(id, name, ***, age, tel)

values

('12'

,'jack1'

,'男',12

,'13345674567'

) into student

(id, name, ***, age, tel)

values

('13'

,'jack2'

,'男',13

,'13345674567'

) select '14'

,'jack'

,'男',13

,'13345674567'

from dual;

note: 我也不知道為什麼要加select from dual語句,反正不加就報錯

命令格式2:

insert into [(

,...)

] select [

,...]

from dual

[ union select [

,...]

from dual ]

...//示例:insert into student(id, name, ***, age, tel)

select '24'

,'jack'

,'男',22

,'13345674567'

from dual

union select '25'

,'jack'

,'男',22

,'13345674567'

from dual

union select '26'

,'jack'

,'男',32

,'13345674567'

from dual

3. 資料庫記錄插入

命令格式:

insert into [(

,...)

] select [

,...]

from

[where [

...]

] union [ select [

,...]

from

[where [

...]]]

//示例:insert into student(id, name, ***, age, tel)

select

(id-1)

||''

as id, name, ***, age, tel from student where id=

'11'

union select id||

'1'as id, name, ***, age, tel from student where id like '1%'

union select id||

'2'as id, name, ***, age, tel from student where id like '%1' and id/3!=

0

note:不推薦插入語句不寫名字段,比如

insert into student select *

from student2;

into student values

('12'

,'jack'

,'男',12

,'13345674567'

)

這樣的語句是不推薦的

批量插入資料 Oracle

在使用 oracle 開發期間,或許我們會為編寫一條一條插入語句而困惱,這裡給出 對資料表進行簡單批量插入的例子。以下均是oracle 資料庫操作 insert into cbay user t userid,username,password,userage select test1 test1 ...

oracle批量插入資料

值是可以省略的 插入到表名 列值 後跟乙個查詢語句的話就代表值,簡單的說就是後面select select出來的值就是要插入的值,即 insert into tb 欄位名一,欄位名二 select 欄位名一,欄位名二 from tb 等於insert into tb 欄位名一,欄位名二 values...

oracle實現批量插入

最近專案上需要批量插入資料到oracle當中,這裡總結三個方法 一.帶自增id的形式,注意這邊是沒有values insert into test id,name,age,address select seq test id.nextval id,a.from select from dual a二...