小编典典

出现SQL错误:ORA-00957:创建视图时重复的列名

sql

我正在尝试进行查看,但是出现重复的列名错误。如果我单独运行选择查询,则查询返回的结果如下:

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'));

然后,我得到重复的列名错误。为什么会出现此错误?


阅读 41

收藏
2021-04-07

共1个答案

小编典典

您有两product_type列:

fac.PRODUCT_TYPE

app.PRODUCT_TYPE

您应该别名其中之一,例如

app.PRODUCT_TYPE app_prod_type
2021-04-07