create sequence student_studentid_seq
increment by 10
start with 100
nocycle;
create table student
(studentid number(10),
name varchar2(30) not null,
ss# number(9) unique,
gpa number(2,3) not null,
constraint student_studentid_pk PRIMARY KEY (studentid),
constraint student_gpa_ck CHECK (GPA >= 0));
insert into student (studentid, name, ss#, gpa)
values(student_studentid_seq.NEXTVAL,'Draze Katan', 323456789,1);
receiving error message:
Error starting at line 29 in command:
insert into student (studentid, name, ss#, gpa)
values(student_studentid_seq.NEXTVAL,'Draze Katan', 323456789,1)
Error report:
SQL Error: ORA-01438: value larger than specified precision allowed for this column
01438. 00000 - "value larger than specified precision allowed for this column"
*Cause: When inserting or updating records, a numeric value was entered
that exceeded the precision defined for the column.
*Action: Enter a value that complies with the numeric column's precision,
or use the MODIFY option with the ALTER TABLE command to expand
the precision.
因此,看來錯誤消息是針對下一個約束:約束student_gpa_ck CHECK(GPA> = 0)); 在插入語句中,如果我爲GPA輸入'0',原始數據將被插入,但是更多我將收到錯誤消息。我創建了CHECK約束,但收到錯誤消息
這是我的一個練習題,我弄不明白。我只需要提示錯誤不是全分辨率。請如果你能幫助我。
你爲什麼使用數字(10)作爲主鍵。它應該是整數。數字較慢。 –
@JoeLove數字較慢?你能否用一些支持數據來說明這一點? – BobC
爲什麼'數字(2,3)'爲GPA?這是問題(不是「檢查約束」)。你是什麼意思?如果你的意思是數字3.84和2.33,那麼你需要數字(3,2)'。 3表示「三位有效數字」,2表示「......其中最後兩位在小數點後」。 – mathguy