Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plsql 为什么这个PL/SQL不';不行?_Plsql_Sqlplus - Fatal编程技术网

Plsql 为什么这个PL/SQL不';不行?

Plsql 为什么这个PL/SQL不';不行?,plsql,sqlplus,Plsql,Sqlplus,我正在努力学习PL/SQL。我被这个密码深深打动了。请通知我哪里出了问题。我在命令行中使用Oracle 10g declare grade char(1):='&v_grade'; app varchar(15); begin app:=case v_grade when 'a' then dbms_output.put_line('Excellent'); when 'b' then dbms_output.put_line('Good'); else dbms_output.put_

我正在努力学习PL/SQL。我被这个密码深深打动了。请通知我哪里出了问题。我在命令行中使用Oracle 10g

declare
grade char(1):='&v_grade';
app varchar(15);
begin
app:=case v_grade
when 'a' then
dbms_output.put_line('Excellent');
when 'b' then
dbms_output.put_line('Good');
else
dbms_output.put_line('Bad');
end case;
dbms_output.put_line('Grade'||grade||' Appraisal:'||app);
end;
/
它表明

Enter value for v_grade: a
old   2: grade char(1):='&v_grade';
new   2: grade char(1):='a';
dbms_output.put_line('Excellent');
                                 *
ERROR at line 7:
ORA-06550: line 7, column 34:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( * % & = - + < / > at else end in is mod remainder not rem
when <an exponent (**)> <> or != or ~= >= <= <> and or like
LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_
The symbol ";" was ignored.
ORA-06550: line 9, column 29:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( * % & = - + < / > at else end in is mod remainder not rem
when <an exponent (**)> <> or != or ~= >= <= <> and or like
LIKE2_ LIKE4_ LIKEC_ between ||
ORA-06550: line 11, column 28:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( * % & = - + < / > at end in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_
LIKE4_ LIKEC_ between || multiset
输入v_等级的值:a
旧2:等级字符(1):='和v_等级';
新2:等级字符(1):='a';
dbms_output.put_line('Excellent');
*
第7行错误:
ORA-06550:第7行第34列:
PLS-00103:在预期以下情况时遇到“;”符号:
. (*%&=-+在中的else端是mod余数而不是rem
当或!=或~=>=在else end in中是mod rement而不是rem时
当或!=或~=>=在结尾处为mod rem时,余数不是rem

或者!=或者~=>=T.J.Crowder是对的,在SQL中case语句中不应该有分号,但是这是PL/SQL版本,所以它有点不同

您当前正试图从
dbms\u输出中分配(不存在)返回。将
过程(非函数)调用放入
app
变量

为了使赋值有效,您需要将
案例
计算为字符串,因此您可以只使用文本文本;但赋值需要在每个分支中:

declare
  grade char(1):='&v_grade';
  app varchar(15);
begin
  case grade
    when 'a' then app:= 'Excellent';
    when 'b' then app:= 'Good';
    else app := 'Bad';
  end case;

  dbms_output.put_line('Grade '||grade||' Appraisal: '||app);
end;
/
declare
  grade char(1):='&v_grade';
begin
  dbms_output.put('Grade '||grade||' Appraisal: ');
  case grade
    when 'a' then
      dbms_output.put_line('Excellent');
    when 'b' then
      dbms_output.put_line('Good');
    else
       dbms_output.put_line('Bad');
  end case;
end;
/

Enter value for v_grade: c
Grade c Appraisal: Bad

PL/SQL procedure successfully completed.
当运行得到以下结果时:

Enter value for v_grade: a
Grade b Appraisal: Excellent

PL/SQL procedure successfully completed.
或者使用查询来执行分配,尽管这不是很有效:

declare
  grade char(1):='&v_grade';
  app varchar(15);
begin
  select case grade
    when 'a' then 'Excellent'
    when 'b' then 'Good'
    else 'Bad'
  end case
  into app
  from dual;
  dbms_output.put_line('Grade '||grade||' Appraisal: '||app);
end;
/

Enter value for v_grade: b
Grade b Appraisal: Good

PL/SQL procedure successfully completed.
或者,您可以直接在每个分支中进行输出:

declare
  grade char(1):='&v_grade';
  app varchar(15);
begin
  case grade
    when 'a' then app:= 'Excellent';
    when 'b' then app:= 'Good';
    else app := 'Bad';
  end case;

  dbms_output.put_line('Grade '||grade||' Appraisal: '||app);
end;
/
declare
  grade char(1):='&v_grade';
begin
  dbms_output.put('Grade '||grade||' Appraisal: ');
  case grade
    when 'a' then
      dbms_output.put_line('Excellent');
    when 'b' then
      dbms_output.put_line('Good');
    else
       dbms_output.put_line('Bad');
  end case;
end;
/

Enter value for v_grade: c
Grade c Appraisal: Bad

PL/SQL procedure successfully completed.
输出的第一部分现在在案例之前

你基本上混淆了不同的方法

您可能希望将第一行更改为:

  grade char(1):= upper('&v_grade');
…然后让案例寻找A,B,C,而不是A,B,C-那么输入在什么情况下都无关紧要


你可以阅读更多关于PL/SQL
案例的内容。

我对PL/SQL一无所知,但我会怀疑,既然
放线
案例中…当…然后
在它不正确之后放一个
语句。在SQL中,
终止语句。你不想在那里终止语句。Th直到
结束case
之后,e语句才结束(这里确实有一个
,这是适当的)。我怀疑它没有一个值,但正如我所说,我对PL/SQL一无所知,所以…:-)我仍然在第9行第7列
输入v_grade的值:一个旧的2:grade字符(1):='&v_grade';新2:等级字符(1):='a';结束案例;*第9行错误:ORA-06550:第9行第7列:PLS-00103:在预期以下情况时遇到符号“CASE”:&=-+;at in是mod余数而不是rem或!=或者~=>=@AravindS-是的,对不起,我正在执行你的任务,还没有注册你不能这么做。我更新了三个备选方案。结果证明你可以完成任务。