在存储过程中用动态SQL建表后如果用PL/SQL插入
CREATE OR REPLACE PROCEDURE y_p_test AS
BEGIN
drop_table(‘y_test‘);
EXECUTE IMMEDIATE ‘ create table y_test (id number, name varchar2(20)) ‘;
FOR i IN (SELECT/*+driving_site(b) */ * FROM small_tab_local a, big_tab_remote@remote b
WHERE a.sub_id=b.sub_id AND a.acc_id=b.acc_id)
LOOP
INSERT INTO y_test VALUES i;
END LOOP;
COMMIT;
END;
create or replace procedure drop_table(x varchar2) as
table1 number;
begin
select COUNT(*) INTO table1 from user_tables where table_name=upper(x);
if table1 > 0
then execute immediate ‘drop table ‘||x;
end if;
end;
/
CREATE OR REPLACE PROCEDURE y_p_test0
AS
BEGIN
drop_table(‘y_test‘);
EXECUTE IMMEDIATE ‘create table y_test as select * from fzt_dd where 1=2‘;
END;
/
CREATE OR REPLACE PROCEDURE y_p_test AS
BEGIN
FOR i IN (SELECT * FROM fzt_dd WHERE ROWNUM<10)
LOOP
INSERT INTO y_test VALUES i;
END LOOP;
COMMIT;
END;
/
CREATE OR REPLACE PROCEDURE y_p_test1 AS
BEGIN
EXECUTE IMMEDIATE ‘begin y_p_test0; end;‘;
EXECUTE IMMEDIATE ‘begin y_p_test; end;‘;
END;
/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。