我有几个无法在Oracle SQL Developer 18.2.0.183中运行的块。我不确定是否在块中遗漏了某些东西,或者是否需要对开发人员进行一些更改。下面的块输出“在命令-中从第1行开始出错”。 (用于声明)。
declare
total_purchases number(7,2);
begin
total_purchases :=20;
case
when (total_purchases>200) then dbms_output.put_line(‘high’);
when (total_purchases>100) and total_purchases<200) then dbms_output.put_line(‘mid);
when (total_purchases<100) then dbms_output.put_line(‘low’);
end case;
end
它还会输出以下内容:
感谢您的帮助。谢谢。
答案 0 :(得分:1)
我用“ ^”标记
declare
total_purchases number(7,2);
begin
total_purchases :=20;
case
when (total_purchases>200) then dbms_output.put_line('high');
when ((total_purchases>100) and total_purchases<200) then dbms_output.put_line('mid');
^ ^
when (total_purchases<100) then dbms_output.put_line('low');
end case;
end;
^
答案 1 :(得分:0)
您有两个错字
gcc -g
替换为
when (total_purchases>100) and total_purchases<200) then dbms_output.put_line(‘mid);
答案 2 :(得分:0)
不使用单引号(''),并且大小写定义不正确
fflush()
答案 3 :(得分:0)
这是一种实现方法-将CASE
放入DBMS_OUTPUT.PUT_LINE
通话中:
SQL> set serveroutput on
SQL> DECLARE
2 total_purchases NUMBER (7, 2);
3 BEGIN
4 total_purchases := 20;
5 DBMS_OUTPUT.put_line (CASE
6 WHEN total_purchases > 200
7 THEN
8 'high'
9 WHEN total_purchases > 100
10 AND total_purchases < 200
11 THEN
12 'mid'
13 WHEN total_purchases < 100
14 THEN
15 'low'
16 END);
17 END;
18 /
low
PL/SQL procedure successfully completed.
SQL>
或者,如果您使用语法,请先修复错误(多余的括号,缺少分号):
SQL> DECLARE
2 total_purchases NUMBER (7, 2);
3 BEGIN
4 total_purchases := 20;
5
6 CASE
7 WHEN (total_purchases > 200)
8 THEN
9 DBMS_OUTPUT.put_line ('high');
10 WHEN (total_purchases > 100)
11 AND total_purchases < 200
12 THEN
13 DBMS_OUTPUT.put_line ('mid');
14 WHEN (total_purchases < 100)
15 THEN
16 DBMS_OUTPUT.put_line ('low');
17 END CASE;
18 END;
19 /
low
PL/SQL procedure successfully completed.
SQL>