如原表中有如下数据:
emp表中有如下数据,其中要将empno为7369的empno和ename插入到test表中。
可以用如下语句:
1
2
insert into test (id,name) select empno,ename from emp where empno=7369
commit
结果如下,其中红框部分为新加的数据:
insert into emp2 (empno,ename,job,sal,comm,deptno,flag,loc,hiredate)select a.empno,a.ename,a.job,a.sal,
case when a.comm between 0 and 1000 then comm+100 end
case when comm>1000 and comm<2000 then comm+200 end
case when comm>=2000 then comm+300 end,
a.deptno,b.flag,b.loc,a.hiredate from emp1
where a,dept1 b where a.deptno=b.deptno
貌似也用不着存储过程,前边直接加个begin,后边加个end就是存储过程了
create table emp(
id number(10) unique not null,
name varchar2(10) unique not null,
sex varchar2(2) not null check (sex in('男','女')),
job varchar2(20),
joindate date,
salary number(20),
dept varchar2(20),
constraint PK_EMP primary key(id,name)
)
insert into emp values
(1,'陈冠希','男','电影','2000-09-09',10000,'英皇')
select id,name
from emp
where name is like 'J%' and (salary>500 or job='MANAGER')
select dept,count(id)
from emp
group by dept
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)