有谁知道为什么我的立即执行不能在 PRO*C 中编译?

Does anyone know why my execute immediate doesn't complie in PRO*C?

任何人都可以找出我在以下 PRO*C 代码中的错误吗?我无法编译:

int v1 = 5096;
int v2 = 8110;
int v3 = 8111;
int v4 = -1;
char stmt[6000];

strcpy(stmt, " MERGE INTO LDX_STYLE_MOVEMENTS ssd  USING (SELECT :1 pk from dual) ssd_pk   ON (ssd.style_movements_pk = ssd_pk.pk)  WHEN NOT MATCHED THEN insert (style_movements_pk, style, from_subclass, to_subclass, reclassified_date, change_type_fk) values(LDX_STYLE_MOVEMENTS_SEQ.nextval , null, :2, :3, null, :4 )");   

EXEC SQL execute immediate  :stmt using :v1, :v2, :v3, :v4;

EXECUTE IMMEDIATE (dynamic SQL method 1) 不支持 USING 子句。

您可以准备并执行它(使用 dynamic SQL method 2):

EXEC SQL PREPARE ora_stmt FROM :stmt;
EXEC SQL EXECUTE stmt USING :v1, :v2, :v3, :v4;

看起来您根本不需要动态执行此操作,但如果您选择这样做,则需要使用适当的方法。

文档中的更多详细信息:

Method 1 parses, then immediately executes the SQL statement using the EXECUTE IMMEDIATE command. The command is followed by a character string (host variable or literal) containing the SQL statement to be executed, which cannot be a query.

The syntax of the EXECUTE IMMEDIATE statement follows:

EXEC SQL EXECUTE IMMEDIATE { :host_string | string_literal };

...

With Method 2, the SQL statement can contain placeholders for input host variables and indicator variables...

The syntax of the PREPARE statement follows:

EXEC SQL PREPARE statement_name 
    FROM { :host_string | string_literal }; 

PREPARE parses the SQL statement and gives it a name.

The statement_name is an identifier used by the precompiler, not a host or program variable, and should not be declared in the Declare Section. It simply designates the PREPAREd statement you want to EXECUTE.

The syntax of the EXECUTE statement is

EXEC SQL EXECUTE statement_name [USING host_variable_list];

where host_variable_list stands for the following syntax:

:host_variable1[:indicator1] [, host_variable2[:indicator2], ...] 

EXECUTE executes the parsed SQL statement, using the values supplied for each input host variable.