Oracle:DBMS_UTILITY.EXEC_DDL_STATEMENT与立即执行 [英] Oracle: DBMS_UTILITY.EXEC_DDL_STATEMENT vs EXECUTE IMMEDIATE
问题描述
DBMS_UTILITY.EXEC_DDL_STATEMENT
和EXECUTE IMMEDIATE
之间有哪些区别?
推荐答案
从根本上讲,它们执行相同的操作,这是提供一种在PL/SQL中执行DDL语句的机制,这是本机不支持的.如果内存对我有好处,则Oracle 7版本的DBMS_UTILITY软件包中提供了EXEC_DDL_STATEMENT,而本机动态SQL(EXECUTE IMMEDIATE)仅在8中引入.
Fundamentally they do the same thing, which is to provide a mechanism to execute DDL statements in PL/SQL, which isn't supported natively. If memory serves me well, the EXEC_DDL_STATEMENT was available in the Oracle 7 version of the DBMS_UTILITY package, whereas Native Dynamic SQL (EXECUTE IMMEDIATE) was only introduced in 8.
有几个区别. EXECUTE IMMEDIATE主要是关于执行动态SQL(如其NDS名称所示).我们可以将其用于DDL的事实很明显.
There are a couple of differences. EXECUTE IMMEDIATE is mainly about executing dynamic SQL (as its NDS name indicates). the fact that we can use it for DDL is by-the-by.
但是保留DBMS_UTILITY版本并不是为了向后兼容,它有一个整齐的技巧,我们不能立即执行EXECUTE-以分布式方式运行DDL.我们可以从本地数据库运行此语句,以在远程数据库上创建表(假设我们的用户在那里具有必需的特权):
But the DBMS_UTILITY version isn't retained just for backwards compatibility, it has one neat trick we cannot do with EXECUTE IMMEDIATE - running DDL in a distributed fashion. We can run this statement from our local database to create a table on a remote database (providing our user has the necessary privileges there):
SQL> exec DBMS_UTILITY.EXEC_DDL_STATEMENT@remote_db('create table t1 (id number)');
我不建议这样做,只是说可以做到.
I'm not recommending this, just say it can be done.
这篇关于Oracle:DBMS_UTILITY.EXEC_DDL_STATEMENT与立即执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!