I get that I should add alias with all the columns and I’m doing so but I’m still getting error.
CREATE TABLE MENTIONS AS SELECT
UM.USER_ID AS U_ID,
UM.SCREEN_NAME AS USER_SCREEN_NAME,
UM.MENTION_ID AS M_USER_ID,
(
SELECT
UI.USER_SCREEN_NAME AS MENTIONED_USER
FROM
USER_INFO UI
WHERE
UI.USER_ID = UM.MENTION_ID
AND ROWNUM = 1
)
FROM
USER_MENTION UM
USER_MENTION table
USER_ID SCREEN_NAME MENTION_ID
135846337 irisschrijft 774759032636727300
50117969 Chjulian 13769472
14411827 thenriques45 13769472
26681613 ahenotri 252074645
26681613 ahenotri 9796472
158378782 SpringerOpen 9796472
144241914 Kumarappan 252074645
User_INFO table:
USER_ID USER_SCREEN_NAME
22553325 jasonesummers
23435691 QRJAM false
67421923 inTELEgentMSP
97393397 knauer0x
85303739 MarriageTheorem
3842711 seki
3036414608 Bayes_Rule
838677852 BOLIGATOR
I’m still getting the above mentioned error, what am I doing wrong?
asked Feb 19, 2017 at 11:03
melissa melissa
3751 gold badge8 silver badges20 bronze badges
3
Lookup the Oracle Error Message Manual of the current Oracle version. Here the error is mentioned but without additional information.
In such a case look up the
Oracle Error Message Manual of version 9i
For reasons I don’t know a lot of error messages have a description in the 9i manual but not in the manuals of higher versions. 9i is a rather old version so the description may be out of date. But it may contain valuable hints.
ORA-00998 must name this expression with a column alias
Cause: An expression or function was used in a CREATE VIEW statement, but no corresponding column name was specified. When expressions or functions are used in a view, all column names for the view must be explicitly specified in the CREATE VIEW statement.
Action: Enter a column name for each column in the view in parentheses after the view name.
We don’t have a view but a a table that was created by a select. And actually the last expression of the select list is an expression without an alias. So try your statement using an alias for the last expression. So try
CREATE TABLE MENTIONS AS SELECT
UM.USER_ID AS U_ID,
UM.SCREEN_NAME AS USER_SCREEN_NAME,
UM.MENTION_ID AS M_USER_ID,
(
SELECT
UI.USER_SCREEN_NAME
FROM
USER_INFO UI
WHERE
UI.USER_ID = UM.MENTION_ID
AND ROWNUM = 1
) AS MENTIONED_USER
FROM
USER_MENTION UM
The column alias in the inner select list is useless and can be removed.
answered Feb 19, 2017 at 11:25
miracle173miracle173
1,83116 silver badges33 bronze badges
The problem with your query is that each column in the create table
needs to have a name. You think you are assigning a name in the sub-select. However, you are not.
The subquery is just returning a value — not a value with a name. So, the AS MENTIONED_USER
in your version does nothing. This is a bit tricky, I guess. One way to think of the scalar subquery is that it is just another expression or function call. Things that happen inside it don’t affect the outer query — except for the value being returned.
The correct syntax is to put the column alias outside the subselect, not inside it:
CREATE TABLE MENTIONS AS
SELECT UM.USER_ID AS U_ID, UM.SCREEN_NAME AS USER_SCREEN_NAME, UM.MENTION_ID AS M_USER_ID,
(SELECT UI.USER_SCREEN_NAME
FROM USER_INFO UI
WHERE UI.USER_ID = UM.MENTION_ID AND ROWNUM = 1
) AS MENTIONED_USER
FROM USER_MENTION UM;
answered Feb 19, 2017 at 12:15
Gordon LinoffGordon Linoff
1.2m57 gold badges639 silver badges781 bronze badges
ORA-00998
ORA-00998: это выражение должно называться с псевдонима
Причина:
Выражение или функция использовались операторе CREATE VIEW, но не указывалось ни одного соответствующего имени колонки. Когда выражения или функции используются в обзоре, все имена колонок для обзора должны быть явно указаны в операторе CREATE VIEW.
Действие:
Введите имя колонки для каждой колонки в обзоре в круглых скобках после имени обзора.
Oracle SQL Error: ORA-00998: must name this expression with a column alias
Cause:
An expression or function was used in a CREATE VIEW statement, but no corresponding column name was specified.
Solution:
Enter a column name for each column in the view in parentheses after the view name.
Example:
CREATE VIEW BOOKS_VIEW AS SELECT ROWID, ID, NAME FROM BOOKS;
Output:
SQL Error: ORA-00998: must name this expression with a column alias
Correct
CREATE VIEW BOOKS_VIEW AS SELECT ROWID as row_id, ID, NAME FROM BOOKS;
Output:
view BOOKS_VIEW created.
I’m working in oracle and I can’t figure out what’s wrong with this statement. The error it gives me is must name this expression with a column alias
CREATE TABLE shipping_costs_grouped AS
SELECT SUM(invoice_amt), SUM(entered_weight), SUM(billed_weight), SUM(net_amt), MAX(ZONE), pps_num
FROM shipping_costs GROUP BY pps_num;
I know it has something to do with the group by statement but I don’t know how to resolve it
asked Mar 3, 2012 at 0:31
You need to add aliases for the computed columns so that Oracle knows what names the columns of the table should have
CREATE TABLE shipping_costs_grouped
AS
SELECT SUM(invoice_amt) total_invoice_amt,
SUM(entered_weight) total_entered_weight,
SUM(billed_weight) total_billed_weight,
SUM(net_amt) total_net_amt,
MAX(ZONE) max_zone,
pps_num
FROM shipping_costs
GROUP BY pps_num;
should be valid syntax.
Whether it is actually appropriate to create a table for this sort of thing is a question you’d have to answer. My bias would be that it would be more appropriate to create a view or potentially a materialized view but I don’t know the exact nature of the problem you’re trying to solve.
answered Mar 3, 2012 at 0:44
Justin CaveJustin Cave
20.1k2 gold badges50 silver badges65 bronze badges
Posted by Matthias Rogel on 27. January 2012
Did you ever encounter
ORA-00998: must name this expression with a column alias
and wondered why ?
Doc says
Error: ORA 998 Text: must name this expression with a column alias ------------------------------------------------------------------------------- Cause: An expression or function was used in a CREATE VIEW statement, but no corresponding column name was specified. When expressions or functions are used in a view, all column names for the view must be explicitly specified in the CREATE VIEW statement. Action: Enter a column name for each column in the view in parentheses after the view name.
but that is (at most) only half the truth.
Here is my story about ORA-00998:
sokrates@11.2 > create table temp as select count(*) from dual;
create table temp as select count(*) from dual
*
ERROR at line 1:
ORA-00998: must name this expression with a column alias
sokrates@11.2 > REM must ?
sokrates@11.2 > REM I don't think so ...
sokrates@11.2 > REM let's see ...
sokrates@11.2 > create table temp as select * from (select count(*) from dual);
Table created.
sokrates@11.2 > desc temp
Name Null? Type
----------------------------------------- -------- ----------------------------
COUNT(*) NUMBER
sokrates@11.2 > REM hehe !
sokrates@11.2 > select "COUNT(*)" from temp;
COUNT(*)
----------
1
sokrates@11.2 > CREATE VIEW test_v AS
2 SELECT owner || '.' || table_name
3 FROM all_tables
4 WHERE owner = USER;
SELECT owner || '.' || table_name
*
ERROR at line 2:
ORA-00998: must name this expression with a column alias
sokrates@11.2 > create view test_v as
2 select * from (
3 SELECT owner || '.' || table_name
4 FROM all_tables
5 WHERE owner = USER
6 );
View created.
sokrates@11.2 > desc test_v
Name Null? Type
----------------------------------------- -------- ----------------------------
OWNER||'.'||TABLE_NAME VARCHAR2(61)
sokrates@11.2 > select "OWNER||'.'||TABLE_NAME" from test_v where rownum=1;
OWNER||'.'||TABLE_NAME
-------------------------------------------------------------
SOKRATES.T
🙂
This entry was posted on 27. January 2012 at 13:13 and is filed under sql.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.