我一直在为学校的SQL数据库项目工作,我的想法有一个问题。我正在做一个汽车服务数据库(都是虚构的),我有一个表order
的数据类型为date
的列order
(在我的语言中都有名称- 'rok‘和'narocilo'),并且我试图将null插入到客户没有指定截止日期的一些行中。
create table narocilo
(
id_narocila integer NOT null,
opis varchar(50),
cena integer,
status varchar(20),
datum_narocila date,
rok date
);
这是我尝试插入null的一些方法,但都不起作用
to_date('dd-mm-yyyy', null)
to_date(null)
null
to_date('null')
所以,我的问题是,我可以将null插入到date
列中吗?如果可以,如何插入?
提前谢谢你!
发布于 2018-06-04 05:12:07
您必须插入整行数据,但只要您没有像上面那样将该字段定义为not NULL,那么将NULL值插入到日期字段中应该是可以的:
INSERT INTO narocilo(id_narocila, opis, cena, status, datm_narocila, rok)
VALUES (1001, 'something', 6, 'Open', NULL, NULL)
发布于 2018-06-04 06:07:11
对NULL
进行insert
的一个非常简单的方法是将它们完全排除在insert
之外:
INSERT INTO narocilo (id_narocila, opis, cena, status)
VALUES (?, ?, ?, ?);
从技术上讲,这会插入默认值。但是您没有指定一个,所以缺省值是NULL
。
https://stackoverflow.com/questions/50670953
复制相似问题