当我运行该程序时,我得到此错误[错误] ORA-24344:成功编译错误缺少关键字

时间:2017-03-21 12:06:57

标签: oracle

CREATE OR REPLACE 
PROCEDURE "UNASSIGN_CUSTOMER_FEATURES" 
(CustomerID_Param IN NUMBER, FeatureID_Param IN NUMBER, WalletID_Param IN NUMBER)
AS
BEGIN

DELETE FROM CUSTOMER_EXTRA_FEATURES WHERE FEATURES_ID = FeatureID_Param 
AND CUSTOMER_ID = CustomerID_Param;

MERGE INTO CUSTOMER_SERVICE_CONFIG c
USING 
            (SELECT BUSINESS_SERVICE_CONFIG.ID from BUSINESS_SERVICE_CONFIG join SERVICE_CONFIG_MAP 
                    ON BUSINESS_SERVICE_CONFIG.Business_SERVICE_TYPE = SERVICE_CONFIG_MAP.Service_type_ID
                    and BUSINESS_SERVICE_CONFIG.ORGANIZATION_ID = WalletID_Param
                    and BUSINESS_SERVICE_CONFIG.BUSINESSSERVICECATEGORY = 0 
                    and SERVICE_CONFIG_MAP.FEATURES_ID = FeatureID_Param ) ids

ON (c.SERVICE_CONFIG_ID = ids.ID and c.CUSTOMER_ID = CustomerID_Param )
WHEN MATCHED THEN 
DELETE WHERE CUSTOMER_ID = CustomerID_Param AND SERVICE_CONFIG_ID = ids.ID;

END;

2 个答案:

答案 0 :(得分:0)

在执行DELETE

之前,您缺少UPDATE语句

类似

WHEN MATCHED THEN 
  UPDATE SET <some field> with <some value>
  DELETE WHERE CUSTOMER_ID = CustomerID_Param AND SERVICE_CONFIG_ID =ids.ID;
END;

请参阅以下网址: Oracle sql merge to insert and delete but not update

希望有所帮助!

答案 1 :(得分:0)

The syntax diagram for the merge statement表明delete子句是update的可选部分,而不是独立的:

enter image description here

您正在获取&#34; ORA-00905:缺少关键字&#34;错误,因为您没有update。您可以进行虚拟更新,但看起来您确实要删除所有匹配的行,而不会更新其他行或插入新行;这可能比简单delete更简单,如:

DELETE FROM CUSTOMER_SERVICE_CONFIG c
WHERE CUSTOMER_ID = CustomerID_Param
AND SERVICE_CONFIG_ID IN (
  SELECT BUSINESS_SERVICE_CONFIG.ID from BUSINESS_SERVICE_CONFIG join SERVICE_CONFIG_MAP 
  ON BUSINESS_SERVICE_CONFIG.Business_SERVICE_TYPE = SERVICE_CONFIG_MAP.Service_type_ID
  and BUSINESS_SERVICE_CONFIG.ORGANIZATION_ID = WalletID_Param
  and BUSINESS_SERVICE_CONFIG.BUSINESSSERVICECATEGORY = 0 
  and SERVICE_CONFIG_MAP.FEATURES_ID = FeatureID_Param );

DELETE FROM CUSTOMER_SERVICE_CONFIG c
WHERE CUSTOMER_ID = CustomerID_Param
AND EXISTS (
  SELECT null from BUSINESS_SERVICE_CONFIG join SERVICE_CONFIG_MAP 
  ON BUSINESS_SERVICE_CONFIG.Business_SERVICE_TYPE = SERVICE_CONFIG_MAP.Service_type_ID
  and BUSINESS_SERVICE_CONFIG.ORGANIZATION_ID = WalletID_Param
  and BUSINESS_SERVICE_CONFIG.BUSINESSSERVICECATEGORY = 0 
  and SERVICE_CONFIG_MAP.FEATURES_ID = FeatureID_Param
  WHERE BUSINESS_SERVICE_CONFIG.ID = c.SERVICE_CONFIG_ID );