2
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

4

3 回答 3

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));
于 2013-11-08T11:21:27.783 回答
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));
于 2013-11-08T11:21:36.150 回答
1

您必须在列约束之前使用默认值,例如不为空。供参考

于 2013-11-08T11:25:54.073 回答