我得到了这个Oracle视图:
CREATE OR REPLACE VIEW "VALIDA_CADVEN_VIEW" ("SETOR_INI", "NOME_REP_INI", "RE_REP_INI", "TARGET_REP_INI", "SETOR_FIM", "NOME_REP_FIM",
"RE_REP_FIM", "TARGET_REP_FIM", "Situacao", "Causa") AS
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'Não existe no arquivo atual' Situacao, 'Arquivo' Causa
FROM ZCADVEN_INI I
LEFT JOIN (SELECT * FROM ZCADVEN_FIM WHERE RE_REP IS NOT NULL ) f
ON I.RE_REP = F.RE_REP
WHERE F.RE_REP IS NULL
AND I.RE_REP IS NOT NULL
UNION
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'Não existe no arquivo anterior' Situacao, 'Arquivo' Causa
FROM ZCADVEN_FIM F
LEFT JOIN (SELECT * FROM ZCADVEN_INI WHERE RE_REP IS NOT NULL ) I
ON I.RE_REP = F.RE_REP
WHERE I.RE_REP IS NULL
AND F.RE_REP IS NOT NULL
UNION
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'Há divergências' Situacao, 'Target' Causa
FROM ZCADVEN_FIM F
INNER JOIN (SELECT * FROM ZCADVEN_INI WHERE RE_REP IS NOT NULL ) I
ON I.RE_REP = F.RE_REP
WHERE I.TARGET_REP <> F.TARGET_REP
UNION
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'Há divergências' SITUACAO, 'Nome' CAUSA
FROM ZCADVEN_FIM F
INNER JOIN (SELECT * FROM ZCADVEN_INI WHERE RE_REP IS NOT NULL ) I
ON I.RE_REP = F.RE_REP
WHERE I.NOME_REP <> F.NOME_REP
UNION
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'Há divergências' Situacao, 'Setor' Causa
FROM ZCADVEN_FIM F
INNER JOIN (SELECT * FROM ZCADVEN_INI WHERE RE_REP IS NOT NULL ) I
ON I.RE_REP = F.RE_REP
WHERE I.SETOR <> F.SETOR
UNION
SELECT I.SETOR, I.NOME_REP, I.RE_REP, I.TARGET_REP,
F.SETOR, F.NOME_REP, F.RE_REP, F.TARGET_REP, 'OK' Situacao, '-' Causa
FROM ZCADVEN_FIM F
INNER JOIN ZCADVEN_INI I
ON I.RE_REP = F.RE_REP
AND I.SETOR = F.SETOR
AND I.NOME_REP = F.NOME_REP
AND I.TARGET_REP = F.TARGET_REP
现在,在某些时候我需要做这个简单的SELECT
:
SELECT CAUSA FROM VALIDA_CADVEN_VIEW
我收到了这个错误:
ORA-00904: "CAUSA": "%s: invalid identifier"
我做错了什么想法?
谢谢。
答案 0 :(得分:4)
由于您使用双引号创建了带有“Causa”的视图,因此案例非常重要。你必须这样做:
SELECT "Causa" FROM valida_cadven_view;
我建议您使用大写标识符重新创建视图。要么取消双引号,要么将标识符设为大写:
CREATE OR REPLACE VIEW VALIDA_CADVEN_VIEW
(SETOR_INI, NOME_REP_INI, RE_REP_INI, TARGET_REP_INI, SETOR_FIM
, NOME_REP_FIM, RE_REP_FIM, TARGET_REP_FIM, Situacao, Causa) AS
或
CREATE OR REPLACE VIEW "VALIDA_CADVEN_VIEW"
("SETOR_INI", "NOME_REP_INI", "RE_REP_INI", "TARGET_REP_INI", "SETOR_FIM"
, "NOME_REP_FIM", "RE_REP_FIM", "TARGET_REP_FIM", "SITUACAO", "CAUSA") AS
除非您有非常令人信服的理由在标识符中使用小写,否则我建议您不要使用它们。正如你所看到的,它们是混乱的主要根源。