0

这是我在 Oracle SQL Developer 中运行的代码,接下来出现了错误:这是一个非常简单的查询,它有什么问题?

DECLARE zero varchar(20);
DECLARE emptys;
begin
zero := '0';
emptys := null;
IF(emptys = zero)   then 
DBMS_OUTPUT.put_line('yes');
ELSE
dbms_output.Put_line('no'); 
end if;
end;
    

从行开始的错误:命令中的 1 - DECLARE zero varchar(20); 声明为空;从零开始:='0';清空:=空;

IF(emptys = zero)   then 
DBMS_OUTPUT.put_line('yes');
ELSE
dbms_output.Put_line('no'); 
end if;

结尾;

错误报告 - ORA-06550:第 2 行,第 5 列:PLS-00103:在预期以下情况之一时遇到符号“DECLARE”:

begin function pragma procedure subtype type current cursor delete exists prior 在“DECLARE”之前插入符号“begin”以继续。ORA-06550:第 13 行,第 74 列:PLS-00103:预期时遇到符号“end-of-file”以下之一:

(begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge json_exists json_value json_query json_object json_array 06550.00000 - “第 %s 行,第 %s 列:\n%s" *原因:通常是 PL/SQL 编译错误。*操作:

4

1 回答 1

0

DECLARE表示变量声明部分的开始。你只有一个这样的部分。您不会为您声明的每个变量重复该关键字。

您没有为变量提供数据类型emptys。我假设你想要那样varchar2(20)

DECLARE 
  zero varchar(20);
  emptys varchar2(20);
begin
  zero := '0';
  emptys := null;
  IF(emptys = zero)   then 
    DBMS_OUTPUT.put_line('yes');
  ELSE
    dbms_output.Put_line('no'); 
  end if;
end;
    
于 2021-12-12T10:26:15.910 回答