From keyword not found where expected oracle ошибка

    select 
      country_olympic_name, 
      SUM(part_gold) as 'Number of Gold Medals'
    From
      games.country,
      games.participation
   where
      participation.country_isocode = country.country_isocode
   group by
      country_olympic_name;

I have been getting the error ORA-00923: FROM keyword not found where expected and do not know why, please help

asked Sep 16, 2013 at 14:34

user2784327's user avatar

1

Identifiers need to be quoted with double quotes ("). Single quotes (') denote a character value (not a «name»).

Therefor you need to use:

SUM(part_gold) as "Number of Gold Medals"

More details in the manual:

  • Database Object Names and Qualifiers
  • Text literals

answered Sep 16, 2013 at 14:35

a_horse_with_no_name's user avatar

0

Add comma after SELECT QUERY


In my case, I had this query

SELECT BANK_NAME
DECODE (SWIFT_CODE, 'BRDEROBU', 'BRD',
                   'NO RESULT') RESULT
FROM BANK_GAR;

As you may see, I didn’t had the comma after the SELECT BANK_NAME line.

The correct query is:

SELECT BANK_NAME,
DECODE (SWIFT_CODE, 'BRDEROBU', 'BRD',
                   'NO RESULT') RESULT
FROM BANK_GAR;

answered Jun 23, 2020 at 20:21

Gabriel Arghire's user avatar

Gabriel ArghireGabriel Arghire

1,8731 gold badge19 silver badges34 bronze badges

0

Check reserved words. This was my issue. For whatever reason using «size» as a column alias caused oracle to spit that exact error out and it had me scratching my head for a while.

select 1 size, 1 id from dual

answered Dec 12, 2020 at 2:04

user239512's user avatar

You may try doing this:-

select 
  country_olympic_name, 
  SUM(part_gold) as "Number of Gold Medals"
From
  games.country,
  games.participation
where
  participation.country_isocode = country.country_isocode
group by
  country_olympic_name;

answered Sep 16, 2013 at 14:37

Rahul Tripathi's user avatar

Rahul TripathiRahul Tripathi

167k31 gold badges277 silver badges331 bronze badges

Try this…

SELECT
      COUNTRY_OLYMPIC_NAME,
      SUM ( PART_GOLD ) AS NUMBER_OF_GOLD_MEDALS
FROM
      GAMES.COUNTRY,
      GAMES.PARTICIPATION
WHERE
      PARTICIPATION.COUNTRY_ISOCODE = COUNTRY.COUNTRY_ISOCODE
GROUP BY
      COUNTRY_OLYMPIC_NAME;

answered Sep 16, 2013 at 14:37

Srini V's user avatar

Srini VSrini V

11k14 gold badges66 silver badges89 bronze badges

1

Similar error will be their when you have invalid select columns like below.
try below SQL and see yourself.

SELECT
    1 ,
    2 ,
    S /*FF               */
    NULL,
    4 ,
    /*FF       */
    NULL,
    /*FF        */
    NULL,
    /*FF                */
FROM
    dual;

answered Dec 10, 2022 at 12:59

Vaibs's user avatar

VaibsVaibs

2,00822 silver badges29 bronze badges

ORA-00923

ORA-00923: ключевое слово FROM не было найдено, где оно ожидалось

Причина:

В операторах SELECT или REVOKE ключевое слово FROM скорее всего пропущено, неправильно размещено, или неправильно написано. Ключевое слово FROM должно сопровождаться последним элементом в SELECT операторе, или привилегией в REVOKE операторе.

Действие:

Вставьте ключевое слово FROM где это следует. Выбранный вами список сам по себе может быть ошибочным.

      SELECT TITLE, CONCAT(TO_CHAR(SUM((COST-RETAIL)/COST)*100), '100'), '%') 
      AS "Markup"
      FROM BOOKS
      GROUP BY TITLE; 

::THE GOAL::
I’m trying to calculate the mark-up for my products (books).

::ZE PROBLEM::
When I try to run the stated SQL, I get the error

ORA-00923: FROM keyword not found where expected

In advance I thank you for any and all input on my issue.

marc_s's user avatar

marc_s

728k174 gold badges1326 silver badges1455 bronze badges

asked Mar 21, 2013 at 12:50

Tas's user avatar

1

Your parentheses are not balanced I count 4 left and 5 right. This error usually happens when there is a formatting error that prevents the FROM clause from being reached (missing/extra comma, unbalanced bracket, etc)

answered Mar 21, 2013 at 12:55

munch1324's user avatar

munch1324munch1324

1,1485 silver badges10 bronze badges

  SELECT TITLE, TO_CHAR( SUM( COST-RETAIL )/ SUM( COST )) || '%'
      AS "Markup"
      FROM BOOKS
      GROUP BY TITLE; 

answered Mar 21, 2013 at 13:00

Randy's user avatar

RandyRandy

16.5k1 gold badge37 silver badges55 bronze badges

1

There was an extra right parentheses and here is what it should look like.

SELECT TITLE, CONCAT(TO_CHAR(SUM((COST-RETAIL/COST)*100), '100'), '%') 
AS "Markup"
FROM BOOKS
GROUP BY TITLE;

answered Mar 21, 2013 at 13:01

Joe W's user avatar

Joe WJoe W

1,7602 gold badges28 silver badges37 bronze badges

2

The ORA-00923: FROM keyword not found where expected error occurs when the FROM keyword is missing, misspelled, or misplaced in the Oracle SQL statement such as select or delete. The FROM keyword is used to identify the table name. If an error occurs when checking for the FROM keyword, the table name cannot be found. If the the FROM keyword is missing from the SQL query, misspelled, or misplaced in the select statement, Oracle parser will fail to detect the FROM keyword. If the FROM keyword is not found where it should be, an error message ORA-00923: FROM keyword not found where expected will be displayed.

The FROM keyword is used in the select statement to specify the table or view name. The select statement could not identify the table names if the FROM keyword was missing, misspelled, or misplaced. The issue is caused by the FROM keyword or the code written before the FROM keyword. The issue ORA-00923: FROM keyword not found where expected will be fixed if you rewrite the select query along with the FROM keyword.

When this ORA-00923 error occurs

The error will occur in the Oracle database if the FROM keyword is missing, misspelled, or misplaced in the select statement. The error will occur if there are any errors in the code written before the FROM keyword. If you examine the sql query in and around the FROM keyword, you may be able to rectify the error.

select id,name emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"
*Cause:    
*Action:
Error at Line: 9 Column: 18

Root Cause

The FROM keyword will be used in the select statement to specify the table or view name from which the data will be retrieved. If the FROM keyword is missing, misplaced, or misspelled in the select statement, the table name cannot be identified. In this example, the select statement expects the presence of a FROM keyword in the query. As a result, an Oracle error “ORA-00923: FROM keyword not found where expected” will be thrown.

Solution 1

If the FROM keyword is not present in the select statement, it should be added before the table or view name. The select statement reads the table or view name and retrieves data from it. Check that the FROM keyword is present in the select query.

Problem

select id,name emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id,name FROM emp;

Solution 2

Oracle will give an error if the FROM keyword in the select statement is misspelled. The FROM keyword was not found in the query, thus the select statement failed. In this scenario, the table or view name could not be discovered. The FROM keyword must be properly written. The FROM keyword is case insensitive.

Problem

select id,name FRM emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id,name FROM emp;

Solution 3

If the FROM keyword is misplaced in the select statement, an error notice will be produced. The FROM keyword should come before the table or view name and after the list of column names. If the FROM keyword is used in combination with the name of a column, Oracle will consider the FROM keyword to be one of the columns and will expect the FROM keyword to identify the table or view name.

Problem

select id,name, FROM emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id,name FROM emp;

Solution 4

If there is a mistake in the list of column names in the select statement, an error message will be displayed. Oracle will treat the error in the column list and expects the FROM keyword in the select statement to specify the table or view name. The column name contains a space in between and no double quotes is used to the column name.

Problem

select id, name as senior manager from emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id, name as "senior manager" from emp;

Solution 5

The error will be thrown if the column name is identified with a single quotation. The column name should be included in double quotation marks. The issue may be fixed by changing the single quotation to a double quotation. In Oracle, a single quote will be used to identify the string value or date value. In the column names, a double quotation should be utilized.

Problem

select id, name as 'senior manager' from emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id, name as "senior manager" from emp;

Solution 6

The from keyword error happens in the Oracle database if any of the oracle keywords is used as the column names in the select statement. The keyword should not be used as the name of a column. The issue may be fixed by deleting the keyword from the column name.

Problem

select id as size from emp;

ORA-00923: FROM keyword not found where expected
00923. 00000 -  "FROM keyword not found where expected"

Solution

select id as size_ from emp;

You need an alias for both derived tables. And the outer pair around the from clause is useless.

SELECT DISTINCT t1.unique_id AS uid, t1.confidence_is_same
FROM ( --<< only one opening parenthesis
  SELECT unique_id,
         confidence_is_same,
         first_name,
         last_name,
         postal_code
  FROM daniel.unique_physician
  WHERE daniel.unique_physician.first_name = ''
  AND   daniel.unique_physician.last_name = ''
  AND   daniel.unique_physician.is_root_phys = 0
  AND   daniel.unique_physician.postal_code = ''
) t1 ---<< the alias for the derived table is missing
  INNER JOIN (
    SELECT max(confidence_is_same) OVER (PARTITION BY root_id) max_conf
    FROM daniel.unique_physician
    WHERE daniel.unique_physician.first_name = ''
    AND   daniel.unique_physician.last_name = ''
    AND   daniel.unique_physician.is_root_phys = 0
    AND   daniel.unique_physician.postal_code = ''
  ) t2 ON t1.confidence_is_same = t2.max_conf

But the join isn’t needed in the first place. Your query can be simplified to:

SELECT DISTINCT t1.unique_id AS uid, t1.confidence_is_same
FROM (
  SELECT unique_id,
         confidence_is_same,
         max(confidence_is_same) OVER (PARTITION BY root_id) max_conf
  FROM daniel.unique_physician unq
  WHERE unq.first_name = ''
  AND   unq.last_name = ''
  AND   unq.is_root_phys = 0
  AND   unq.postal_code = ''
) t1
where confidence_is_same = max_conf;

You don’t need to select first_name, last_name and postal_code in the inner select as you don’t use them in the outer select. This can make the query potentially more efficient.

Additionally, the condition unq.last_name = '' won’t do what you think it does. Oracle does not have an «empty string». A string with length zero ('') will be stored as NULL, so what you really want is probably:

SELECT DISTINCT t1.unique_id AS uid, t1.confidence_is_same
FROM (
  SELECT unique_id,
         confidence_is_same,
         max(confidence_is_same) OVER (PARTITION BY root_id) max_conf
  FROM daniel.unique_physician unq
  WHERE unq.first_name is null
  AND   unq.last_name is null
  AND   unq.is_root_phys = 0
  AND   unq.postal_code is null
) t1
where confidence_is_same = max_conf;

Понравилась статья? Поделить с друзьями:

Не пропустите эти материалы по теме:

  • Яндекс еда ошибка привязки карты
  • Fr 041 ошибка актрос
  • From imageai detection import objectdetection ошибка
  • From flask import flask ошибка
  • Fr 04041 ошибка актрос

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии