I'd like to update a table in dynamic 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
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:
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
".... You cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement...."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.