Knowee
Questions
Features
Study Tools

Error starting at line : 6 File @ /oracle.sqlIn command -create table CROP(CROP_ID NUMBER primary key,CROP_NAME VARCHAR2(100) NOT NULL,PLANTING_DATE DATE NOT NULL,FIELD_ID NUMBER NOT NULL,constraint FK_FIELD_ID references FIELD(FIELD_ID),constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID))Error report -ORA-00907: missing right parenthesis00907. 00000 - "missing right parenthesis"

Question

Error starting at line : 6 File @ /oracle.sqlIn command -create table CROP(CROP_ID NUMBER primary key,CROP_NAME VARCHAR2(100) NOT NULL,PLANTING_DATE DATE NOT NULL,FIELD_ID NUMBER NOT NULL,constraint FK_FIELD_ID references FIELD(FIELD_ID),constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID))Error report -ORA-00907: missing right parenthesis00907. 00000 - "missing right parenthesis"

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The error message you're receiving is indicating that there is a missing right parenthesis in your SQL command. However, from the command you've provided, the parentheses seem to be balanced.

The issue might be related to the way you've written your constraints. In Oracle SQL, you don't need to specify the column name when you're creating a foreign key constraint if the primary key is a single column.

Here's how you can modify your command:

CREATE TABLE CROP(
    CROP_ID NUMBER PRIMARY KEY,
    CROP_NAME VARCHAR2(100) NOT NULL,
    PLANTING_DATE DATE NOT NULL,
    FIELD_ID NUMBER NOT NULL,
    CONSTRAINT FK_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD,
    CONSTRAINT FK_FIELD_CONDITION_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD
)

In this command, I've removed the (FIELD_ID) after REFERENCES FIELD in your constraints. If FIELD_ID is the primary key in the FIELD table, Oracle SQL will automatically know that your foreign key is referencing it.

If FIELD_ID is not the primary key in the FIELD table, you need to specify it like this:

CREATE TABLE CROP(
    CROP_ID NUMBER PRIMARY KEY,
    CROP_NAME VARCHAR2(100) NOT NULL,
    PLANTING_DATE DATE NOT NULL,
    FIELD_ID NUMBER NOT NULL,
    CONSTRAINT FK_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD(FIELD_ID),
    CONSTRAINT FK_FIELD_CONDITION_FIELD_ID FOREIGN KEY (FIELD_ID) REFERENCES FIELD(FIELD_ID)
)

Please replace FIELD with your actual table name if it's different.

This problem has been solved

Similar Questions

Error starting at line : 6 File @ /oracle.sqlIn command -create table CROP(CROP_ID NUMBER primary key,CROP_NAME VARCHAR2(100) NOT NULL,PLANTING_DATE DATE NOT NULL,FIELD_ID NUMBER NOT NULL,constraint FK_FIELD_ID foreign key (FIELD_ID)references FIELD(FIELD_ID),constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID))Error report -ORA-02274: duplicate referential constraint specifications02274. 00000 - "duplicate referential constraint specifications"*Cause: Self-evident.*Action: Remove the duplicate specification.

Error starting at line : 7 File @ /oracle.sqlIn command -create table FIELD_CONDITION(CONDITION_ID NUMBER,FIELD_ID NUMBER NOT NULL,CONDITION_TYPE VARCHAR2(50) NOT NULL,VALUE NUMBER NOT NULL,RECORDED_AT TIMESTAMP NOT NULL,constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID),constraint CK_CONDITION_TYPE check(CONDITION_TYPE IN ('soil moisture','temperature','humidity','pH')))Error report -ORA-02264: name already used by an existing constraint02264. 00000 - "name already used by an existing constraint"*Cause: The specified constraint name has to be unique.*Action: Specify a unique constraint name for the constraint.

Error starting at line : 7 File @ /oracle.sqlIn command -create table SHIPMENT(SHIPMENT_ID NUMBER,BATCH_ID NUMBER NOT NULL,SHIPMENT_DATE DATE NOT NULL,DESTINATION VARCHAR2(255) NOT NULL,QUANTITY_SHIPPED NUMBER NOT NULL check (QUANTITY_SHIPPED > 0),foreign key (BATCH_ID) references BATCH(BATCH_ID) on delete cascade)Error report -ORA-02270: no matching unique or primary key for this column-list02270. 00000 - "no matching unique or primary key for this column-list"*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table.*Action: Find the correct column names using the ALL_CONS_COLUMNS catalog view

Error starting at line : 8 File @ /oracle.sqlIn command -alter table BOOKS drop primary key add primary key (Title)Error report -ORA-00933: SQL command not properly ended00933. 00000 - "SQL command not properly ended"*Cause: *Action:

Error starting at line : 10 File @ /oracle.sqlIn command -alter table BORROWERS drop primary keyError report -ORA-02441: Cannot drop nonexistent primary key02441. 00000 - "Cannot drop nonexistent primary key"*Cause: alter table drop primary key - primary key does not exist.*Action: None

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.