SELECT ac.ac_id,
  clnt.clnt_class_cde,
  en.enty_typ, en.id_typ, 
nvl(ac.ovrided_ac_nam, en.mis_cust_nam) name,
addr.has_prc_id, 
addr.has_prc_addr,
nvl(sus_ac.total,0) suspend_total, 
mc.AC_ID,
  mc.DAY_OF_MRGN_CALL,
  mc.DAY_OF_MRGN_CALL2,
  mc.INSUFFICIENT_AMT, 
  mc.MRGN_REQ, 
  mc.MRGN_CALL_AMT, 
  flmt.offl_expur_lmt, 
  nvl(repay.RPYMT_ID, 0),
  mr.MRKT_GRP_ID,
  mr.MC_AC_MRGN_PSTR, 
  mr.mamount
FROM cc_ac ac
        inner join MC_AC_MRGN_CALL_DSP mc 
              on  ac.ac_id = mc.AC_ID
        inner join cc_clnt clnt 
              on ac.primy_clnt_id = clnt.clnt_id AND clnt.entrp_cde = ac.entrp_cde
        inner join cc_enty en 
              on en.enty_seq = clnt.enty_seq
        inner join cc_clnt_fincl_lmt flmt 
              on flmt.clnt_id = clnt.clnt_id
        inner JOIN (SELECT primy_clnt_id, COUNT(*) TOTAL 
          FROM cc_ac 
          WHERE ac_stat='SUSPENDED' GROUP BY primy_clnt_id) sus_ac 
      ON clnt.clnt_id = primy_clnt_id
        inner JOIN cc_clnt_addr addr ON clnt.clnt_id = addr.clnt_id 
        AND clnt.entrp_cde = addr.entrp_cde
        inner JOIN MC_RPYMT repay 
              ON repay.AC_ID = ac.ac_id
        inner JOIN (SELECT mgroupMem.MRKT_GRP_ID, 
rmAcct.PSTR_SEQ, 
rmAcct.PSTR, 
margin.AC_ID, 
(margin.INIT_MRGN * exr.MID_RATE) mamount
   FROM MC_AC_MRGN_PSTR rmAcct, 
    MC_AC_MRGN margin, 
    MC_MRKT_GRP mgroupMem, 
    MC_EXCH_RATE exr
   WHERE rmAcct.AC_MRGN_ID = margin.AC_MRGN_ID
AND margin.MRKT_ID = mgroupMem.MRKT_GRP_ID
AND (mgroupMem.MRKT_GRP_ID = 1 
OR mgroupMem.MRKT_GRP_ID = 2)
AND margin.CCY_CDE = exr.CCY_CDE
AND exr.AGAINST_CCY_CDE = 'aaa'
ORDER BY mgroupMem.MRKT_GRP_ID, rmAcct.PSTR_SEQ) mr 
 ON ac.ac_id = mr.AC_ID
WHERE 
  mc.businessDate = '13-4月 -08 12.00.00.000000 上午'
          AND repay.RPYMT_EFF_DATE <= '13-4月 -08 12.00.00.000000 上午'
AND repay.RPYMT_EXPR_DATE > '13-4月 -08 12.00.00.000000 上午'
  AND ac.entrp_cde = 'TF'
  AND en.entrp_cde = ac.entrp_cde
  ORDER BY mc.AC_ID, mr.PSTR_SEQ, clnt.clnt_class_cde, en.enty_typ, en.id_typ, suspend_total
这条SQL语句出现‘ora-00918 未明确定义列’错误,请高手帮忙,急用。谢谢!

解决方案 »

  1.   

    到sqlplus下执行,看具体的报错行数
      

  2.   

    是不是最后那个列名没有指定表别名  suspend_total 
      

  3.   

    select column from table a , talbe b 
    where a.columna=b.columnb
    如果a和b都要column这一列,那么会报ora-00918 未明确定义列 
      

  4.   

    今天我也遇到了這個錯誤,是由於不小心有兩個相同的字段存在,應該重名了!
    可能要檢測相關字段是否重複,另外檢測子表或子查詢中是否存在此字段
    同時建議能不用INNER JOIN就不用!
      

  5.   

    我觉得应该是order by nvl(sus_ac.total,0),不能以字段别名作为order by的,可能是这个原因吧不妨试试看
      

  6.   


    太长了  自己在sqlplus下运行 看报错在具体哪行  仔细看字段跟下面的表  
      

  7.   

    ORDER BY mc.AC_ID, mr.PSTR_SEQ, clnt.clnt_class_cde, en.enty_typ, en.id_typ, suspend_total红色部分  自己看下就明白 
    ORDER BY mc.AC_ID, mr.PSTR_SEQ, clnt.clnt_class_cde, en.enty_typ, en.id_typ, 
    nvl(sus_ac.total,0)
      

  8.   

    ORDER BY mc.AC_ID, mr.PSTR_SEQ, clnt.clnt_class_cde, en.enty_typ, en.id_typ, suspend_total 
    --改成下面的ORDER BY mc.AC_ID, mr.PSTR_SEQ, clnt.clnt_class_cde, en.enty_typ, en.id_typ,  
    nvl(sus_ac.total,0)
      

  9.   

     ORA-00918 
    ORA-00918: column ambiguously defined 
    Cause: A column name used in a join exists in more than one table and is thus referenced ambiguously. In a join, any column name that occurs in more than one of the tables must be prefixed by its table name when referenced. The column should be referenced as TABLE.COLUMN or TABLE_ALIAS.COLUMN. For example, if tables EMP and DEPT are being joined and both contain the column DEPTNO, then all references to DEPTNO should be prefixed with the table name, as in EMP.DEPTNO or E.DEPTNO. 
    Action: Prefix references to column names that exist in multiple tables with either the table name or a table alias and a period (.), as in the examples above.  
     
    解决办法:
    因为你的列在多个表中存在,你需要在选择的列前加上表前缀以避免错误
     
      

  10.   

    重复的列,oracle不知道是那个表的,所以你要加上 别名.