我需要复制或插入来自my_view
的数据(基于3个连接表)。在此之前,我已根据my_table
创建了表格my_view
。
对于我使用以下程序:
create or replace procedure view_copy(
my_view in varchar2,
my_table in varchar2)
is
begin
execute immediate 'insert into '||my_table||' (select * from '||my_view||')';
end;
数据不会复制到my_table
。是否可以将数据从视图复制到表格?如何以不同的方式编写程序?
答案 0 :(得分:1)
你的程序有效;如果您无法在目标表中找到数据,也许您应该检查您的视图。 对您的程序进行简单测试:
SQL> create table table1 ( id1 number)
2 /
Table created.
SQL> create table table2 ( id2 number)
2 /
Table created.
SQL> create or replace view v_t1_t2 as select id1, id2 from table1 cross join table2
2 /
View created.
SQL> create table table1_2 ( id1 number, id2 number)
2 /
Table created.
SQL> create or replace procedure view_copy(
2 my_view in varchar2,
3 my_table in varchar2)
4 is
5 begin
6 execute immediate 'insert into '||my_table||' (select * from '||my_view||')';
7 end;
8 /
Procedure created.
SQL> insert into table1 values (1);
1 row created.
SQL> insert into table2 values (2);
1 row created.
SQL> exec view_copy('v_t1_t2', 'table1_2');
PL/SQL procedure successfully completed.
SQL> select * from table1_2;
ID1 ID2
---------- ----------
1 2