简体   繁体   English

动态SQL-使用表变量更新表

[英]Dynamic sql - update table using table variable

I'd like to update a table in dynamic sql. 我想更新动态sql中的表。

declare
    x varchar2(10) := 'table_n';
begin
    execute immediate 'update :1 set column_n = 12345' using x;
end;

I get ORA-00903: invalid table name 我得到ORA-00903:无效的表名

But

declare
    x varchar2(10) := 'table_n';
begin
    execute immediate 'update ' || x ||  ' set column_n = 12345';
end;

Works. 作品。

What's wrong with the first solution? 第一个解决方案出了什么问题?

您不能在pl / sql中为表名使用绑定变量

Dynamic sql: 动态SQL:

1.It generally uses the SQL statements at run time. (for the time which we don't have data at the compilation time).
2. The bind variable , in your query, `x`, uses it on runtime and execute the dynamic on run time. 
3. the bind variable refered by colon is used after USING clause.

For more click here: http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm 有关更多信息,请单击此处: http : //docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm

Usage Notes 使用说明

".... You cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement...." “ ....您不能使用绑定参数将架构对象的名称传递给动态SQL语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM