Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/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
Oracle 执行错误时遇到符号“quot;如果;当预期以下情况之一时_Oracle_Plsql_Logical Operators_Declare - Fatal编程技术网

Oracle 执行错误时遇到符号“quot;如果;当预期以下情况之一时

Oracle 执行错误时遇到符号“quot;如果;当预期以下情况之一时,oracle,plsql,logical-operators,declare,Oracle,Plsql,Logical Operators,Declare,SQL查询执行期间出错 Reason: SQL Error [6550] [65000]: ORA-06550: line 11, column 1: PLS-00103: Encountered the symbol "IF" when expecting one of the following: := . ( % ; The symbol ";" was substituted for "IF" to continue.

SQL查询执行期间出错

Reason:
SQL Error [6550] [65000]: ORA-06550: line 11, column 1:
PLS-00103: Encountered the symbol "IF" when expecting one of the following:

   := . ( % ;
The symbol ";" was substituted for "IF" to continue.
ORA-06550: line 31, column 15:
PLS-00103: Encountered the symbol "(" when expecting one of the following:

   , from
------------------------代码从这里开始--------


前两个PL/SQL块是正常的(就语法而言)。但是,考虑用斜线终止它们。

但是,第三个块的格式完全不正确:

  • 如果
    不能将字符串括在双引号中(您可能应该将“my logic here”放在注释中,并使用
    NULL;
    命令,以便对其进行编译
  • 变量不应该有冒号(此处不使用任何绑定)
  • 要计算它的值,您不必从DUAL中选择——只需计算它
  • 此外,
    END
    丢失
此外,由于第三个块使用前两个块中声明的变量,因此它无法工作-它们在这里是未知的。您可能只有一个
DECLARE
部分,声明所有3个变量,将所有“逻辑”放在一个PL/SQL块中。类似这样:

DECLARE
   totalcount         INT;
   totalptcount       INT;
   totaloverallcount  INT;
BEGIN
   SELECT COUNT (*) INTO totalcount FROM abc;

   DBMS_OUTPUT.put_line (totalcount);

   SELECT COUNT (*)
     INTO totalptcount
     FROM ghi g;

   DBMS_OUTPUT.put_line (totalptcount);

   totaloverallcount := (totalptcount / totalcount) * 100;

   DBMS_OUTPUT.put_line (totaloverallcount);

   IF totaloverallcount >= 10                  --> your IF is completely wrong
   THEN
      NULL;
   -- "my logic here"
   END IF;
END;
/

您尚未指定正在使用的DBMS。查看代码时,DBMS\u output.put\u行(TOTALOVERALLCOUNT)后面应该有“;”?当您遇到Oracle错误时,它不是SQL Server。请只标记一个RDBMS。感谢@Littlefoot。我最终在一个块中声明了所有变量,并使其正常工作,但我的问题仍然是,我希望在任何适用的情况下满足条件,然后执行“我的逻辑”部分并输出无法让它工作。我也尝试过使用case语句而不是IF,但它不起作用。有什么建议吗?这就是我修改后的代码看起来像是这样的@Littlefoot。我最终在一个块中声明了所有变量,我让它工作了,但我的问题仍然是IF语句不起作用,并抛出t错误。我也尝试过使用case语句而不是IF,但它不起作用。有什么建议吗?当我分别运行declare块和logic块时,它们运行时没有任何错误,所以我想我没有正确地加入它们使用IF-so,如果你能纠正我的错误,或者如何正确地应用IF在我的逻辑中是值得赞赏的ted.TIA这就是我修改过的代码的样子:DECLARE TOTALCOUNT int;TOTALPTCOUNT int;TOTALOVERALLCOUNT int;BEGIN SELECT count()作为cnt从abc转换成TOTALCOUNT;dbms_output.put_line(TOTALCOUNT);SELECT count()作为cnt从ghi g转换成TOTALPTCOUNT;dbms_output.put_line(TOTALPTCOUNT);TOTALOVERALLCOUNT:=((TOTALPTCOUNT/TOTALCOUNT)*100);dbms_output.put_line(TOTALOVERALLCOUNT);如果TOTALOVERALLCOUNT>1,则“我的逻辑在此”结束如果;结束;唯一明显错误的是双引号字符串
“我的逻辑在此”
。您应该在其中放入一些代码,即“您的逻辑”.我不知道这个逻辑是什么-这就是为什么我在那里放了一个
null;
命令。
DECLARE
   totalcount         INT;
   totalptcount       INT;
   totaloverallcount  INT;
BEGIN
   SELECT COUNT (*) INTO totalcount FROM abc;

   DBMS_OUTPUT.put_line (totalcount);

   SELECT COUNT (*)
     INTO totalptcount
     FROM ghi g;

   DBMS_OUTPUT.put_line (totalptcount);

   totaloverallcount := (totalptcount / totalcount) * 100;

   DBMS_OUTPUT.put_line (totaloverallcount);

   IF totaloverallcount >= 10                  --> your IF is completely wrong
   THEN
      NULL;
   -- "my logic here"
   END IF;
END;
/