首页 > 解决方案 > ORA-00917 如果将带有转义单引号的 SQL 语句传递给 OCIStmtExecute

问题描述

如果我尝试在 Oracle SQL Developer 中执行以下语句,我会成功。(注意第一个插入语句的最后一个值。)

    BEGIN
    INSERT INTO attr_value
                (predef_class,
                 plan_nr,
                 key1,
                 key2,
                 key3,
                 key4,
                 key5,
                 type_id,
                 item_id,
                 access_type_id,
                 str_val)
    VALUES      (0,
                 0,
                 10000001,
                 1,
                 1,
                 1740,
                 0,
                 10242,
                 0,
                 10242,
                 'test''test');

    INSERT INTO attr_value
                (predef_class,
                 plan_nr,
                 key1,
                 key2,
                 key3,
                 key4,
                 key5,
                 type_id,
                 item_id,
                 access_type_id,
                 str_val)
    VALUES      (0,
                 0,
                 10000001,
                 1,
                 1,
                 1740,
                 0,
                 10248,
                 0,
                 10248,
                 '');

    INSERT INTO attr_value
                (predef_class,
                 plan_nr,
                 key1,
                 key2,
                 key3,
                 key4,
                 key5,
                 type_id,
                 item_id,
                 access_type_id,
                 dt_val)
    VALUES      (0,
                 0,
                 10000001,
                 1,
                 1,
                 1740,
                 0,
                 10237,
                 0,
                 10237,
                 '2000-01-01 00:00:00');

    INSERT INTO attr_value
                (predef_class,
                 plan_nr,
                 key1,
                 key2,
                 key3,
                 key4,
                 key5,
                 type_id,
                 item_id,
                 access_type_id,
                 float_val)
    VALUES      (0,
                 0,
                 10000001,
                 1,
                 1,
                 1740,
                 0,
                 10111,
                 0,
                 10111,
                 25.281797);

    INSERT INTO attr_value
                (predef_class,
                 plan_nr,
                 key1,
                 key2,
                 key3,
                 key4,
                 key5,
                 type_id,
                 item_id,
                 access_type_id,
                 in_val)
    VALUES      (0,
                 0,
                 10000001,
                 1,
                 1,
                 1740,
                 0,
                 10079,
                 0,
                 10079,
                 0);
END; 

但是,如果我将相同的语句传递给 ociap.h 中定义的 OCIStmtExecute 函数,则相同的语句将失败,并出现 ORA-06550 'Statement ignored' 和 ORA-00917 'Missing comma'。

有没有人提示我如何克服这个问题?

问候,本

标签: c++databaseoracleescaping

解决方案


推荐阅读