Home > database >  SQL Oracle - Can not create a view (ORA-00998 ERROR)
SQL Oracle - Can not create a view (ORA-00998 ERROR)

Time:05-08

I want to create view with select and count/order by. Select lonely works but when I add command CREATE VIEW pocetpresov AS it shows me a error. (ORA-00998: must name this expression with a column alias ) Where is problem please?

CREATE VIEW pocetpresov AS
SELECT mesto, COUNT( mesto ) FROM klient GROUP BY mesto
HAVING
    COUNT( mesto )> 1
ORDER BY
    mesto;

CodePudding user response:

You need to give a name to your COUNT column to get this query worked as a VIEW -

CREATE VIEW pocetpresov AS
SELECT mesto, COUNT( mesto ) cnt_mesto 
  FROM klient 
 GROUP BY mesto
HAVING COUNT( mesto )> 1
 ORDER BY mesto;

CodePudding user response:

Obviously need to alias COUNT( mesto ) which appears on the select list( you must use aliases if the query contains expressions rather than only column names from the documentation ) – Barbaros Özhan 30 mins ago

  • Related