Home » RDBMS Server » Server Utilities » Trigger
Trigger [message #71857] Wed, 22 January 2003 09:31 Go to next message
Pratibha
Messages: 29
Registered: November 2001
Junior Member
Hai

I do understand somewhat about triggers.

Here ,I got one question,what it is

For what purpose,we are using triggers?

Thank you
Re: Trigger [message #71859 is a reply to message #71857] Wed, 22 January 2003 09:53 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
if u want SOME ACTION to be done AUTOMATICALLY,
when A CERTAIN EVENT (insert or update or delete or so on) in a database, u use trigger.
Re: Trigger [message #71898 is a reply to message #71857] Wed, 29 January 2003 15:24 Go to previous messageGo to next message
Pratibha
Messages: 29
Registered: November 2001
Junior Member
Thank u very much.

here,I have an example from one text book

some x-company would like to trap some data entry errors like entering quantity delivered is greater than quantity ordered.

create or replace trigger orders before insert on order_detail for each row
declare
orno order_detail.orderno%type;
begin
select orderno into orno from order_detail where quantity_ord<quantity_deld;
if orno='o001' then
raise_application_error(-20,001,'enter some other number');
end if;
end;
/

please explain me what is going in this trigger body

Thanks for your time
Re: Trigger [message #71901 is a reply to message #71857] Thu, 30 January 2003 06:42 Go to previous message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
before every insert in table order_detail, this trigger is fired.
it checks whether a particulr orno already exists.

----------------------------------------------------------------------

this trigger is have logical error.
it always checks for orno='o001'.
ie..if there is already an orno='o001' inserted,
then, TRIGGER WILL NOT ALLOW U TO INSERT ANY RECORD.
becuase u are checking if orno='o001' is present in table
IRRELEVANT  of wat u insert

----------------------------------------------------------------------

correct  code should be

----------------------------------------------------------------------

if :new.orno='o001'
then raise_application_error 
  ...
  ...

</hr>
now you check whether the orno that is CURRENTLY INSERTED equal to 'o001'

Previous Topic: Re: Error 1053: The service did not respond to the start or control request in a timely fashion.
Next Topic: Trigger
Goto Forum:
  


Current Time: Wed May 15 20:10:15 CDT 2024