sqloracle-databasesqlpluscomposite-primary-keyora-00936

Why am I getting an ORA-00936 error for my composite primary key on my sqlplus code?


The error is at the very end of this code block.

SQL> CREATE TABLE Hotel
2  (hotelNo          INTEGER       NOT NULL
3  ,hotelName        VARCHAR2(50)  NOT NULL
4  ,city             VARCHAR2(50)  NOT NULL
5  ,CONSTRAINT PKHotel PRIMARY KEY (hotelNo)
6  );

Table created.

SQL> CREATE TABLE Room
2  (roomNo           INTEGER       NOT NULL
3  ,hotelNo          INTEGER       NOT NULL
4  ,type             CHAR(6)       NOT NULL
5  ,price            DECIMAL (3,2) NOT NULL
6  ,CONSTRAINT PKRoom PRIMARY KEY (roomNo, hotelNo)
7  ,CONSTRAINT FKRoom FOREIGN KEY (hotelNo) REFERENCES Hotel (hotelNo)
8  ,CONSTRAINT chk_type CHECK (type IN ('Single', 'Double', 'Family'))
9  ,CONSTRAINT chk_roomNo CHECK(roomNo > 1 AND roomNo < 100)
10  ,CONSTRAINT chk_price CHECK(price > 10.00 AND price <100.00)
11  );

Table created.

SQL> -- Q3.
SQL> CREATE TABLE Guest
2  (guestNo         INTEGER        NOT NULL
3  ,guestName       VARCHAR(50)    NOT NULL
4  ,guessAddress    VARCHAR(50)    NOT NULL
5  ,CONSTRAINT PKGuest PRIMARY KEY (guestNo)
6  );

Table created.

SQL>
SQL> CREATE TABLE Booking
2  (hotelNo         INTEGER        NOT NULL
3  ,guestNo         INTEGER        NOT NULL
4  ,dateFrom        DATE           NOT NULL
5  ,dateTo          DATE           NOT NULL
6  ,roomNo          INTEGER        NOT NULL
7  ,discount     DECIMAL(2,2)DEFAULT
8  ,CONSTRAINT PKBooking PRIMARY KEY (hotelNo,guestNo,dateFrom)
9  ,CONSTRAINT FKBooking_1 FOREIGN KEY (hotelNo, roomNo) REFERENCES Room                (hotelNo, roomNo)
10  ,CONSTRAINT FKBooking_2 FOREIGN KEY (guestNo) REFERENCES Guest (guestNo)
11  );
,CONSTRAINT PKBooking PRIMARY KEY (hotelNo,guestNo,dateFrom)
*
ERROR at line 8:
ORA-00936: missing expression

I don't really understand why this isn't working because the syntax is good. I'm assuming the logic is wrong but I'm relatively new at this so I'm not sure. I'd really appreciates some feedback.


Solution

  • That's because you left out the DEFAULT value/expression for DISCOUNT.