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: Trigger to Combine Two Columns

Re: Trigger to Combine Two Columns

From: Arjan van Bentem <avbentem_at_DONT-YOU-DAREdds.nl>
Date: Fri, 23 Apr 1999 20:20:04 +0200
Message-ID: <7fqdkb$rev$1@weber.a2000.nl>


MIke wrote
> group varchar2(25)primary
> group_num varchar2(5)
> group_name varchar2(20)
>
> I would like to set up a trigger so that the end user only has to enter
> the group_num and group_name and the trigger will combine the
> two fields seperated by a '.' to form the primary key.

    create or replace trigger biu_my_table

        before insert or update on my_table
        for each row
    begin
        :new.group := :new.group_num || '.' || :new.group_name;
    end biu_my_table;
    /
    show errors

However, you could also simply use both columns as the primary key:

    create table my_table

        ( group_num varchar2(5)
        , group_name varchar2(20)
        , ....
        , primary key (group_num, group_name)
        );

Arjan. Received on Fri Apr 23 1999 - 13:20:04 CDT

Original text of this message

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