gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:06:44 27 4
gpt4 key购买 nike

我需要在数据库中添加新记录,或者如果已经存在则对其进行更新。
我使用了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>

但是,我坚持不使用保留关键字。使用其他变量名。

关于oracle - PL/SQL : ORA-00936: missing expression::Where Am I going wrong in the code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28956824/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com