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: Richard B <someguyonthenet_at_hotmail.com>
Date: Tue, 20 Nov 2001 12:37:47 -0000
Message-ID: <3bfa4f8d@peer1.news.newnet.co.uk>

"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?
>
> Gr.
>
> Jesper
>
>

The simplest way is to create a view against the table. Eg.

CREATE TABLE mytable (
value1 number not null,
value2 number not null);

CREATE VIEW v_mytable as
SELECT value1, value2, (value1 * value2) as value3 FROM mytable;

The drawback with this method is that you can't update the value3 colum directly. But presumably Transact-SQL wouldn't let you do this either.

-Richard



"Propose to an Englishman any principle, or instrument, however admirable, and you will observe that the

whole effect of the English mind is directed to find a difficulty, a defect, or an impossibility in it.

If you speak to him of a machine for peeling a potato, he will pronounce it impossible;

if you peel a potato with it before his eyes, he will declare it useless, because it will not slice a pineapple."


Received on Tue Nov 20 2001 - 06:37:47 CST

Original text of this message

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