>
> -- dpch is datasource
> -- hhp_calendar is the table
> -- id is the primary key updated by the sequence
Some comments intersparsed:
> CREATE OR REPLACE TRIGGER hhp_calendar.trg_hhp_calendar_id
> BEFORE INSERT OR UPDATE
We don't really want to change the primary key when we update, do we?
> ON hhp_calendar.hhp_calendar
> REFERENCING NEW AS NEW OLD AS OLD
> FOR EACH ROW
> DECLARE
> iCounter hhp_calendar.id%TYPE;
> cannot_change_counter EXCEPTION;
IIRC most of this is optional.
> BEGIN
> IF INSERTING THEN
If we don't define the trigger for updates, we don't need the IF
later on either :)
> Select uniqueNum_s.NEXTVAL INTO iCounter FROM Dual;
> :new.id := iCounter;
No need for a temp var, you can select into new:id directly.
So I suppose we end up with:
CREATE OR REPLACE TRIGGER hhp_calendar.trg_hhp_calendar_id
BEFORE INSERT ON hhp_calendar.hhp_calendar FOR EACH ROW
BEGIN
SELECT uniqueNum_s.nextval INTO :new.id FROM dual;
END;
Jochem
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

