我想使用execute immediate作为forall语法,因为我想使用变量'schemasname'而不是'dcbhmoh1'。 感谢
DECLARE
schemasname varchar2(25) := 'dcbhmoh1';
datet char(6) := '102024';
TYPE anames IS table of dcbhmoh1.F01131M%ROWTYPE;
ar anames;
BEGIN
EXECUTE IMMEDIATE 'SELECT * FROM ' || schemasname || '.F01131M WHERE ZMDTI >= ' || datet BULK COLLECT INTO ar;
dbms_output.put_line(ar.count);
IF ar.Count > 0 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || schemasname || '.F01131M';
FORALL i in ar.first .. ar.last INSERT INTO dcbhmoh1.F01131M VALUES ar(i);
END IF;
END;
答案 0 :(得分:1)
您可以尝试使用
为工作会话定义架构EXECUTE IMMEDIATE 'Alter session set current_schema='|| schemasname ;
像这样:
DECLARE
schemasname varchar2(25) := 'dcbhmoh1';
datet char(6) := '102024';
TYPE anames IS table of dcbhmoh1.F01131M%ROWTYPE;
ar anames;
BEGIN
-- set schema
EXECUTE IMMEDIATE 'Alter session set current_schema='|| schemasname ;
-- do your work
EXECUTE IMMEDIATE 'SELECT * FROM F01131M WHERE ZMDTI >= ' || datet BULK COLLECT INTO ar;
dbms_output.put_line(ar.count);
IF ar.Count > 0 THEN
EXECUTE IMMEDIATE 'TRUNCATE TABLE F01131M';
FORALL i in ar.first .. ar.last INSERT INTO F01131M VALUES ar(i);
END IF;
END;
(不确定FORALL
的完整语法。)