Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2006
    Posts
    83

    Question Unanswered: computed columns in oracle

    Hi

    Does oracle support computed columns in the CREATE TABLE statement like SQL Server ?

    For eg :
    I have the following table in SQL Server

    CREATE TABLE computed_column_table(column1 int , column2 as 100 - column1) ;

    In the above table only column1 needs to be inserted while the column2 will be updated based on the column1 value .

    I want to know whether there is a similar option in Oracle at the table definition level.

    thanks,

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    No there isn't.

    You will need to create a view that calculates that value

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    While oracle doesn't natively support this option, it is easy to do. Simply create an on insert trigger on the table which would perform the calculation and adjust column2. However, if column2 will always be exactly (100 - column1), why would you ever store column2. simply use (100 -column1) in your select.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,296
    yeah, leave calculations to the front-end.
    databases should store data, not manipulate data.
    That is what applications are for.
    Why store redundant data?

    Just my opinion, but once you start down that road the next thing you
    know is that you coded the whole application.
    - The_Duck
    you can lead someone to something but they will never learn anything ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •