当我为以下视图运行脚本时,出现此错误:
错误报告-
ORA-00936:缺少表达式
00936. 00000-“缺少表达式”
*原因:
*动作:
脚本:
CREATE OR REPLACE VIEW mainUser.studentData_view
(
StudentID,
StudentName,
StudentDOB,
StudentSubjectID,
SubjectName,
LastUpdated)
AS
SELECT student.StudentID,
student.StudentName,
student.StudentDOB,
student.StudentSubjectID,
subject.SubjectName,
audit.SYSTIMESTAMP
FROM mainuser.studentdata student,
mainuser.studentdatachanges audit,
mainuser.subjectdata subject
WHERE student.StudentSubjectID = subject.SubjectID
AND AUD.systimestamp = (SELECT Max(SYSTIMESTAMP)
FROM mainuser.studentdatachanges AUD2
WHERE AUD2.NEW_StudentID = AUD.new_studentid);
答案 0 :(得分:0)
您应该使用显式连接语法(JOIN
关键字),这样可以使所有内容更加清晰。具有显式联接的查询如下所示:
SELECT ... --Removed to shorten query
FROM mainUser.studentData student
JOIN mainUser.studentDataChanges audit --Missing join predicate
JOIN mainUser.subjectData subject ON student.StudentSubjectID = subject.SubjectID
WHERE AUD.SYSTIMESTAMP = (SELECT MAX(SYSTIMESTAMP)
FROM mainUser.studentDataChanges AUD2
WHERE AUD2.NEW_StudentID = AUD.NEW_StudentID);
这里需要注意的几件事:
studentDataChanges
的别名为audit
,然后称为AUD
。需要选择两个之一studentDataChanges
缺少连接谓词(也许AUD.StudentID = student.StudentID
吗?)它看起来像这样:
SELECT ...
FROM mainUser.studentData student
JOIN mainUser.studentDataChanges AUD ON AUD.StudentID = student.StudentID
JOIN mainUser.subjectData subject ON student.StudentSubjectID = subject.SubjectID
WHERE AUD.SYSTIMESTAMP = (SELECT MAX(SYSTIMESTAMP)
FROM mainUser.studentDataChanges AUD2
WHERE AUD2.NEW_StudentID = AUD.NEW_StudentID);