Home » RDBMS Server » Server Utilities » trigger
trigger [message #71813] Wed, 15 January 2003 15:09 Go to next message
Pratibha
Messages: 29
Registered: November 2001
Junior Member
ORDER ITEMC QTY_ORD QTY_DELD
----- ----- ---------- ----------
o001 i001 50 70
o002 i002 40 40

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 qty_ord(is less than)qty_deld;
if orno='001'then
raise_application_error(-20001,'enter some other number');
end if;
end;
/
Trigger created
SQL> insert into order_detail values('o003','i003',30,30);
insert into order_detail values('o003','i003',30,30)
*
ERROR at line 1:
ORA-20001: enter some other number
ORA-06512: at "RANI.ORDERS", line 6
ORA-04088: error during execution of trigger 'RANI.ORDERS'

SQL> insert into order_detail values('o001','i003',40,40);
insert into order_detail values('o001','i003',40,40)
*
ERROR at line 1:
ORA-20001: enter some other number
ORA-06512: at "RANI.ORDERS", line 6
ORA-04088: error during execution of trigger 'RANI.ORDERS'

*When I post this message,in posted message,less than symbol not coming,that's why for your understanding I write.

Please explain what happened .

Thank's for your help
Re: trigger [message #71815 is a reply to message #71813] Wed, 15 January 2003 15:28 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
SQL> create or replace trigger before_in_ddd
  2  before insert on ddd
  3  for each row
  4  declare
  5  a varchar2(10);
  6  begin
  7  if :new.dname='sample' then
  8    raise_application_error(-20001,'enter some other number');
  9  end if;
 10  end;
 11  /

Trigger created.

SQL> insert into ddd values ('samples')
  2  ;

1 row created.

SQL> insert into ddd values ('sample');
insert into ddd values ('sample')
            *
ERROR at line 1:
ORA-20001: enter some other number
ORA-06512: at "MAG.BEFORE_IN_DDD", line 5
ORA-04088: error during execution of trigger 'MAG.BEFORE_IN_DDD'

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

u have to use trigger predicates :new and :old.
in your code, u have already insert number 001.
so when u are querying the table first record is 001.
so, the excepption is thrown.
WHICH IS EXACTLY WAT U REQUIRED.
[b] and pls maintain a single thread...people cant kkeep track ....

Re: trigger [message #71817 is a reply to message #71815] Wed, 15 January 2003 15:56 Go to previous message
Pratibha
Messages: 29
Registered: November 2001
Junior Member
Thank u.
I got what you elucidated.

next,If I give another name inplace of 'samples',it would be inserted.Is this right?

regards
pratibha
Previous Topic: IMP utility has a bug? when CONSTRAINTS = N
Next Topic: How to do a FULL IMPORT from PROD to TEST?
Goto Forum:
  


Current Time: Mon May 13 23:55:56 CDT 2024