时间:2021-07-01 10:21:17 帮助过:4人阅读
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);
SQL> select * from sales_source_data; EMPLOYEE_ID WEEK_ID SALES_MON SALES_TUE SALES_WED SALES_THUR SALES_FRI ----------- ------- ---------- ---------- ---------- ---------- ---------- 176 6 2000.00 3000.00 4000.00 5000.00 6000.00
create table sales_info ( employee_id number(6), week number(2), sales number(8,2) );看上面的表结构,现在将要sales_source_data表中的数据转换到sales_info表中,这种情况就需要使用旋转Insert 示例如下:
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;
SQL> select * from sales_infor; EMPLYEE_ID WEEK SALES ---------- ---- ---------- 176 6 2000.00 176 6 3000.00 176 6 4000.00 176 6 5000.00 176 6 6000.00 SQL>从该例子可以看出,所谓旋转Insert是无条件 insert all 的一种特殊应用,但这种应用被oracle官方,赋予了一个pivoting insert的名称,即旋转insert 《FROM:http://www.cnblogs.com/einyboy/archive/2012/08/06/2624886.html》
Oracle 中的Pivoting Insert用法
标签: