oracle CASE WHEN sql 语句中缺少关键字错误
missing keyword error in oracle CASE WHEN sql statement
我正在编写一个过程,其中我有 sql 语句,该语句将使用 CASE WHEN
语句在 TEMP_WF_WORKFLOW
table 中插入值。条件是当 STATUS_ID
是 0
然后是 EVENT_ID=10003
,当 STATUS_ID
是 1
然后是 EVETN_ID=10018
。当我尝试为此使用 CASE WHEN
时,它给我错误 missing keyword.I 不知道,但如果不使用 CASE WHEN
语句,还有其他方法可以做到这一点。我正在考虑使用 cursor
但不知道该怎么做。
这是我的查询:
CREATE OR REPLACE PROCEDURE ext_self_10003_sigwf AS BEGIN
-- first empty TEMP_WF_WORKFLOW table
EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
-- get WF_WORKFLOW table data
INSERT INTO temp_wf_workflow (status_id, event_id, order_number)
SELECT
wf.status_id,
CASE WHEN wf.status_id = 0 THEN event_id = 10003
WHEN wf.status_id = 1 THEN event_id = 10018 END AS eventid,
tsm.order_number
FROM wf_workflow@fonic_retail wf
JOIN tmp_soap_monitoring_ids tsm ON tsm.subscription_id = wf.subscription_id
WHERE tsm.order_type = 'SELF_REGISTRATION' AND wf.name = 'SIGNUP_MOBILE_PRE_PAID';
COMMIT;
END ext_self_10003_sigwf;
仅插入 THEN 值
CASE WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018 END
从 CASE
:
中删除 EVENT_ID
...
CASE -- EVENT_ID
WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018
END AS EVENTID
...
CASE 有两种形式:
CASE
WHEN <condition> THEN <value>
WHEN <condition> THEN <value> -- etc
ELSE <default value> -- optional
END
或
CASE <value source>
WHEN <match value> THEN <result value>
WHEN <match value> THEN <result value> -- etc
ELSE <default value> -- optional
END
Case 语句执行不正确。您可以通过两种方式使用案例:
1)
Case <some_variable or column_name>
When <value1> then <return_value>
else
<return_value>
end;
2)
Case
When <logical_stamtement (e.g. value1=0 or column1=0)> then <return_value>
else
<return_value>
end
在你的程序中你同时使用了它们。正确的代码应该是
create or replace PROCEDURE EXT_SELF_10003_SIGWF AS
BEGIN
-- first empty TEMP_WF_WORKFLOW table
EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
-- get WF_WORKFLOW table data
Insert into TEMP_WF_WORKFLOW(STATUS_ID,EVENT_ID,ORDER_NUMBER)
Select WF.STATUS_ID,
CASE WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018 END AS EVENTID
,TSM.ORDER_NUMBER FROM WF_WORKFLOW@FONIC_RETAIL WF
where WF.NAME='SIGNUP_MOBILE_PRE_PAID';
commit;
END EXT_SELF_10003_SIGWF;
CASE EVENT_ID WHEN WF.STATUS_ID=0 THEN EVENT_ID=10003
WHEN WF.STATUS_ID=1 THEN EVENT_ID=10018 END AS EVENTID
您混合了 CASE 语句的两种不同 语法。
1.simple_case_statement
CASE [ expression ]
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result
END
2.searched_case_statement
CASE
WHEN expression condition_1 THEN result_1
WHEN expression condition_2 THEN result_2
...
WHEN expression condition_n THEN result_n
ELSE result
END
把你的表情改成-
CASE
WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018
END AS EVENTID
按照此 link 查看这两种语法的文档。
更新 OP 说他仍然遇到 缺少关键字错误。这是一个测试用例,表明它不是真的。缺少的关键字将使用正确的 CASE 语句修复。
SQL> CREATE OR REPLACE
2 PROCEDURE EXT_SELF_10003_SIGWF
3 AS
4 BEGIN
5 -- first empty TEMP_WF_WORKFLOW table
6 EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
7 -- get WF_WORKFLOW table data
8 INSERT
9 INTO TEMP_WF_WORKFLOW
10 (
11 STATUS_ID,
12 EVENT_ID,
13 ORDER_NUMBER
14 )
15 SELECT WF.STATUS_ID,
16 CASE
17 WHEN WF.STATUS_ID=0
18 THEN 10003
19 WHEN WF.STATUS_ID=1
20 THEN 10018
21 END AS EVENTID,
22 TSM.ORDER_NUMBER
23 FROM WF_WORKFLOW@FONIC_RETAIL WF
24 JOIN TMP_SOAP_MONITORING_IDS TSM
25 ON TSM.SUBSCRIPTION_ID=WF.SUBSCRIPTION_ID
26 WHERE TSM.order_type ='SELF_REGISTRATION'
27 AND WF.NAME ='SIGNUP_MOBILE_PRE_PAID';
28 COMMIT;
29 END EXT_SELF_10003_SIGWF;
30 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE EXT_SELF_10003_SIGWF:
LINE/COL ERROR
-------- --------------------------------------------------
7/3 PL/SQL: SQL Statement ignored
23/8 PL/SQL: ORA-00942: table or view does not exist
SQL>
我正在编写一个过程,其中我有 sql 语句,该语句将使用 CASE WHEN
语句在 TEMP_WF_WORKFLOW
table 中插入值。条件是当 STATUS_ID
是 0
然后是 EVENT_ID=10003
,当 STATUS_ID
是 1
然后是 EVETN_ID=10018
。当我尝试为此使用 CASE WHEN
时,它给我错误 missing keyword.I 不知道,但如果不使用 CASE WHEN
语句,还有其他方法可以做到这一点。我正在考虑使用 cursor
但不知道该怎么做。
这是我的查询:
CREATE OR REPLACE PROCEDURE ext_self_10003_sigwf AS BEGIN
-- first empty TEMP_WF_WORKFLOW table
EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
-- get WF_WORKFLOW table data
INSERT INTO temp_wf_workflow (status_id, event_id, order_number)
SELECT
wf.status_id,
CASE WHEN wf.status_id = 0 THEN event_id = 10003
WHEN wf.status_id = 1 THEN event_id = 10018 END AS eventid,
tsm.order_number
FROM wf_workflow@fonic_retail wf
JOIN tmp_soap_monitoring_ids tsm ON tsm.subscription_id = wf.subscription_id
WHERE tsm.order_type = 'SELF_REGISTRATION' AND wf.name = 'SIGNUP_MOBILE_PRE_PAID';
COMMIT;
END ext_self_10003_sigwf;
仅插入 THEN 值
CASE WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018 END
从 CASE
:
EVENT_ID
...
CASE -- EVENT_ID
WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018
END AS EVENTID
...
CASE 有两种形式:
CASE
WHEN <condition> THEN <value>
WHEN <condition> THEN <value> -- etc
ELSE <default value> -- optional
END
或
CASE <value source>
WHEN <match value> THEN <result value>
WHEN <match value> THEN <result value> -- etc
ELSE <default value> -- optional
END
Case 语句执行不正确。您可以通过两种方式使用案例: 1)
Case <some_variable or column_name>
When <value1> then <return_value>
else
<return_value>
end;
2)
Case
When <logical_stamtement (e.g. value1=0 or column1=0)> then <return_value>
else
<return_value>
end
在你的程序中你同时使用了它们。正确的代码应该是
create or replace PROCEDURE EXT_SELF_10003_SIGWF AS
BEGIN
-- first empty TEMP_WF_WORKFLOW table
EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
-- get WF_WORKFLOW table data
Insert into TEMP_WF_WORKFLOW(STATUS_ID,EVENT_ID,ORDER_NUMBER)
Select WF.STATUS_ID,
CASE WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018 END AS EVENTID
,TSM.ORDER_NUMBER FROM WF_WORKFLOW@FONIC_RETAIL WF
where WF.NAME='SIGNUP_MOBILE_PRE_PAID';
commit;
END EXT_SELF_10003_SIGWF;
CASE EVENT_ID WHEN WF.STATUS_ID=0 THEN EVENT_ID=10003 WHEN WF.STATUS_ID=1 THEN EVENT_ID=10018 END AS EVENTID
您混合了 CASE 语句的两种不同 语法。
1.simple_case_statement
CASE [ expression ]
WHEN condition_1 THEN result_1
WHEN condition_2 THEN result_2
...
WHEN condition_n THEN result_n
ELSE result
END
2.searched_case_statement
CASE
WHEN expression condition_1 THEN result_1
WHEN expression condition_2 THEN result_2
...
WHEN expression condition_n THEN result_n
ELSE result
END
把你的表情改成-
CASE
WHEN WF.STATUS_ID=0 THEN 10003
WHEN WF.STATUS_ID=1 THEN 10018
END AS EVENTID
按照此 link 查看这两种语法的文档。
更新 OP 说他仍然遇到 缺少关键字错误。这是一个测试用例,表明它不是真的。缺少的关键字将使用正确的 CASE 语句修复。
SQL> CREATE OR REPLACE
2 PROCEDURE EXT_SELF_10003_SIGWF
3 AS
4 BEGIN
5 -- first empty TEMP_WF_WORKFLOW table
6 EXECUTE IMMEDIATE 'TRUNCATE TABLE TEMP_WF_WORKFLOW';
7 -- get WF_WORKFLOW table data
8 INSERT
9 INTO TEMP_WF_WORKFLOW
10 (
11 STATUS_ID,
12 EVENT_ID,
13 ORDER_NUMBER
14 )
15 SELECT WF.STATUS_ID,
16 CASE
17 WHEN WF.STATUS_ID=0
18 THEN 10003
19 WHEN WF.STATUS_ID=1
20 THEN 10018
21 END AS EVENTID,
22 TSM.ORDER_NUMBER
23 FROM WF_WORKFLOW@FONIC_RETAIL WF
24 JOIN TMP_SOAP_MONITORING_IDS TSM
25 ON TSM.SUBSCRIPTION_ID=WF.SUBSCRIPTION_ID
26 WHERE TSM.order_type ='SELF_REGISTRATION'
27 AND WF.NAME ='SIGNUP_MOBILE_PRE_PAID';
28 COMMIT;
29 END EXT_SELF_10003_SIGWF;
30 /
Warning: Procedure created with compilation errors.
SQL> sho err
Errors for PROCEDURE EXT_SELF_10003_SIGWF:
LINE/COL ERROR
-------- --------------------------------------------------
7/3 PL/SQL: SQL Statement ignored
23/8 PL/SQL: ORA-00942: table or view does not exist
SQL>