Pro*C中Merge用法的异常

一同事在公司的bbs技术栏里发布一帖子,请教如下的问题:

在Pro*C中使用Merge语句,来代替原来的Update or Insert语句,在预编译时,总是报错。代码如下:
EXEC SQL MERGE INTO tab1 a USING
(select * from tab2
where tab2.col1=:parameter1 and tab2.col2=:parameter2) b
ON (a.col1 = b.col1 AND a.col2 = b.col2)
WHEN MATCHED THEN UPDATE SET a.col3 = :parameter3
WHEN NOT MATCHED THEN INSERT VALUES (b.col1, b.col2, b.col3);

所使用的预编译器是:Pro*C/C++: Release 9.2.0.4.0

[@more@]

异常信息如下:
PCC-S-02201, Encountered the symbol "MERGE" when expecting one of the following:

for, register, at, close, commit, connect, declare, describe,
execute, fetch, open, prepare, rollback, select, whenever,
alter, audit, comment, create, delete, drop, get, grant,
insert, lock, noaudit, rename, revoke, set, update, validate,
arraylen, allocate, cache, call, collection, context,
deallocate, enable, free, lob, object, savepoint, analyze,
explain, truncate,
The symbol "alter," was substituted for "MERGE" to continue.

通过查询oracle相关文档,得知如下结论:
The Unified SQL Parser was introduced in the Oracle RDBMS PL/SQL in 9i. The precompilers, as of 10g, have not yet
incorporated this Unified SQL Parser into their syntactic or semantic checking and still use an old version of the PL/SQL Parser.
This means that the existing Precompiler's PL/SQL Parser engine is limited to 8.0 and some 8i syntax.

Precompilers and the Unified SQL ParserAlso, syntactic checking is done by the precompiler, and not the PL/SQL parser. The precompiler was extended in each release to pick up some of the new syntax but not all. For instance 9.2 MERGE is not accepted by the syntax checker so therefore you will find 9i and 10g syntax that the precompilers do not accept.

The most common error reported for syntax that is not accepted is Error: PCC-S-02201
The workaround is to use dynamic SQL so no statement parsing takes place at precompile time.
The Unified Parser for Pro*C and Pro*Cobol is planned to be included in 11g with very high priority.

看来要在Pro*C中使用Merge语句,得使用动态的SQL才行。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/38542/viewspace-928328/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/38542/viewspace-928328/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值