oracle同时向多表插入数据
单表插入以insert into开头,不能有then into语句.
多表插入以insert first/all 开头,可以有then into语句
在Oracle操作过程中经常会遇到同时向多个不同的表插入数据,此时用该语句就非常合适。
All表示非短路运算,即满足了第一个条件也得向下执行查看是否满足其它条件,而First是短路运算找到合适条件就不向下进行。
INSERT ALL
WHEN prod_category=’B’ THEN
INTO book_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
WHEN prod_category=’V’ THEN
INTO video_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
WHEN prod_category=’A’ THEN
INTO audio_sales(prod_id,cust_id,qty_sold,amt_sold)
VALUES(product_id,customer_id,sale_qty,sale_price)
SELECT prod_category ,product_id ,customer_id ,sale_qty
,sale_price
from sales_detail;
Merging Rows into a Table
MERGE INTO oe.product_information pi
USING (SELECT product_id, list_price, min_price
from new_prices) NP
ON (pi.product_id = np.product_id)
WHEN MATCHED THEN UPDATE SET pi.list_price =np.list_price
,pi.min_price = np.min_price
WHEN NOT MATCHED THEN INSERT (pi.product_id,pi.category_id
,pi.list_price,pi.min_price)
VALUES (np.product_id, 33,np.list_price, np.min_price);
相关文档:
oracle表空间操作详解
1
2
3作者: 来源: 更新日期:2006-01-04
5
6
7建立表空间
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
Mysql,SqlServer,Oracle主键自动增长的设置
1、把主键定义为自动增长标识符类型
在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create table customers(id int auto_increment primary key not null, name varchar(15));
insert into customers(name) values("name1"),("nam ......
Oracle 用户及角色 介绍 收藏
一. 用户管理
1.1 建立用户(数据库验证)
CREATE USER DAVE IDENTIFIED BY pwd
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp ......
create table test1 as select 1 id,'create table test2(id number,name varchar2(200));insert into test2 values(1,''a'');' sqltext from dual
2 union all select 2,'truncate table test2;' from dual
3 union all select 3,'insert into test2 select rownum,dbms_random.string(''l'', ......