DEFAULT值的问题

时间:2013-11-08 11:18:25

标签: sql oracle

create Table payment_record(
payment_record_id int NOT NULL,
payment_number Varchar(5) NOT NULL UNIQUE,
recieved_from_client Number (8,2) NOT NULL DEFAULT 0.00,
Paid_to_client Number (8,2) NOT NULL DEFAULT 0.00,
payment_date Date NOT NULL,
PRIMARY KEY(payment_record_id));

结果

SQL> create Table payment_record(
 2  payment_record_id int NOT NULL,
 3  payment_number Varchar(5) NOT NULL UNIQUE,
 4  recieved_from_client Number (8,2) NOT NULL DEFAULT 0.00,
 5  Paid_to_client Number (8,2) NOT NULL DEFAULT 0.00,
 6  payment_date Date NOT NULL,
 7  PRIMARY KEY(payment_record_id));
 recieved_from_client Number (8,2) NOT NULL DEFAULT 0.00,
                                       *
ERROR at line 4:
ORA-00907: missing right parenthesis

请问我出错了什么?我试图创建一个默认为

的表
Paid_to_client 
recieved_from_client 
如果未分配值,

可以生成0.00

3 个答案:

答案 0 :(得分:3)

default子句应该在NOT NULL规范之前:

SQL> create Table payment_record(
 2  payment_record_id int NOT NULL,
 3  payment_number Varchar(5) NOT NULL UNIQUE,
 4  recieved_from_client Number (8,2) DEFAULT 0.00 NOT NULL,
 5  Paid_to_client Number (8,2) DEFAULT 0.00 NOT NULL,
 6  payment_date Date NOT NULL,
 7  PRIMARY KEY(payment_record_id));

答案 1 :(得分:3)

DEFAULT在NOT NULL之前发生:

create Table payment_record(
payment_record_id int NOT NULL,
payment_number Varchar(5) NOT NULL UNIQUE,
recieved_from_client Number (8,2) DEFAULT 0.00 NOT NULL,
Paid_to_client Number (8,2) DEFAULT 0.00 NOT NULL ,
payment_date Date NOT NULL,
PRIMARY KEY(payment_record_id));

答案 2 :(得分:1)

您必须在列约束之前使用默认值,例如not null。对于reference