假设我们有员工表,我的目的是编写declare -blog语句,该员工的薪水增加10%,工作部门的工资高于平均水平,如果没有更多,则增加20%薪水, 我认为代码应该是
begin
update employees e set e.salary=e.salary+e.salary*0.1;
where e.salary>(select avg(e.salary) from employees e group by e.department_id);
update employees e set e.salary=e.salary+e.salary*0.1;
where e.salary<(select avg(e.salary) from employees e group by e.department_id);
end;
但它返回以下错误列表
Error starting at line 4 in command:
begin
update employees e set e.salary=e.salary+e.salary*0.1;
where e.salary>(select avg(e.salary) from employees e group by e.department_id);
update employees e set e.salary=e.salary+e.salary*0.1;
where e.salary<(select avg(e.salary) from employees e group by e.department_id);
end;
Error report:
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "WHERE" when expecting one of the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
请帮我解释为什么?,是否有必要的循环声明或?
答案 0 :(得分:4)
删除<{p>}上的;
update employees e set e.salary=e.salary+e.salary*0.1;
;
会终止该声明,但您会继续使用WHERE
答案 1 :(得分:2)
;
之前有分号(where
);分号关闭PL / SQL语句。
我还建议您以一种易于阅读和更难犯错的方式格式化您的陈述:
update employees e set
e.salary=e.salary+e.salary*0.1 -- no semicolon here
where
e.salary > (
select avg(e.salary)
from employees e
group by e.department_id
);