0

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?

4

3 に答える 3

1

pl/sql のテーブル名にバインド変数を使用することはできません

于 2013-07-30T09:46:48.013 に答える
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

于 2013-07-30T09:49:24.420 に答える