0

I'm having some issues with this Query. I am trying to create a query where the user will be able to input 2 dates at runtime. It's asking me for an input, for both start date and end sate, but, it then comes up with: ORA-00904: "JAN": invalid identifier

My Query is currently:

SELECT p.FirstName, p.email, a.Avatar_Name, s.Species_Name, a.Avatar_Level, a.Skill, s.Wisdom_Level, a.AvA_DOB, a.Hoard
    FROM Players P, Avatars A, Species S
    WHERE a.Player_ID = p.Player_ID
    AND a.Species_ID = s.Species_ID
    AND Avatar_Level = 'Master'
    AND AvA_DOB BETWEEN &startdate AND &enddate
    ORDER BY Hoard DESC;

I want the user to be able to find a list of avatars between the two dates the user enters. Any help please? If more information is needed please do ask! (: (SQL PLUS)

6
  • 2
    And these various issues are...?
    – Siyual
    Apr 6, 2015 at 20:49
  • What error is sqlplus returning?
    – Politank-Z
    Apr 6, 2015 at 20:50
  • Well, it's asking me for an input, for both start date and end sate, but, it then comes up with: ORA-00904: "JAN": invalid identifier Apr 6, 2015 at 20:52
  • My DATE is dd-mmm-yyyy format, so like 10-JAN-2014 if thats any help Apr 6, 2015 at 20:55
  • 1
    Put them in single quotes. '10-JAN-2014'
    – Bob
    Apr 6, 2015 at 21:07

1 Answer 1

1

Date values in SQL need to be wrapped in single quotes. Oracle will cast these strings to a date datatype, but it's safer to use an explicit conversion, with the expected format mask.

SELECT p.FirstName, p.email, a.Avatar_Name, s.Species_Name, a.Avatar_Level, a.Skill, s.Wisdom_Level, a.AvA_DOB, a.Hoard
    FROM Players P, Avatars A, Species S
    WHERE a.Player_ID = p.Player_ID
    AND a.Species_ID = s.Species_ID
    AND Avatar_Level = 'Master'
    AND AvA_DOB BETWEEN to_date('&startdate', 'dd-mmm-yyyy') 
                AND to_date('&enddate', 'dd-mmm-yyyy')
    ORDER BY Hoard DESC;
1
  • Yes, thank-you for the answer. I did actually figure this out when I re-looked at it, I just had a reminder by Bob haha! Thank-you anyhow. Apr 8, 2015 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.