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

Sub*_*ash 0 sql oracle

这与我在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;
Run Code Online (Sandbox Code Playgroud)

Ale*_*sej 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;
Run Code Online (Sandbox Code Playgroud)

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

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

或者,更好地,显式写入列名而不是使用*:

  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,
       ...
Run Code Online (Sandbox Code Playgroud)