ORA-00918:在内连接上模糊定义的列

时间:2016-07-31 02:08:22

标签: oracle

尝试使用内部联接创建视图时出现错误:

    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:列模糊定义

有关如何解决此问题的任何想法?

2 个答案:

答案 0 :(得分:2)

您还需要使用正确的表格在TO_CHARstarttimeendtime)调用中为时间加前缀。您还要从不同的表中选择firstnamelastname两次,第二个将重命名为firstname_1然后,因为您正在创建它们,所以必须重命名它们一个观点,请参阅@ sstan的答案。

答案 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,
...