Home » Developer & Programmer » Forms » Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION (Oracle Forms, 10g, Win XP)
Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION [message #557336] Tue, 12 June 2012 00:44 Go to next message
mvmkandan
Messages: 68
Registered: May 2010
Location: Trivendrum
Member
My requirement, if there is no record in emp table when validate the EMP_NO_CHK text field, i need to set the focus on that field (EMP_NO_CHK) itself.
But while execute the following code, I got error. Please suggest me anyone to achieve the task.


--EMP_NO_CHK_WHEN_VALIDATE_ITEM Trigger
-----------------------------------
Declare
cursor c is Select * from emp where Emp_no = :header.empno;
c1 emp%rowtype;
n NUMBER;
BEGIN
  OPEN c;
  Loop
	FETCH c into C1;
	Exit when c%notfound;
	n := n + 1;
  END LOOP:
  CLOSE c;
  If n = 0 then
	Raise NO_DATA_FOUND;
  END IF;
Exception
	WHEN NO_DATA_FOUND THEN
		RAISE FORM_FAILURE_TRIGGER;	
	WHEN OTHERS THEN
		Message('asasdsad');

END;


Thanks in Advance,

Veera
Re: Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION [message #557342 is a reply to message #557336] Tue, 12 June 2012 00:58 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It is FORM_TRIGGER_FAILURE, not FORM_FAILURE_TRIGGER.
Re: Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION [message #557369 is a reply to message #557342] Tue, 12 June 2012 03:19 Go to previous messageGo to next message
mvmkandan
Messages: 68
Registered: May 2010
Location: Trivendrum
Member
oh sorry...

My requirement, if there is no record in emp table when validate the EMP_NO_CHK text field, i need to set the focus on that field (EMP_NO_CHK) itself.
But while execute the following code, I got error. Please suggest me anyone to achieve the task.



--EMP_NO_CHK_WHEN_VALIDATE_ITEM Trigger
-----------------------------------
Declare
cursor c is Select * from emp where Emp_no = :header.empno;
c1 emp%rowtype;
n NUMBER;
BEGIN
  OPEN c;
  Loop
	FETCH c into C1;
	Exit when c%notfound;
	n := n + 1;
  END LOOP:
  CLOSE c;
  If n = 0 then
	Raise NO_DATA_FOUND;
  END IF;
Exception
	WHEN NO_DATA_FOUND THEN
		RAISE FORM_TRIGGER_FAILURE;	
	WHEN OTHERS THEN
		Message('asasdsad');

END;


Thanks in Advance,

Veera
Re: Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION [message #557379 is a reply to message #557369] Tue, 12 June 2012 06:23 Go to previous messageGo to next message
sandeepgujje
Messages: 28
Registered: January 2012
Location: India
Junior Member
actually that task will be so easy if you can use a direct SELECT statement instead of a CURSOR

DECLARE
  v_count NUMBER;
BEGIN
  SELECT COUNT(*)
  INTO v_count
  FROM EMP
  WHERE Emp_No = :HEADER.EMPNO;
  
  IF v_count > 0 THEN
     MESSAGE('The Number of Records Found - '||v_count);
  ELSE
     RAISE FORM_TRIGGER_FAILURE;
  END IF;
END;

(OR)

DECLARE
  v_empno NUMBER;
BEGIN
  SELECT Emp_No
  INTO v_empno
  FROM EMP
  WHERE Emp_No = :HEADER.EMPNO;

  MESSAGE('This means it has got some Records');
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    MESSAGE('No Data Found..!!');
    RAISE FORM_TRIGGER_FAILURE;
  WHEN OTHERS THEN
    MESSAGE('Error - '||SQLCODE);
END;


Hope this helps..!!

Re: Can we use RAISE FORM_FAILURE_TRIGGER in EXCEPTION [message #557382 is a reply to message #557379] Tue, 12 June 2012 06:29 Go to previous message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
Your code doesn't work because you don't assign an initial value to n.
So is n is null.
null + 1 is null.
So n is always null, nver 0.

Set it to 0 at the start of the code an it'll work.
Better yet use sandeepgujje's second code example.
Previous Topic: Need Help TO Typing,Inserting,Updating and display on Reprt in HINDI FONT
Next Topic: How can we rollback back once we commited
Goto Forum:
  


Current Time: Fri Jul 05 22:10:49 CDT 2024