DECLARE
var_employee_number VARCHAR2(30);
var_employee_name VARCHAR2(30);
var_salary VARCHAR2(30);
BEGIN
SELECT employee_number,employee_name,
CASE var_salary
WHEN salary <= 10000 THEN salary:= salary* .02 /*I am getting an error over here*/
WHEN salary BETWEEN 10000 AND 15000 THEN salary := salary * .02
WHEN salary BETWEEN 15000 AND 20000 THEN salary := salary * .025
END AS salary INTO var_employee_number,var_employee_name,var_salary
FROM EMPLOYEES
WHERE employee_number := var_employee_number;
dbms_output.put_line('The salary is '||var_salary);
END;
我试图写一个案例陈述,如果你的工资在一个特定的范围内,工资应该乘以20%或25%,具体取决于工资范围。
答案 0 :(得分:3)
您的CASE
声明有几个问题:
CASE var_salary -- you don't need var_salary here
WHEN salary <= 10000 THEN salary:= salary* .02 /*I am getting an error over here*/ -- you don't need "salary:=" here
WHEN salary BETWEEN 10000 AND 15000 THEN salary := salary * .02
WHEN salary BETWEEN 15000 AND 20000 THEN salary := salary * .025
END AS salary
所以纠正这些问题应该只读:
CASE WHEN salary <= 10000 THEN salary * 0.2
WHEN salary BETWEEN 10000 AND 15000 THEN salary * 0.2
WHEN SALARY BETWEEN 15000 AND 20000 THEN salary * 0.25
END AS salary
您可能还会注意到<= 10000
和BETWEEN 10000 AND 15000
的案例相同,因此可以合并。
另请注意,BETWEEN ... AND
包含在内,因此值15000将返回15000 * 0.2
(3000),而不是* 0.25
。
此外,请注意我更正了您的数字... 20%是0.2
,而不是.02
。