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

标签 sql c oracle embedded-sql

谁能找出我在以下 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.

关于sql - 有谁知道为什么我的立即执行不能在 PRO*C 中编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30213146/

相关文章:

sql - 'extract(year from sysdate)'的速度

PHP选择类别和计数

c++ - 按钮和组合框 WinAPI

oracle - ALL_CONSTRAINTS 和 ALL_CONS_COLUMNS 中的 OWNER 是否与表所有者相同?

database - 如何从另一个表创建表并将 NULL 值传递给列?

database - PFILE 在 Oracle 中的位置

php - PDO 联合选择结果没有任何结果

sql - 如何从没有 id 的表中删除重复(重复)记录和行

c - 即使存在非局部跳跃,也能稳健地检测递归

c - 为什么程序会给出意外的输出?