Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to create computed field/column in a table

Re: How to create computed field/column in a table

From: Dmitry E. Loginov <dmitry_loginov_at_mtu.ru>
Date: Wed, 21 Nov 2001 00:24:22 +0300
Message-ID: <9tehq2$1f8a$1@gavrilo.mtu.ru>

"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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US