Reputation: 135
Trying to create table that have a getdate()
function
CREATE TABLE Orders
(OrderId int NOT NULL PRIMARY KEY,
ProductName varchar(50) NOT NULL,
OrderDate datetime NOT NULL DEFAULT GETDATE()
);
but got an error
ora-00901 right parenthesis missing
Upvotes: 4
Views: 21138
Reputation: 11
Since we do not need to write NOT NULL as it accepts default function.
You can try this:
CREATE TABLE Orders
(OrderId int NOT NULL PRIMARY KEY,
ProductName varchar(50) NOT NULL,
OrderDate datetime DEFAULT GETDATE()
);
Upvotes: 1
Reputation: 168281
You need to use:
DATE
data type (which contains years through seconds data);SYSDATE
;DEFAULT
needs to go before the constraint; andVARCHAR
works and is currently synonymous with VARCHAR2
, you probably want to use VARCHAR2
for a string data type.Like this:
CREATE TABLE Orders
(
OrderId INT NOT NULL
PRIMARY KEY,
ProductName VARCHAR2(50) NOT NULL,
OrderDate DATE DEFAULT SYSDATE
NOT NULL
);
Upvotes: 3
Reputation: 21657
Try doing this instead:
CREATE TABLE Orders (
OrderId INT NOT NULL PRIMARY KEY,
ProductName VARCHAR(50) NOT NULL,
OrderDate DATE DEFAULT sysdate NOT NULL
);
Upvotes: 2