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
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
);
Try doing this instead:
CREATE TABLE Orders (
OrderId INT NOT NULL PRIMARY KEY,
ProductName VARCHAR(50) NOT NULL,
OrderDate DATE DEFAULT sysdate NOT NULL
);
sqlfiddle demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With