誰能幫助我弄清楚,爲什麼我得到一個錯誤的cms.CRIME_ID
:奇怪的Oracle SQL「無效的」錯誤
invalid identifier
select c.criminal_id, c.first, c.last, cms.CRIME_ID, cc.crime_code, cc.fine_amount
from criminals c join crimes cms on c.criminal_id = cms.criminal_id
join crime_charges cc using (crime_id)
order by c.first, c.last;
我知道絕對的事實,列存在,我可以引用所有其他除此之外,該表中的列。
與該列唯一不同的是它是該表的主鍵。
編輯:這是完整的錯誤和表創建腳本。
Error starting at line 1 in command:
select c.criminal_id, c.first, c.last, cms.CRIME_ID, cc.crime_code, cc.fine_amount
from criminals c join crimes cms on c.criminal_id = cms.criminal_id
join crime_charges cc using (crime_id)
order by c.first, c.last
Error at Command Line:1 Column:39
Error report:
SQL Error: ORA-00904: "CMS"."CRIME_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
CREATE TABLE crimes
(crime_id NUMBER(9),
criminal_id NUMBER(6),
classification CHAR(1),
date_charged DATE,
status CHAR(2),
hearing_date DATE,
appeal_cut_date DATE);
ALTER TABLE crimes
MODIFY (classification DEFAULT 'U');
ALTER TABLE crimes
ADD (date_recorded DATE DEFAULT SYSDATE);
ALTER TABLE crimes
MODIFY (criminal_id NOT NULL);
ALTER TABLE crimes
ADD CONSTRAINT crimes_id_pk PRIMARY KEY (crime_id);
ALTER TABLE crimes
ADD CONSTRAINT crimes_class_ck CHECK (classification IN('F','M','O','U'));
ALTER TABLE crimes
ADD CONSTRAINT crimes_status_ck CHECK (status IN('CL','CA','IA'));
ALTER TABLE crimes
ADD CONSTRAINT crimes_criminalid_fk FOREIGN KEY (criminal_id)
REFERENCES criminals(criminal_id);
ALTER TABLE crimes
MODIFY (criminal_id NOT NULL);
EDIT2:另外,我也許應該提到的是不使用的時候加入,只是普通的SELECT語句,我可以訪問列就好了,如下面的代碼示例:
select c.criminal_id, c.first, c.last, cms.crime_id, cc.crime_code, cc.fine_amount
from criminals c, crime_charges cc, crimes cms
where c.criminal_id = cms.criminal_id
and cms.crime_id = cc.crime_id
order by c.first, c.last;
請發表 –
請問您的用戶所涉及的表的詳細信息,對所犯罪行表的權限? –
什麼是crime_charges表的定義? – Ollie