Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > ORA-00936 with Oracle script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-08, 08:49
straygrey straygrey is offline
Registered User
 
Join Date: Oct 2008
Location: Midrand, South Africa
Posts: 5
ORA-00936 with Oracle script

When run the following script returns an ORA-00936 missing expression error.
Code:
select mem_number AS MemNumber, sum(trans_turnover) AS Turnover from members join transact on mem_number = trans_code where Trans_date between '01-Jan-2004' and '09-Oct-2008' and mem_barred = 0 group by mem_number, order by turnover desc ) where rownum <=200;

Please tell me what I have done wrong and how do I fix this.
Reply With Quote
  #2 (permalink)  
Old 10-10-08, 09:32
cis_groupie cis_groupie is offline
Registered User
 
Join Date: Jun 2004
Posts: 442
Why have you got a stray right parenthesis on the second to last line?
__________________
90% of users' problems can be resolved by punching them - the other 10% by switching off their PCs.
Reply With Quote
  #3 (permalink)  
Old 10-10-08, 09:45
straygrey straygrey is offline
Registered User
 
Join Date: Oct 2008
Location: Midrand, South Africa
Posts: 5
ORA-00936 with Oracle script

Slip of the finger or was it slip of the brain?
Removing it however did not fix the problem. I am still getting ORA-00936.
Reply With Quote
  #4 (permalink)  
Old 10-10-08, 12:00
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 109
Do you have any idea, what this query shall do and what the current query really does? It shall be syntactically incorrect even after removing the mentioned parenthesis, as it is not allowed to have multiple WHERE clauses in one query.

If you want to get top 200 turnover rows, you miss the very first row, something like
Code:
select * from (
Reply With Quote
  #5 (permalink)  
Old 10-10-08, 12:23
beilstwh beilstwh is offline
Registered User
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 1,642
Try the following

Code:
select MemNumber,Turnover from ( select mem_number MemNumber, sum(trans_turnover) Turnover from members join transact on mem_number = trans_code where Trans_date between to_date('01-Jan-2004') and to_date('09-Oct-2008') and mem_barred = 0 group by mem_number, order by turnover desc ) where rownum <=200;
__________________
Bill
Cream always raises to the top, and so does the scum!!
Reply With Quote
  #6 (permalink)  
Old 10-11-08, 02:28
straygrey straygrey is offline
Registered User
 
Join Date: Oct 2008
Location: Midrand, South Africa
Posts: 5
ORA-00936 with Oracle script

I have now got the code to look like
Code:
select * from ( mem_number AS MemNumber, sum(trans_turnover) AS Turnover from members join transact on mem_number = trans_code where Trans_date between '01-Jan-2004' and '09-Oct-2008' and mem_barred = 0 group by mem_number order by turnover desc ) where rownum <=200;
and now the error I get is ORA-00907: missing right parenthesis.
Help again please.
Reply With Quote
  #7 (permalink)  
Old 10-11-08, 02:35
straygrey straygrey is offline
Registered User
 
Join Date: Oct 2008
Location: Midrand, South Africa
Posts: 5
Changing my script to:-
Code:
select MemNumber,Turnover from ( select mem_number MemNumber, sum(trans_turnover) Turnover from members join transact on mem_number = trans_code where Trans_date between '01-Jan-2004' and '09-Oct-2008' and mem_barred = 0 group by mem_number order by turnover desc )

caused it to work. Thank you all especially beilstwh.
Reply With Quote
  #8 (permalink)  
Old 10-11-08, 06:05
Littlefoot Littlefoot is online now
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,715
Just beware of using "dates" the way you do:
Code:
where Trans_date between '01-Jan-2004' and '09-Oct-2008'
because 01-Jan-2004 looks like a date to you or me, but - as far as Oracle is concerned - it is just a character STRING (not a date).

The fact that your query runs well means nothing but that you have used format which is set to be a default date format on your database. For example, it would not run on my database:
Code:
SQL> select * from emp 2 where hiredate between '01-jan-2004' and '09-oct-2008'; where hiredate between '01-jan-2004' and '09-oct-2008' * ERROR at line 2: ORA-01858: a non-numeric character was found where a numeric was expected SQL>
Therefore, you'd rather use the TO_DATE function and take control over dates. This is one of acceptable solutions:
Code:
... where trans_date between to_date('01.01.2004', 'dd.mm.yyyy') and to_date('09.10.2008', 'dd.mm.yyyy')
Reply With Quote
  #9 (permalink)  
Old 10-11-08, 06:39
straygrey straygrey is offline
Registered User
 
Join Date: Oct 2008
Location: Midrand, South Africa
Posts: 5
I have hard coded the dates for test purposes but thank you for showing me how I should do it.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On