0

我得到了这个 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"

关于我做错了什么的任何想法?

谢谢你。

4

1 回答 1

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 

除非您有真正令人信服的理由在标识符中使用小写字母,否则我建议您不要使用它们。如您所见,它们是造成混乱的主要来源。

于 2012-07-22T17:50:40.353 回答