我是sql的新手。我正在尝试运行以下查询
Create view ReturnCode as
(
select ret_code, to_char(creation_dt,'DD-MON-YYYY HH24:MI:SS')“Created_Date”,current_timestamp,buff.log.*
from buff.log
WHERE ret_Code= '90'
order by creation_dt
);
获取错误
must name this expression with a column alias
请帮助我在这里失踪
答案 0 :(得分:1)
您必须在视图中为current_timestamp
添加一个列名称。
隔离错误使其更加明显:
SQL> create view v1 as select current_timestamp from emp;
create view v1 as select current_timestamp from emp
*
ERROR at line 1:
ORA-00998: must name this expression with a column alias
(SQL * Plus甚至会向您显示必须命名的WHICH表达式 - 如果您使用的是SQL * Plus,它将在您的视图定义中执行相同的操作。)
为此表达式添加列名称:
SQL> create view v1 as select current_timestamp as current_ts from emp;
View created.
答案 1 :(得分:0)
使用此:
CREATE VIEW ReturnCode
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
);