ORACLE如何批量插入(Insert)
ORACLE批量插入(Insert)
Oracle批量插入語句與其他數(shù)據(jù)庫不同,下面列出不同業(yè)務(wù)需求的插入
假設(shè)有一張表Student
-- 學生表 create table Student( id Varchar2(11) primary key, name varchar2(32) not null, sex varchar2(3) not null, age smallint, tel varchar(16) )
注意:
其中[]中代表可選;<>代表必須;table_column的數(shù)量必須和column_value一致,并且數(shù)據(jù)類型要相匹配
1. 單條自定義記錄插入
命令格式:
insert into table <tableName>[(<table_column1>,<table_column2>...)] values([<column_value1>,<column_value2>...])
示例:
insertinto Student(id, name, sex, age, tel) values (‘13', ‘jack', ‘男', 13, ‘13345674567')
2. 多條自定義記錄插入
命令格式1:
insert all into <tableName>[(<table_column1>,<table_column2>...)] values([<column_value1>,<column_value2>...]) [into <tableName>[(<table_column1>,<table_column2>...)] values([<column_value1>,<column_value2>...])]... select <table_value1>[,<table_value2>...] from dual;
示例:
insert all into Student(id, name, sex, age, tel) into Student(id, name, sex, age, tel) values ('12', 'jack1', '男', 12, '13345674567' ) into Student(id, name, sex, age, tel) values ('13', 'jack2', '男', 13, '13345674567') select '14', 'jack', '男', 13, '13345674567' from dual;
注意: 我也不知道為什么要加select from dual語句,反正不加就報錯
命令格式2:
insert into <tableName>[(<table_column1>,<table_column2>...)] select [<column_value1>,<column_value2>...] from dual [ union select [<column_value1>,<column_value2>...] from dual ]...
示例:
insert into student(id, name, sex, age, tel) select '10' , 'ldh', '男', 19, '14445674567' from dual union select '11' , 'zxy', '男', 20, '13333674567' from dual union select '12', 'zxc', '男', 21, '15555674567' from dual
命令格式3:
insert into <tableName1>[(<table_column1>,<table_column2>...)] select [<column_value1>,<column_value2>...] from <tableName2> [where [...]] union [ select [<column_value1>,<column_value2>...] from <tableName2> [where [...] ]]
示例:
insert into student(id, name, sex, age, tel) select (id-1)||'' as id, name, sex, age, tel from Student where id='11' union select id||'1' as id, name, sex, age, tel from Student where id like '1%' union select id||'2' as id, name, sex, age, tel from Student where id like '%1' and id/3 != 0
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
PL/SQL遠程備份和恢復(fù)Oracle數(shù)據(jù)庫
這篇文章主要為大家詳細介紹了PL/SQL遠程備份和恢復(fù)Oracle數(shù)據(jù)庫的具體方法,感興趣的小伙伴們可以參考一下2016-09-09Oracle數(shù)據(jù)庫及圖形化界面安裝教程圖解
本文通過圖文并茂的形式給大家介紹了Oracle數(shù)據(jù)庫及圖形化界面安裝教程,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2018-08-08Oracle 子程序參數(shù)模式,IN,OUT,NOCOPY
Oracle 子程序參數(shù)模式主要有IN,OUT,NOCOPY,IN和OUT可以組合,OUT和NOCOPY也可以組合使用.2009-10-10Oracle存儲過程和存儲函數(shù)創(chuàng)建方法(詳解)
下面小編就為大家?guī)硪黄狾racle存儲過程和存儲函數(shù)創(chuàng)建方法(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06