Lucee中INSERT上的Oracle SQL错误ORA-00933

时间:2017-01-24 15:16:36

标签: oracle lucee

错误ORA-00933:SQL命令未正确结束

尝试使用以下cfscript语句插入行:

q.setSQL("
INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
SELECT #r.SCOINDEX[i]#, sc.DESCRIP, #(data.isDefault == 'Y' ? "'Y'" : "NULL")#, sc.CODE, sc.ID, sc.PRICE
FROM SALES_CHOICE sc
WHERE sc.ID = #y.id[1]#
");

结果

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
SELECT 25628, sc.DESCRIP, 'Y', sc.CODE, sc.ID, sc.PRICE
FROM SALES_CHOICE sc
WHERE sc.ID = 222

其他变种也因ORA-00933错误而失败:

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE, SEQ) 
SELECT 25628, DESCRIP, 'Y', CODE, ID, PRICE, NULL
FROM SALES_CHOICE
WHERE ID = 222
AND NOT ID in (
    SELECT SALES_CHOICE_ID 
    FROM SALES_OPTION_CHOICE l
    WHERE SALES_CONFIG_OPTION_ID = 25628
)

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE, SEQ) 
SELECT 25628, DESCRIP, 'Y', CODE, ID, PRICE, NULL
FROM SALES_CHOICE
WHERE ID = 222

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE, SEQ) 
SELECT 25628, DESCRIP, 'Y', CODE, ID, PRICE, NULL
FROM SALES_CHOICE
WHERE ID = 222

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
SELECT 25628 SCOINDEX, DESCRIP, 'Y' ISDEFAULT, CODE, ID, PRICE
FROM SALES_CHOICE
WHERE ID = 222

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
SELECT 25628 SCOINDEX, sc.DESCRIP, 'Y' ISDEFAULT, sc.CODE, sc.ID, sc.PRICE
FROM SALES_CHOICE sc
WHERE sc.ID = 222

INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
SELECT 25628 SCOINDEX, sc.DESCRIP, 'Y' ISDEFAULT, sc.CODE, sc.ID, sc.PRICE
FROM SALES_CHOICE sc
WHERE sc.ID = 222;

我确信这个问题对我来说是一个小小的疏忽。我现在已经打了好几个小时了。我很欣赏任何见解。

1 个答案:

答案 0 :(得分:0)

解决了!显然INSERT语句需要包含在BEGIN - END中;

q.setSQL("
    BEGIN
       INSERT INTO SALES_OPTION_CHOICE (SALES_CONFIG_OPTION_ID, DESCRIP, ISDEFAULT, CODE, SALES_CHOICE_ID, PRICE) 
       SELECT #r.SCOINDEX[i]#, sc.DESCRIP, #(data.isDefault == 'Y' ? "'Y'" : "NULL")#, sc.CODE, sc.ID, sc.PRICE
       FROM SALES_CHOICE sc
       WHERE sc.ID = #y.id[1]#;
    END;
");