创建视图时出现重复的列名称错误

时间:2017-01-25 16:08:20

标签: sql oracle

这与我在Getting Error while creating a view in oracle DB

的问题有关

我尝试了以下内容,但在第6行获取重复的错误列

CREATE VIEW ReturnCode90
AS
  SELECT t.ret_code,
       TO_CHAR (t.creation_dt, 'DD-MON-YYYY HH24:MI:SS') Created_Date,
       CURRENT_TIMESTAMP Curr_tmp,
       t.* 
  FROM buff.log t
  WHERE t.ret_Code = '90' 
 order by t.creation_dt desc;

1 个答案:

答案 0 :(得分:5)

您正在创建一个具有相同列ret_code两次的视图;如果您在视图中两次出现相同的列,则需要为两次出现之一使用别名:

CREATE VIEW ReturnCode90
AS
  SELECT t.ret_code as someAlias,
       TO_CHAR (t.imx_creation_dt, 'DD-MON-YYYY HH24:MI:SS') Created_Date,
       CURRENT_TIMESTAMP Curr_tmp,
       t.* 
  FROM imxbuff.bank_imx_pmt_head t
  WHERE t.ret_Code = '90' 
 order by t.imx_creation_dt desc;

如果您不想这样做,可以从选择列表中删除该列

SELECT TO_CHAR (t.imx_creation_dt, 'DD-MON-YYYY HH24:MI:SS') Created_Date,
       CURRENT_TIMESTAMP Curr_tmp,
       t.*

或者,更好的是,明确地编写列名而不是使用*

  SELECT t.ret_code,
       TO_CHAR (t.imx_creation_dt, 'DD-MON-YYYY HH24:MI:SS') Created_Date,
       CURRENT_TIMESTAMP Curr_tmp,
       t.otherColumn1,
       t.otherColumn2,
       ...