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
510 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
[X]
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
6 Comments
 
LVL 77

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 74

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 74

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL: ORA-00979: not a GROUP BY expression 3 82
oracle query 3 35
Using Sum with Case When within a query 9 48
Oracle SQL Developer equivalent MS SQL 6 35
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

738 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