0

I am a rookie in sql. I am trying to run the below query

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

Getting the error

must name this expression with a column alias

Please help what I am missing here

2
  • Unrelated, but: the parentheses around the select statement are useless. Commented Jan 25, 2017 at 13:17
  • 1
    And you need to use "straigh" double quotes " not those typographic ones: Commented Jan 25, 2017 at 13:17

2 Answers 2

1

You must give current_timestamp a column name in your view.

Isolating the error so it is more obvious:

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 even shows you exactly WHICH expression must be named - it would do the same on your view definition, if you were using SQL*Plus.)

Add a column name for this expression:

SQL> create view v1 as select current_timestamp as current_ts from emp;

View created.
Sign up to request clarification or add additional context in comments.

Comments

1

Use this :

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

4 Comments

@XING- Ha! I see you edited your post to add the correct answer (which had nothing to do with what you posted originally). When you post an incorrect or incomplete answer, then someone else posts an answer, and then you edit your own answer to add what you saw in that other answer, it is customary to ACKNOWLEDGE what you did. Anyone who cares can see the edits you made by clicking on the "edited 1 hour ago" link. Not cool!
@mathguy.. That was a miss from my side. I appreciate your answer however would like to say that even if OP will follow your stuff it wont work. You can give a try. After resolving the first part if the isue which is using CURRENT_TIMESTAMP he will face another issue which i had resolved. Am not here to do any competition with you and your answer. SO is not paying me anything. If you feel demotivated. +1 from me . Cheers. There was no reason to downvote a correct answer i guess just coz someone didnot vote you.
@XING - I don't doubt the fact that my answer will not solve all of the OP's problems; I didn't try to. If he solves the original error and runs into another one, he may be able to fix it himself, or he should post another question (since it is a very different issue). That wasn't my point though. My point was about exactly what I wrote in the COMMENT. If you use what you see in someone else's answer to change your own, you should say what you did - not leave it to the interpretation that the other answer (posted later than yours) copied what you wrote. That is what is not cool.
And regarding the downvote: it wasn't for the quality of your answer, it was for the lack of intellectual honesty. I would have used different means to express my displeasure, but I don't think there are any (short of flagging your behavior for review by the moderators, which I felt wasn't necessary in this case). My plan is to remove the downvote after you edit your answer to add this acknowledgement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.