2013-07-30 21 views
0

我想更新動態sql中的表。動態sql - 使用表變量更新表

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

我得到ORA-00903:無效的表名

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

作品。

第一個解決方案有什麼問題?

回答

1

您不能使用綁定變量的表名在PL/SQL

0

動態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. 

欲瞭解更多請點擊:http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm

0

Usage Notes

」 ....您不能使用綁定參數將模式對象的名稱傳遞給動態SQL語句....「