Oracle SQL Create View无效标识符

时间:2013-04-24 19:32:57

标签: sql oracle view

我需要创建视图,我基本上必须将三个表组合在一起才能查看联系人上次验证的时间。这是我到目前为止的代码:

CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL, 
       OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE, 
       OC.LAST_DATE_VERIFIED AS VERIFIED_ON
  FROM P_OWNER OW 
  LEFT JOIN P_OWNERCONTACT OC 
            ON OW.OWNERID = OC.OWNERID
  LEFT JOIN P_OWNERPHONE OP
            ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE VERIFIED_ON IS NULL OR 
      VERIFIED_ON > SYSDATE-365
ORDER BY LASTNAME;

我不断收到此错误,无法弄清楚原因。

Error at Command Line:10 Column:7
Error report:
SQL Error: ORA-00904: "VERIFIED_ON": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

如果有人能提供帮助,我会非常感激。

1 个答案:

答案 0 :(得分:1)

您在verified_on子句中使用where。我认为你需要last_date_verified代替:

CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT 
OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL, 
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE, 
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW LEFT JOIN P_OWNERCONTACT OC 
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
    ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE OC.LAST_DATE_VERIFIED IS NULL OR 
OC.LAST_DATE_VERIFIED > SYSDATE-365
ORDER BY LASTNAME;

您不能使用select子句中where子句中定义的列别名。