获取SQL错误:ORA-00957:创建视图时重复列名称

时间:2013-03-25 10:23:00

标签: sql oracle11g

我正在尝试制作视图,但是我收到了重复的列名错误。如果我单独运行select查询,则查询返回如下结果:

SELECT distinct app.APP_REF_NO, app.APP_STATUS, app.APP_DT, app.ATTEND_STAFF,
                app.ATTEND_BRANCH, app.PRODUCT_TYPE, cust.CUST_ID, 
                cust.APP_JOINT_T, cust.ID1_TYPE, cust.ID1, cust.ID2_TYPE, 
                cust.ID2, cust.FIRST_NAME, cust.LAST_NAME, cust.FULL_NAME, 
                cust.FULL_NAME_CAP, cust.DOB, fac.FACILITY_NO, fac.PRODUCT_TYPE,
                fac.PRODUCT_CODE, fac.MAIN_PROD_IND, fac.AMT_APPLIED
FROM 
    LOSA_APP app 
LEFT JOIN 
    LOSA_CUST cust 
ON
    cust.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
   LOSA_FACILITIES fac 
ON
    fac.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
    OS_CURRENTSTEP STEP 
ON
    STEP.REF_ID = app.APP_REF_NO
   WHERE (app.APP_STATUS ='P' OR app.APP_STATUS ='T' OR 
         ((app.APP_STATUS='R' OR app.APP_STATUS='S') AND STEP.STEP_NAME='011'));

此查询正常。但是,当我尝试将其作为一个视图运行时:

CREATE VIEW basit_test1 AS
SELECT distinct app.APP_REF_NO, app.APP_STATUS, app.APP_DT, app.ATTEND_STAFF,
                app.ATTEND_BRANCH, app.PRODUCT_TYPE, cust.CUST_ID, 
                cust.APP_JOINT_T, cust.ID1_TYPE, cust.ID1, cust.ID2_TYPE, 
                cust.ID2, cust.FIRST_NAME, cust.LAST_NAME, cust.FULL_NAME, 
                cust.FULL_NAME_CAP, cust.DOB, fac.FACILITY_NO, fac.PRODUCT_TYPE,
                fac.PRODUCT_CODE, fac.MAIN_PROD_IND, fac.AMT_APPLIED
FROM 
    LOSA_APP app 
LEFT JOIN 
    LOSA_CUST cust 
ON
    cust.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
   LOSA_FACILITIES fac 
ON
    fac.APP_REF_NO = app.APP_REF_NO
LEFT JOIN 
    OS_CURRENTSTEP STEP 
ON
    STEP.REF_ID = app.APP_REF_NO
   WHERE (app.APP_STATUS ='P' OR app.APP_STATUS ='T' OR 
         ((app.APP_STATUS='R' OR app.APP_STATUS='S') AND STEP.STEP_NAME='011'));

然后我得到重复的列名称错误。为什么我会收到此错误?

1 个答案:

答案 0 :(得分:16)

您有两个product_type列:

fac.PRODUCT_TYPE

app.PRODUCT_TYPE

你应该为其中一个别名,例如

app.PRODUCT_TYPE app_prod_type