Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using datediff when creating table

sqlnoobJul 15 2014 — edited Jul 15 2014

Hi all,

I'm trying to calculate the number of years of a product when a new record is inserted.

this is what i've tried

CREATE TABLE WaterMeter (

meterID VARCHAR(25) NOT NULL,

readingID VARCHAR(25) NOT NULL,

meterSerialNum VARCHAR(25) NOT NULL,

installationDate DATE NOT NULL,

noOfYears AS (DATEDIFF (YEAR, sysdate, installationDate)),

CONSTRAINT watermeter_Pkey PRIMARY KEY (meterID),

CONSTRAINT watermeter_Altkey UNIQUE (meterSerialNum)

);

and the following error has appeared.

Error at Command Line:6 Column:27

Error report:

SQL Error: ORA-00904: "YEAR": invalid identifier

00904. 00000 -  "%s: invalid identifier"

*Cause:   

*Action:

so how do I go around solving this issue?

This post has been answered by Solomon Yakobson on Jul 15 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2014
Added on Jul 15 2014
6 comments
950 views