我有这个PL / SQL块,每次运行它时都会创建一个视图。 我想将其更改为名称为“ VIEW_PROC”的存储过程,因此我每次创建视图时都只需要运行proc。 我该怎么做?
set serveroutput on
declare
compte number;
DQEntity varchar2(50);
DynSQL varchar2(4000);
finale varchar2(4000);
v1 varchar2(40):='''DD-MM-YY''';
createview varchar2(4000) := 'CREATE OR REPLACE FORCE EDITIONABLE VIEW "DV2_OBIDMT"."F_GENERAL_DATA_QLTY3" ("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
SRC.SRC_SYS_ID,
EN.SOFT_RULE_NAME,
EN.ENTITY_NAME,
(to_date(to_char(SRC.LDTS,'||v1||'))) 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,'||v1||'))) ' ;
compte := compte -1;
if compte >= 1 then
DynSQL := DynSQL ||chr(13)||chr(10)|| ' UNION ALL ';
end if;
end loop;
finale := createview || DynSQL;
finale := finale|| ')';
execute immediate finale;
end;
谢谢您的帮助!
答案 0 :(得分:1)
这是用于创建存储过程的代码:
create or replace procedure VIEW_PROC is
compte number;
DQEntity varchar2(50);
DynSQL varchar2(4000);
finale varchar2(4000);
v1 varchar2(40):='''DD-MM-YY''';
createview varchar2(4000) := 'CREATE OR REPLACE FORCE EDITIONABLE VIEW "DV2_OBIDMT"."F_GENERAL_DATA_QLTY3" ("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
SRC.SRC_SYS_ID,
EN.SOFT_RULE_NAME,
EN.ENTITY_NAME,
(to_date(to_char(SRC.LDTS,'||v1||'))) 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,'||v1||'))) ' ;
compte := compte -1;
if compte >= 1 then
DynSQL := DynSQL ||chr(13)||chr(10)|| ' UNION ALL ';
end if;
end loop;
finale := createview || DynSQL;
finale := finale|| ')';
execute immediate finale;
end VIEW_PROC;
首先,您必须添加create or replace procedure VIEW_PROC is
,删除declare
,并在末尾的VIEW_PROC
关键字后添加过程名称END
。