Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Before insert trigger code
Hi Ranganath
For your case you can try to create trigger something like this (just example):
create or replace trigger <trigger name> before insert on <table name>
for each row
DECLARE
row_count NUMBER;
BEGIN
SELECT count(*) INTO row_count from <table name> WHERE :new.start_dt BETWEEN
start_dt AND expiry_dt OR
:new.expiry_dt BETWEEN start_dt AND expiry_dt;
IF row_count>0 THEN
dbms_output.put_line('Rejected by conditions ');
ELSE
dbms_output.put_line('Approved by conditions ');
END IF;
END;
/
This trigger returns resulting message (for example) and executing COMMIT or ROLLBACK is up to you.
Regards
Michael Malyk
Oracle Programmer
Toronto,Canada
RanganathK_at_lgcommerznow.com wrote:
> Dear all,
>
> I have a table by name image_master whose structure is as below:
>
> IMAGE_NAME NOT NULL
> VARCHAR2(60)
> TYPE NOT NULL
> CHAR(1)
> START_DT NOT NULL
> VARCHAR2(8)
> EXPIRY_DT
> VARCHAR2(8)
> IMAGE_DESC
> VARCHAR2(600)
> CREATE_DT
> VARCHAR2(8)
> MODIFY_DT
> VARCHAR2(8)
>
> The dates are entered in the form 'yyyymmdd'. All the dates have been
> assigned the datatype as varchar2(8) instead of date for a specific reason.
> I would like to create a before insert trigger on the table so that the
> user cannot insert a record if the start_dt and expiry_dt overlap the
> existing start_dt and expiry_dt in the existing records. For example, if
> there is a record whose start_dt is 20001126 and end_dt is 20001128 then
> the user is not allowed to have start_dt and end_dt between 26th and 28th
> November, 2000 (both dates inclusive). His start_dt and end_dt can be any
> dates apart from 26th, 27th and 28th November. How do I implement this
> using SQL or PL/SQL? Is there any other way out apart from creating a
> before insert trigger? I hope I am clear. Any help in this regard will
> be highly appreciated.
>
> TIA and regards,
>
> Ranganath
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author:
> INET: RanganathK_at_lgcommerznow.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
Received on Tue Nov 28 2000 - 14:09:19 CST