473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

find mistake... Trigger

Hi everyone,

I want to Write a trigger that will limit a user to enter only numeric values between 100 and 200 into a field called bonus for the table empBonus. and I have created trigger so please check for me that where I made mistake.
thank you.

trigger as under which i wrote.

create or replace trigger bonus_chk

before insert on empbonus
for each row

declare
emp_id number(3) := &emp_id;
emp_name varchar2(20) := '&emp_name';
emp_sal number(5) := &emp_sal;
emp_bonus number(3) := &emp_bonus;

begin

if emp_bonus < 100 or &emp_bonus > 200 then
raise_application_error(-20001,' Employee's bonus must be in between 100 to 200);

else
insert into empbonus
values
(&emp_id, '&emp_name','&emp_sal','&emp_bonus');

dbms_output.put_line('One row created successfully !');

end if;

end;
Dec 11 '06 #1
4 3553
what exactly the problem u r getting.

i have some code probably that can help u.

create or replace trigger suj_range_check
2 before insert on employee
3 for each row
4 declare
5 empid number(2):= :new.empid;
6 sal number(5):= :new.sal;
7 begin
8 if (sal>7000 or sal<500) then
9 raise_application_error(-20002,'employee sal must b in b/w 500 and 7000');
10 else
11 insert into employee values(empid,sal);
12 dbms_output.put_line('1 row created');
13 end if;
14 end;
15 /

Trigger created.

SQL> insert into employee values(8,400);
insert into employee values(8,400)
*
ERROR at line 1:
ORA-20002: employee sal must b in b/w 500 and 7000
ORA-06512: at "SUJJ.SUJ_RANGE_CHECK", line 6
ORA-04088: error during execution of trigger 'SUJJ.SUJ_RANGE_CHECK'

it's checking the range .
Dec 12 '06 #2
if it is giving the following oracle error

ERROR at line 1:
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-00036: maximum number of recursive SQL levels (50) exceeded

then the problem
is with insert
inside the trigger body u r trying to insert values into the table it again calls the trigger(before insert).so infinte calls.
Dec 12 '06 #3
for the first code that i have given it's checking the range correctly but for insertion it's firing the trigger repeatedly.so
wat i did is i tried with after insert ,and if the sal is not in the given range i tried to delete it from the table (as it is already inserted).

SQL> create or replace trigger suj_range_check
2 after insert on employee
3 for each row
4 declare
5 empid number(2):= :new.empid;
6 sal number(5):= :new.sal;
7 begin
8 if (sal>7000 or sal<500) then
9 raise_application_error(-20002,'employee sal must b in b/w 500 and 7000');
10 delete from employee where empid=:new.empid;
11 else
12 dbms_output.put_line('1 row created');
13 end if;
14 end;
15 /

Trigger created.

SQL> insert into employee values(8,400);
insert into employee values(8,400)
*
ERROR at line 1:
ORA-20002: employee sal must b in b/w 500 and 7000
ORA-06512: at "SUJJ.SUJ_RANGE_CHECK", line 6
ORA-04088: error during execution of trigger 'SUJJ.SUJ_RANGE_CHECK'


SQL> insert into employee values(8,5000);
1 row created

1 row created.


hope this helps u
Dec 12 '06 #4
suvam
31
Pls refer to ur original code with Trigger "suj_range_check" .
In the body remove the Else part as it will automatically execute if the trigger does not raise Raise_Application_Error .
Rest of the things r OK .
Dec 12 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Miles | last post by:
I recently discovered that some one (or application) updated all the rows in the database. Looks like a query was missing a where clause. It was probably one of the applications, but reviews of...
3
by: lphuong | last post by:
When someone modifies a field in a table, I like to find out which field he/she changed. Currently, only the LAST person to modify an object is saved. For example, if I modify an Application...
6
by: Scott CM | last post by:
I have a multi-part question regarding trigger performance. First of all, is there performance gain from issuing the following within a trigger: SELECT PrimaryKeyColumn FROM INSERTED opposed...
6
by: Mary | last post by:
We are developing a DB2 V7 z/OS application which uses a "trigger" table containing numerous triggers - each of which is activated by an UPDATE to a different column of this "trigger" table. When...
1
by: Thomas Zimmermann | last post by:
I have a form with a subform in datasheet view. Now, I want to trigger a procedure (P1) each time the user selects an entire column (by clicking in the heading) in the subform. The procedure (P1) I...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
by: PW | last post by:
Hi, What the heck is that supposed to mean? I am getting this error on a "Me.Requery" line in a subroutine on a form, but only when I select something from a combo/dropdown box. The *exact*...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
7
by: Shane | last post by:
I have been instructed to write a trigger that effectively acts as a foreign key. The point (I think) is to get me used to writing triggers that dont use the primary key(s) I have created the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.