How to I fix query to get rid of error ORA-00923: FROM keyword not found where expected

Posted on 2011-09-23
Last Modified: 2012-05-12
when I execute the following query:

Select count to_char(publication_date, 'DD-MON-YYYY') as count, publication_date from bib_holdings group by publication_date order by publication_date;

ERROR at line 1:
ORA-00923: FROM keyword not found where expected

What is wrong with this query?
Question by:sikyala
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 77

Accepted Solution

slightwv (䄆 Netminder) earned 250 total points
ID: 36588188
Count is a function

Select count(1), to_char(publication_date, 'DD-MON-YYYY') a from...
LVL 74

Expert Comment

ID: 36588214
there is no need to convert the date if you're going to count it, just count the date as is

Select count(publication_date) as count, publication_date from bib_holdings group by publication_date order by publication_date;


Select count(*) as count, publication_date from bib_holdings group by publication_date order by publication_date;

LVL 74

Expert Comment

ID: 36588223
note  count(*) and count(1) are equivalent,  count(*) is recommended practice by oracle

internally it will rewrite it as count(*) anyway

the difference between count(*) and count(publication_date)  is the handling of NULL values.

count(*) will count rows, regardless of whether they have nulls or not

count(publication_date) will count NOT-NULL values only

count(to_char(publication_date,'DD-MON-YYYY'))  will also count NOT_NULL values only, so the extra conversion isn't necessary
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36588277
I assumed they wanted to count the days not the time portion which is why I moved the to_char outside the count.
LVL 74

Assisted Solution

sdstuber earned 250 total points
ID: 36588327
ah, that changes the group by then too
and makes the order by tricky since the the dates will be strings

Select count(*) as count, to_char(publication_date,'dd-MON-yyyy') publication_date from bib_holdings group by to_char(publication_date,'dd-MON-yyyy')
order by to_char(publication_date,'dd-MON-yyyy')   -- this probably the wrong order by

alternately  use trunc to count by day

Select count(*) as count, trunc(publication_date) publication_date
from bib_holdings
group by trunc(publication_date)
order by trunc(publication_date)

Author Closing Comment

ID: 36588352
Thanks it worked

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  ( Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question