Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to create computed field/column in a table
"Jesper S. Knudsen" <jesper.stougaard.knudsen_at_omgroup.com> wrote in message
news:WxmK7.207$w04.3163937823_at_news.euroconnect.net...
> Hi
>
> Does anyone know how create a computed column in a table?
>
> In MS SQL Server you do it like this:
>
> CREATE TABLE mytable (
> key numeric not null primary key,
> value1 numeric not null,
> value2 numeric not null,
> value3 as (value1*value2)
> )
>
> How is it done in Oracle?
Just create trigger for that column to compute and store value:
CREATE TABLE mytable (
key numeric not null primary key,
value1 numeric not null,
value2 numeric not null,
value3 numeric
);
create or replace trigger MYTABLE_T$BIUER
before INSERT or UPDATE on MYTABLE
for EACH ROW
begin
:new.value3:=:new.value1*:new.value2;
end;
/
>
> Gr.
>
> Jesper
>
>
Received on Tue Nov 20 2001 - 15:24:22 CST
![]() |
![]() |