我尝试使用过程创建实例化视图,但是做错了什么。 我需要这样做,因为我将在服务器上安排作业。 例... 我的脚本是:
create or replace procedure proc_teste_delago
is
begin
execute immediate 'create materialized view mv_test01
refresh force on demand
as
select
campo1,
campo2,
(case campo3
when 'aa' then 'AA'
when 'xx' then 'XX'
when 'ym' then 'YM'
else
'OO' as campo4
from mv_table01_test'
end;
收到的错误是: ORA-06550:linha 2,coluna 7: PLS-00905:对象PROC_TESTE_DELAGO无效 ORA-06550:linha 2,coluna 7: PL / SQL:语句被忽略
一些帮助会很好。 观察员:这是我第一次与Oracle合作。
答案 0 :(得分:3)
q'[ create materialized view ... end; ]'
(这样一来,您无需更改所有引号)不要忘了在此出色字符串的末尾添加分号 准备立即执行:
请勿为文字'00'别名(as campo4
)
结束case语句,并为其加上别名(end) campo3
)
create or replace procedure proc_teste_delago
is
begin
execute immediate 'create materialized view mv_test01
refresh force on demand
as
select
campo1,
campo2,
(case campo3
when ''aa'' then ''AA''
when ''xx'' then ''XX''
when ''ym'' then ''YM''
else
''OO''
end) campo3
from mv_table01_test';
end;
答案 1 :(得分:0)
总是最好使用备用报价机制,变得更容易理解。 https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements003.htm#SQLRF00218
CREATE OR REPLACE PROCEDURE proc_teste_delago
IS
BEGIN
EXECUTE IMMEDIATE q'{CREATE MATERIALIZED VIEW mv_test01
REFRESH
FORCE
ON DEMAND
AS
SELECT
campo1,
campo2,
(
CASE campo3
WHEN 'aa' THEN 'AA'
WHEN 'xx' THEN 'XX'
WHEN 'ym' THEN 'YM'
ELSE 'OO'
END
) AS campo4
FROM
mv_table01_test}';
END;
/
Procedure PROC_TESTE_DELAGO compiled
此外,您可以将案例表达式简化为
CASE
WHEN campo3 IN ('aa','xx','ym') THEN upper(campo3)
ELSE '00'
END