oracle9i中insert 语句新增特性
1、无条件insert all 语法示例(将查询出的数据全部插入到指定的表格中):
insert all
into emp_name(emp_id,lastname,firstname) values
(employeeid,lastname,firstname)
into emp_addr(emp_id,address)values (employeeid,
address)
select employeeid,lastname,firstname,address
from employees where employeeid>3
2、有条件insert all语法示例( sal >10000 可以换成其他的条件例如like 子句)
insert all
when sal>10000 then
insert into history_sal values(empid,hireadate,sal)
when sal >200 then
insert into mgr_history values (empid,mgr,sal)
select employeeid empid,hire_date hiredate,salary sal,
manager_id mgr
from employees
where employee_id>200;
3、有条件的insert first语句表示首先校验第一个条件(first)如果第
一个条件满足,其它条件就不再进行判定和执行,如果第一个条件不满足
就进入一个多条件when的判定的条件中。例如:
insert first
when sal >25000 then
into special_sal values (deptid,sal)
when hiredate like ('%00%') then
into hiredate_history_00 values (deptid,hiredate)
when hiredate like '%99%' then
into hiredate_history_99 values (deptid,hiredate)
else
into hiredate_history values (deptid,hiredate)
select department_id deptid,sum(salary) sal ,
max(hire_date ) hiredate
from employees
group by department_id ;
建立外部扩展表,即使用外部文件的数据作为数据表中的数据,实际查询的结果
是外部文件的数据内容
1、建立数据文件的目录
create directory emp_dir as 'flat_files';
2、根据文件建立数据表的结构
create table oldemp
(empno,number,empname char(200),birthdate date)
organization external
(type oracle_loader
default dircetory emp_dir
access parameters
(records delimited by newline
badfile 'bad_emp'
logfile 'log_emp'
fields terminated by ','
(empno char,
empname char ,
birthdate char date format date mask 'dd-mon-yyyy'))
location ('emp1.txt')
parallel 5
reject limit 200;
3、可以使用select * from oldemp进行读取数据了
关联更新语句
update test2 set address =(select '2' from test1 where test1.name=test2.name and
test1.xh='1005') where test2.xh ='1005';