我已经为此工作了几天,无法弄清楚错误在哪里。查询是:
Select distinct p.PkgID, p.PkgName, p.PkgCost, c.CustFName || ' ' || c.CustLName as "CUSTOMERNAME"
FROM Subscription s, Package p, Customer c
WHERE p.PkgID = s.PkgID
AND c.CustID = s.CustID
AND to_date
(s.StartDate, 'Mon DD, YYYY')=
to_date
(&StartDate, 'Mon DD, YYYY')
ORDER BY p.PkgID;
我不断得到:
SQL 错误:ORA-00907:缺少右括号 00907。00000 -“缺少右括号”。
我找不到问题。任何帮助将非常感激。这是 table 和 insert 语句的样子。
CREATE TABLE SUBSCRIPTION
(
SubID NUMBER(5) NOT NULL CONSTRAINT SUBSCRIPTION_SubID_PK PRIMARY KEY,
StartDate DATE NOT NULL,
EndDate DATE NOT NULL,
CustID NUMBER(5) NOT NULL,
PkgID NUMBER(5) NOT NULL
);
ALTER TABLE SUBSCRIPTION ADD CONSTRAINT SUBSCRIPTION_CustID_FK FOREIGN KEY (CustID) REFERENCES CUSTOMER (CustID);
ALTER TABLE SUBSCRIPTION ADD CONSTRAINT SUBSCRIPTION_PkgID_FK FOREIGN KEY (PkgID) REFERENCES PACKAGE (PkgID);
INSERT INTO SUBSCRIPTION
VALUES (010, to_date('Jan 01, 2010 11:30','Mon DD, YYYY hh24:mi'), to_date('Jan 01, 2013 14:30','Mon DD, YYYY hh24:mi'), 00001, 10101);
INSERT INTO SUBSCRIPTION
VALUES (015,to_date('Mar 01, 2012 17:00','Mon DD, YYYY hh24:mi'), to_date('Dec 05, 2012 17:00','Mon DD, YYYY hh24:mi'), 00002, 20202);
作为旁注,我也尝试过这种方式:
Select distinct p.PkgID, p.PkgName, p.PkgCost, c.CustFName || ' ' || c.CustLName as "CUSTOMERNAME"
FROM Subscription s
Left OUTER JOIN Package p on p.PkgID = s.PkgID
Left OUTER JOIN Customer c on c.CustID = s.CustID
WHERE to_date (s.StartDate, 'Mon DD, YYYY')=
to_date (&StartDate, 'Mon DD, YYYY')
ORDER BY p.PkgID;