简体   繁体   中英

How to update the date for a specific ID in Oracle SQL?

I'm setting up a database for a scuba diving company and have a SQL table with values for Student ID ( SID ), Instructor ID ( IID ), Item Borrowed ( ITEMID ), Equipment Borrow Date ( BorrowDate ), and Equipment Return Date ( ReturnDate ). How do I change the Equipment Return Date for one of the students? I'd like to add an extra 2 days to the ReturnDate . I created the Borrows table like this:

CREATE TABLE BORROWS(
  SID CHAR(15),
  ITEMID CHAR(15),
  IID CHAR(15),
  BORROW_DATE DATE,
  RETURN_DATE DATE,
  PRIMARY KEY(SID, ITEMID),
  FOREIGN KEY(SID) REFERENCES STUDENT(SID) ON DELETE CASCADE,
  FOREIGN KEY(ITEMID) REFERENCES EQUIPMENT(ITEMID) ON DELETE CASCADE,
  FOREIGN KEY(IID) REFERENCES INSTRUCTOR(SSN) ON DELETE CASCADE
);

I tried doing this in my SQL file:

SELECT SID, ADD_DATE(RETURN_DATE, INTERVAL 2 DAY)
FROM BORROWS
WHERE SID = '005' AND IID = '108';

I'm getting this error back:

SELECT SID, ADD_DATE(RETURN_DATE, INTERVAL 2 DAY)
                                       *
ERROR at line 1:
ORA-00907: missing right parenthesis

Can't figure out where the error is in my code...

Adding two days to a date is as simple as + 2.

select return_date + 2 
from borrows 
where sid='005' 
and iid='108'

The syntax you are looking for might be:

select (return_date + INTERVAL '2' DAY)
    from borrows 
    where sid='005' 
    and iid='108'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM