日期:2014-05-17  浏览次数:20949 次

关于ora-00913错误
三个表的结构:
雇员employee(雇员号empid,姓名empname,年龄age,地址address,薪水sal)
部门department(部门号deptno,部门名dname,部门经理mgr)
工作work(雇员号empid,部门号deptno,在该部门工作的年限worktime)
题目:为财务部门的雇员加薪,3年以下加3%,3年以上加5%(用PL/SQL实现)
SQL代码:
SQL code

/*创建employee表*/
CREATE TABLE employee
(empid NUMBER(8),
 empname VARCHAR2(20),
 age NUMBER(2),
 address VARCHAR2(50),
 sal NUMBER(7)
);
/*创建department表*/
CREATE TABLE department
(deptno NUMBER(8),
 dname VARCHAR2(15),
 mgr VARCHAR2(20)
);
/*创建work表*/
CREATE TABLE work
(empid NUMBER(8),
 deptno NUMBER(8),
 worktime NUMBER(2)
);
/*插入数据*/
insert into employee values(1001,'tom',35,'海淀',8000);
insert into employee values(1002,'dennis',24,'朝阳',5000);
insert into employee values(1003,'john',35,'海淀',4000);
insert into employee values(1004,'rick',41,'朝阳',7000);
insert into employee values(1005,'bill',45,'海淀',4000);
insert into employee values(1006,'frank',24,'朝阳',7000);
insert into department values(001,'人事',1002);
insert into department values(002,'信息',1004);
insert into department values(003,'销售',1005);
insert into department values(004,'财务',1006);
insert into work values(1001,002,6);
insert into work values(1002,001,1);
insert into work values(1001,004,2);
insert into work values(1001,001,2);
insert into work values(1002,004,0);
insert into work values(1003,001,4);
insert into work values(1004,002,1);
insert into work values(1005,003,2);
insert into work values(1006,004,4);
/*为财务部门的雇员加薪,3年以上加5%*/
UPDATE employee SET sal=sal+sal*0.05 WHERE empid IN 
    (SELECT e.empid,w.worktime FROM employee e INNER JOIN work w ON 
    e.empid=w.empid INNER JOIN department d ON d.deptno=w.deptno 
WHERE d.dname='财务' AND w.worktime>3);


错误提示ora-00911:值过多
但是单独用括号里面的查询语句查询就没问题啊。请问这是什么原因啊?

------解决方案--------------------
子查询
(SELECT e.empid,w.worktime FROM employee e INNER JOIN work w ON 
e.empid=w.empid INNER JOIN department d ON d.deptno=w.deptno 
WHERE d.dname='财务' AND w.worktime>3)中多select了一个字段w.worktime