簡體   English   中英

動態SQL-使用表變量更新表

[英]Dynamic sql - update table using table variable

我想更新動態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;

作品。

第一個解決方案出了什么問題?

您不能在pl / 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.

有關更多信息,請單擊此處: http : //docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm

使用說明

“ ....您不能使用綁定參數將架構對象的名稱傳遞給動態SQL語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM