sql - Oracle Column Based on Another Column -


i'm using oracle table. let's pretend have simple table has names , datetimestamps:

name  time ---   --- joe   01jan1970:00:00:01 jane  04mar2010:20:55:11 julie 22dec1984:11:11:11 

i want add third column. let's call date. want truncate off time.

name  time               date ---   ---                --- joe   01jan1970:00:00:01 01jan1970 jane  04mar2010:20:55:11 04mar2010 julie 22dec1984:11:11:11 22dec1984 

that accomplished enough update. trick is, if updates julie's time, want date automatically update well:

name   time               date ---    ---                --- joe    01jan1970:00:00:01 01jan1970 jane   04mar2010:20:55:11 04mar2010 julie  02oct1999:22:22:22 02oct1999 

is there simple way accomplish oracle 11g? can set trigger update column in row when column changes?

edit: clarity in example

i second jesse's advice use view returns whatever want.

however, if want stored (e.g. in order create index on it), can use virtual column:

create table foo (   name varchar(50) not null,   time timestamp not null,   plain_date generated (to_char(time, 'yyyy-mm-dd')) ); 

as alternative can use trunc(time) still have time part in - set 00:00:00. using to_char() ensures date in desired format.

here little sqlfiddle: http://sqlfiddle.com/#!4/a7f55/2


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -