Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2013
    Posts
    46

    Unanswered: Oracle equivalent of DB2.....

    Hi,

    I want to convert the following from a db2 create table ddl:

    "COLUMN2" INTEGER NOT NULL GENERATED ALWAYS AS (COLUMN1+1)

    ...how do i use this logic same in oracle? "COLUMN1" is number as well

    Thanks in advance.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    If COLUMN2 is always COLUMN1 + 1, why would you want to use COLUMN2 at all? You *know* that it is COLUMN1 + 1 anyway, so there's no point in storing that value.

    Anyway, if you insist, you'd have to use a database trigger.

  3. #3
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    SQL> desc bonus
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ENAME                                              VARCHAR2(10)
     JOB                                                VARCHAR2(9)
     SAL                                                NUMBER
     COMM                                               NUMBER
    
    SQL> create view foobar as select ename, job, sal, sal+1 col2, comm from bonus;
    
    View created.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    The syntax looks remarkably similar to DB2. I guess you just can't have the NOT NULL constraint:
    CREATE TABLE

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    in oracle 12 you can setup virtual columns which will do what you want.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  6. #6
    Join Date
    Sep 2013
    Posts
    46
    Thank you all. It was fairly simple after looking at create table syntax. Very similar to db2 in fact.

Posting Permissions

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