尝试使用内部联接创建视图时出现错误:
CREATE OR REPLACE VIEW lab3view3
AS
SELECT
f.firstname,
f.lastname,
s.firstname,
s.lastname,
c.coursename,
sec.days,
TO_CHAR (sec.starttime, 'MM/DD/YYYY') AS startdate,
TO_CHAR(sec.starttime, 'HH:MI AM ') AS starttime,
TO_CHAR(sec.endtime, 'MM/DD/YYYY') AS enddate,
TO_CHAR(sec.endtime, 'HH:MI AM ') AS endtime,
sec.sectionid,
l.building,
l.room,
g.grade
FROM section sec
INNER JOIN grade g
ON g.sectionid = sec.sectionid
INNER JOIN course c
ON c.courseid = sec.courseid
INNER JOIN location l
ON l.locationid = sec.locationid
INNER JOIN student s
ON s.studentid = g.studentid
INNER JOIN instructor i
ON i.sectionid = sec.sectionid
INNER JOIN faculty f
ON f.facultyid = i.facultyid
INNER JOIN section sec
ON sec.sectionid = g.sectionid;
继续收到此错误:
第1行的错误;
ORA-00918:列模糊定义
有关如何解决此问题的任何想法?
答案 0 :(得分:2)
您还需要使用正确的表格在TO_CHAR
(starttime
和endtime
)调用中为时间加前缀。您还要从不同的表中选择firstname
和lastname
两次,第二个将重命名为,因为您正在创建它们,所以必须重命名它们一个观点,请参阅@ sstan的答案。firstname_1
然后
答案 1 :(得分:1)
@ maraca的回答是正确的。但是一旦你修复了模糊定义的列错误,你就会得到
ORA-00957:重复的列名
创建视图时,每个选定的列都需要具有唯一的名称。确保相应地在select
子句中对重复的列名称进行别名。
示例:
CREATE OR REPLACE VIEW lab3view3
AS
SELECT faculty.firstname as faculty_firstname,
faculty.lastname as faculty_lastname,
student.firstname as student_firstname,
student.lastname as student_lastname,
...