ORACLE如何批量插入(Insert)
ORACLE批量插入(Insert)
Oracle批量插入語句與其他數(shù)據(jù)庫不同,下面列出不同業(yè)務(wù)需求的插入
假設(shè)有一張表Student
-- 學(xué)生表 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語句,反正不加就報(bào)錯(cuò)
命令格式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é)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Oracle數(shù)據(jù)庫安裝教程并實(shí)現(xiàn)公網(wǎng)遠(yuǎn)程連接(內(nèi)網(wǎng)穿透)
Oracle數(shù)據(jù)庫是用于處理數(shù)據(jù)存儲及大量數(shù)據(jù)計(jì)算的常用數(shù)據(jù)庫,下面這篇文章主要給大家介紹了關(guān)于Oracle數(shù)據(jù)庫安裝教程并實(shí)現(xiàn)公網(wǎng)遠(yuǎn)程連接(內(nèi)網(wǎng)穿透)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06
Oracle 數(shù)據(jù)庫中創(chuàng)建合理的數(shù)據(jù)庫索引
在Oracle數(shù)據(jù)庫中,創(chuàng)建索引雖然比較簡單。但是要合理的創(chuàng)建索引則比較困難了。2009-06-06
ORACLE DATAGUARD中手工處理日志v$archive_GAP的方法
從9i以后,oracle dataguard 備庫一般都不需要手工處理丟失的日志,F(xiàn)AL自動(dòng)會(huì)幫我們處理,本文主要通過個(gè)案例來講下手工處理丟失的日志的方法。2014-08-08
Oracle SQL tuning 數(shù)據(jù)庫優(yōu)化步驟分享(圖文教程)
SQL Turning 是Quest公司出品的Quest Central軟件中的一個(gè)工具。Quest Central是一款集成化、圖形化、跨平臺的數(shù)據(jù)庫管理解決方案,可以同時(shí)管理 Oracle、DB2 和 SQL server 數(shù)據(jù)庫2013-08-08
Linux環(huán)境下Oracle數(shù)據(jù)庫重啟詳細(xì)步驟
這篇文章主要給大家介紹了關(guān)于Linux環(huán)境下Oracle數(shù)據(jù)庫重啟的詳細(xì)步驟,oracle在linux下重啟,有多種方式可選擇,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-06-06

