Solved

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

Posted on 2011-09-23
6
497 Views
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?
0
Comment
Question by:sikyala
  • 3
  • 2
6 Comments
 
LVL 76

Accepted Solution

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

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

Expert Comment

by:sdstuber
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;

or

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

0
 
LVL 73

Expert Comment

by:sdstuber
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 76

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.
0
 
LVL 73

Assisted Solution

by:sdstuber
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)
0
 

Author Closing Comment

by:sikyala
ID: 36588352
Thanks it worked
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now