oracle insert into 脚本怎么写?

 我来答
欧阳宇轩yk3wR
推荐于2019-08-11 · TA获得超过1.4万个赞
知道小有建树答主
回答量:111
采纳率:100%
帮助的人:4万
展开全部

INSERT INTO BOOK(bookid,name,price)  VALUES('100123','oracle ',54);

或者

INSERT INTO tablename(bookid,name,price)

SELECT '100123','oracle,54 FROM DUAL;

总结下Oracle 中的Insert用法

1.标准Insert --单表单行插入

语法:

INSERT INTO table [(column1,column2,...)] VALUE (value1,value2,...) 

例子:  

insert into dep (dep_id,dep_name) values(1,'技术部'); 

2, 无条件 Insert all --多表多行插入

语法:

INSERT [ALL] [condition_insert_clause]

[insert_into_clause values_clause] (subquery) 

示例:

INSERT ALL

INTO sal_history(emp_id,hire_date,salary) values (empid,hiredate,sal)

INTO mgr_history(emp_id,manager_id,salary) values (empid,hiredate,sal)

SELECT employee_id empid,hire_date hiredate,salary sal,manager_id mgr

FROM employees

WHERE employee_id>200; 

3,有条件的Insert

语法:

INSERT [ALL | FIRST]

WHEN condition THEN insert_into_clause values_clause

[WHEN condition THEN] [insert_into_clause values_clause]

......

[ELSE] [insert_into_clause values_clause] 

Subquery; 

示例:

Insert All

when id>5 then into z_test1(id, name) values(id,name)

when id<>2 then into z_test2(id) values(id)

else into z_test3 values(name)

select id,name from z_test; 

4, 旋转Insert (pivoting insert) 

create table sales_source_data (

employee_id number(6),

week_id number(2),

sales_mon number(8,2),

sales_tue number(8,2),

sales_wed number(8,2),

sales_thur number(8,2),

sales_fri number(8,2)

);

insert into sales_source_data values (176,6,2000,3000,4000,5000,6000); 

create table sales_info (

employee_id number(6),

week number(2),

sales number(8,2)

);

示例如下:

insert all

into sales_info values(employee_id,week_id,sales_mon)

into sales_info values(employee_id,week_id,sales_tue)

into sales_info values(employee_id,week_id,sales_wed)

into sales_info values(employee_id,week_id,sales_thur)

into sales_info values(employee_id,week_id,sales_fri)

select employee_id,week_id,sales_mon,sales_tue,

sales_wed,sales_thur,sales_fri

from sales_source_data;

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式