PL/SQL: ORA-00936: 缺少表达式 :: 我的代码哪里出错了?

PL/SQL: ORA-00936: missing expression :: Where Am I going wrong in the code?

我需要在我的数据库中添加一条新记录或更新它(如果它已经存在)。 我使用了 IF else 子句。 我的 oracle 数据库有一个 SQL 查询,如下所示:

DECLARE EXISTS number;
BEGIN
SELECT count(*) INTO EXISTS
FROM reports
WHERE report_id=27;

IF(EXISTS =0) THEN
INSERT INTO reports (REPORT_ID,TITLE,CATEGORY,DISPLAY_ORDER,QUERY,DESCRIPTION,CONTENT_SEQ,DELD,ADMIN_ID,DATE_UPD)
VALUES (27,
        'Check user entered keywords have valid resource link',
        'zData checks',
        9120,
        'Select Rk.Resource_Id As "Resource IDs", Rp.Display_Title As "Title", St.Title As "Type", 
        Decode(Rp.Deld, Null, ''Missing resource'',''Resource deleted (DELD is '' || Rp.Deld || '')'') As "Reason",
        rk.keyword,L.Email As "Owner" from resource_keywords rk
        Left Join Resources Rp On rk.Resource_Id = Rp.Resource_Id
        Left Join Special_Types St On Rp.Special_Id = St.Special_Id
        Left Join Login L On rk.Admin_Id = L.Login_Id
        Where Rk.Deld = 0 And (Rp.Resource_Id Is Null Or Rp.Deld Is Null Or Rp.Deld <> 0);',
        'Check resource_keywords entries for valid and not deleted resource_id.',
        1,
        0,
        1,
        CURRENT_TIMESTAMP);

ELSE
UPDATE reports
SET TITLE = 'Check user entered keywords have valid resource link',
    CATEGORY = 'zData checks',
    DISPLAY_ORDER= 9120,
    QUERY ='Select Rk.Resource_Id As "Resource IDs", Rp.Display_Title As "Title", St.Title As "Type", 
                Decode(Rp.Deld, Null, ''Missing resource'',''Resource deleted (DELD is '' || Rp.Deld || '')'') As "Reason",
                rk.keyword,L.Email As "Owner" from resource_keywords rk
                Left Join Resources Rp On rk.Resource_Id = Rp.Resource_Id
                Left Join Special_Types St On Rp.Special_Id = St.Special_Id
                Left Join Login L On rk.Admin_Id = L.Login_Id
                Where Rk.Deld = 0 And (Rp.Resource_Id Is Null Or Rp.Deld Is Null Or Rp.Deld <> 0);',
    DESCRIPTION='Check resource_keywords entries for valid and not deleted resource_id.',
    CONTENT_SEQ=1,
    DELD=0,
    ADMIN_ID=1,
    DATE_UPD = CURRENT_TIMESTAMP
WHERE REPORT_ID = 27;
END IF;
END;

这会在 ORACLE SQL 开发人员中引发以下错误:

Error report:
ORA-06550: line 3, column 22:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 3, column 1:
PL/SQL: SQL Statement ignored
ORA-06550: line 7, column 11:
PLS-00103: Encountered the symbol "=" when expecting one of the following:

   (
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.

我哪里错了?

ORA-06550: line 3, column 22: PL/SQL: ORA-00936: missing expression

Oracle很清楚的告诉你错误在哪里。您只需要查看错误详细信息,特别是行号。

第 3 行 将带您到 SELECT count(*) INTO EXISTS第 22 栏 会将您带到 EXISTS。为保留关键字,不能直接使用。

如果真的要用,那么用双引号括起来。例如,

SQL> DECLARE
  2    "EXISTS" NUMBER;
  3  BEGIN
  4    SELECT COUNT(*) INTO "EXISTS" FROM emp;
  5    dbms_output.put_line("EXISTS");
  6  END;
  7  /
14

PL/SQL procedure successfully completed.

SQL>

但是,我会坚持不使用保留关键字。使用不同的变量名。