如何在日期字段Oracle SQL Developer中插入NULL

时间:2016-03-18 22:25:20

标签: sql oracle

CREATE TABLE pledge
(
    pledge_ID            NUMBER NOT NULL ,
    pledge_endDate       DATE NULL ,
    pledge_startDate     DATE NULL  ,
    pledge_amount        DECIMAL(9,2) NULL  CONSTRAINT  Currency_1322638346 CHECK (pledge_amount >= 0),
    artist_userID        NUMBER NOT NULL,
    follower_userID      NUMBER NOT NULL, 
CONSTRAINT  XPKPledge PRIMARY KEY (pledge_ID),
CONSTRAINT gets FOREIGN KEY (artist_userID) REFERENCES ArtistMember (user_ID),
CONSTRAINT makes FOREIGN KEY (follower_userID) REFERENCES FollowerMember (user_ID)
);

当我尝试插入空值时,我得到以下错误。

INSERT INTO pledge VALUES(559, 'null','1-FEB-2016', 3850, 85275, 88128);

Error report -
SQL Error: ORA-00904: : invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error starting at line : 209 in command -
INSERT INTO pledge VALUES(559, 'NULL','1-FEB-2016', 3850, 85275, 88128)
Error at Command Line : 209 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

2 个答案:

答案 0 :(得分:5)

SQL Error: ORA-00904: : invalid identifier可能是由于您的FOREIGN KEY引用了一个不存在的列而引起的 - 请检查列名是否拼写正确并且应该解决它(然后是{{1}语句将起作用。)

CREATE TABLE

如果您只使用CREATE TABLE ArtistMember ( user_ID INT PRIMARY KEY ); CREATE TABLE FollowerMember ( user_ID INT PRIMARY KEY ); CREATE TABLE pledge ( pledge_ID INT CONSTRAINT XPKPledge PRIMARY KEY, pledge_endDate DATE NULL, pledge_startDate DATE NULL, pledge_amount DECIMAL(9,2) NULL CONSTRAINT Currency_1322638346 CHECK (pledge_amount >= 0), artist_userID INT NOT NULL CONSTRAINT gets REFERENCES ArtistMember (user_ID), follower_userID INT NOT NULL CONSTRAINT makes REFERENCES FollowerMember (user_ID) ); INSERT INTO ArtistMember VALUES ( 85275 ); INSERT INTO FollowerMember VALUES( 88128 ); INSERT INTO pledge VALUES( 559, NULL, -- Use NULL and not 'NULL' DATE '2016-02-01', -- Use a Date literal and not a string literal 3850, 85275, 88128 ); 中的字符串,那么Oracle将隐式尝试使用'1-FEB-2016'函数转换字符串文字,并使用TO_DATE()会话参数作为格式掩码。如果它们匹配,那么它将工作,但这是一个客户端变量,因此可以更改,然后查询将中断而代码没有更改(并且很难调试)。简单的答案是确保通过使用NLS_DATE_FORMAT和指定格式掩码(根据上面的查询)比较日期值或使用ANSI日期文字TO_DATE()(独立于NLS)设置)。

答案 1 :(得分:0)

将空字符串this.line = new PIXI.Graphics().lineStyle(1, 0x3F51B5, 0.75); this.container.addChild(this.line); . . . loop(){ this.line.clear(); this.line.lineStyle(1, 0x3F51B5, 0.75); for(...){ circle1 = circles1[i]; for(...){ circle2 = circles2[j]; this.line.moveto(circle1.x, circle1.y).linteTo(circle2.x, circle2.y) } } } 插入NUMBER列,Oracle将插入''

例如,NULL的数据类型是日期字段或col_2(任何数据类型不是日期字段),number(12,0)的SQL语句集NULL如下所示:

col_2

insert into foo (col_1, col_2) values ('abc', '');

insert into foo (col_1, col_2) values ('abc', NULL); ,而不是NULL'NULL'