我有这个程序,该程序生成一个创建视图的sql代码。 在此过程结束时,我们将获得变量“ finale”,其中包含创建视图的代码。 我想知道每次运行该程序时如何执行代码“ finale”吗?
set serveroutput on
declare
compte number;
DQEntity varchar2(50);
DynSQL varchar2(4000);
finale varchar2(4000);
createview varchar2(4000) := 'CREATE OR REPLACE FORCE EDITIONABLE VIEW "DV2_OBIDMT"."F_GENERAL_DATA_QLTY2" ("SRC_SYS_ID", "SOFT_RULE_NAME", "ENTITY_NAME", "DATE_", "PASSES", "FAILS") AS
(';
begin select COUNT(*) into compte
from DV2_OBIADM.IM_LUT_ENTITY_SOFT_RULES;
for ins in (
select ENTITY_NAME as Q1
from DV2_OBIADM.IM_LUT_ENTITY_SOFT_RULES
) loop
DQEntity:= ins.Q1;
DynSQL := DynSQL || 'select distinct
SRC.SRC_SYS_ID,
EN.SOFT_RULE_NAME,
EN.ENTITY_NAME,
(to_date(to_char(SRC.LDTS,'||'DD-MM-YY'||'))) as date_,
sum(case when SRC.QLTY_TEST= '||'Pass' ||'then 1 else 0 end) as Passes,
sum(case when SRC.QLTY_TEST= '||'Fail' ||'then 1 else 0 end) as Fails
from "DV2_OBIADM".IM_LUT_ENTITY_SOFT_RULES EN, ' ||DQEntity|| ' SRC
WHERE EN.ENTITY_NAME = ' || DQEntity || '
GROUP BY SRC.SRC_SYS_ID, EN.ENTITY_NAME, EN.SOFT_RULE_NAME,(to_date(to_char(SRC.LDTS,'||'DD-MM-YY'||'))) ' ;
compte := compte -1;
if compte >= 1 then
DynSQL := DynSQL ||chr(13)||chr(10)|| ' UNION ALL ';
end if;
end loop;
finale := createview || DynSQL;
finale := finale|| ');';
dbms_output.put_line(finale);
end;
谢谢您的帮助!
答案 0 :(得分:1)
您可以添加行
EXECUTE IMMEDIATE finale;
输入您的代码...
答案 1 :(得分:0)
立即执行可能有助于每次执行过程中的代码。
asktom.oracle.com/pls/apex/…
https://community.oracle.com/thread/493837
https://community.oracle.com/thread/378545
此参考资料可能有助于正确理解。