3

I understand the ORA-00907 is indicating that I have a syntax error in my code, I just can't find it. Can someone help point out the problem? I'm using SQL Developer (Oracle12c).

CREATE TABLE equip 
  (equipid NUMBER(3),
   edesc VARCHAR2(30), 
   purchdate DATE, 
   rating CHAR(1), 
   deptid NUMBER(2) NOT NULL, 
   etypeid NUMBER(2),
    CONSTRAINT equip_equipid_pk PRIMARY KEY (equipid),
    CONSTRAINT equip deptid_fk FOREIGN KEY (deptid) REFERENCES dept (deptid),
    CONSTRAINT equip_etypeid_fk FOREIGN KEY (etypeid) REFERENCES etypes (etypeid),
    CONSTRAINT equip_rating_ck CHECK (rating IN ('A','B','C')));

Oracle12 SQL Syntax Error

  • 4
    Please post the code **as properly formatted text** - not a screenshots thereof...... – marc_s Feb 02 '21 at 16:33
  • Really, this is in the [how-to-ask](https://stackoverflow.com/help/how-to-ask) guide. Using screenshots for code makes it impossible for readers to copy & paste your code, and it makes it impossible for people who use screen readers. – Bill Karwin Feb 02 '21 at 16:36
  • 2
    Done. Added code properly formatted as text. @marc_s – Andrew Biddle Feb 02 '21 at 16:37

1 Answers1

5

You have a space in the constraint name, which is probably confusing the syntax parser:

CONSTRAINT equip deptid_fk FOREIGN KEY (deptid) REFERENCES dept (deptid),
                ^

If you need a space in identifiers, delimit them in double-quotes like "equip deptid_fk". But it's easier if you can spell your identifiers without whitespace or punctuation.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Awesome. Thanks for the help. Can't believe I missed that. – Andrew Biddle Feb 02 '21 at 16:40
  • @andrewbiddle - In addition to this (correct) answer: pretty much any interface you use will tell you EXACTLY where the error was found (line of code and position on the line, or a marker like Bill is showing above). That should help you find and fix the mistakes yourself. –  Feb 02 '21 at 16:40
  • 1
    Oracle error messages are notoriously unhelpful. I didn't see this either, until I tried your statement in MySQL, and then it told me exactly where the problem was. :-) – Bill Karwin Feb 02 '21 at 16:41
  • 1
    @BillKarwin: thank goodness you had the SQL code to copy&paste! ;-) – marc_s Feb 02 '21 at 16:44