Home » Developer & Programmer » Forms » form trigger
form trigger [message #144473] Wed, 26 October 2005 11:23 Go to next message
Sharaf
Messages: 62
Registered: September 2005
Location: U.K
Member
please i need to attach a trigger created to my oracle form 10g.

I have already created the trigger in sql plus to generate an alphanumeric primary key on insert in my table, and they work fine in sql plus, but i have added forms to my database. now i need to get the trigger working on my form.

the trigger is shown below.

CREATE SEQUENCE patron_id_seq


CREATE OR REPLACE TRIGGER patron_id_trigger
BEFORE INSERT ON patron FOR EACH ROW
BEGIN
SELECT 'P' || TO_CHAR(patron_id_seq.NEXTVAL,'fm000000000')
INTO :new.patron_id
FROM DUAL;
END patron_id_trigger;


thanks.
Re: form trigger [message #144514 is a reply to message #144473] Wed, 26 October 2005 19:31 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
I assume that you don't mind having 'gaps' in your Patron_ID otherwise use the max+1 method. Also, do not populate :new.patron_id unless it is null.

In a When-Create-Record trigger on your block have the following:
begin
  if :blk.patron_id is null then
    SELECT 'P' || TO_CHAR(patron_id_seq.NEXTVAL,'fm000000000')
      INTO :blk.patron_id
      FROM DUAL;
  end if;
end;

David
Re: form trigger [message #144603 is a reply to message #144514] Thu, 27 October 2005 06:50 Go to previous messageGo to next message
Sharaf
Messages: 62
Registered: September 2005
Location: U.K
Member
thanks for your time.

I tried the statement as suggested.

but when i compile it it is showing the error as shown below.

begin
if :loan.loan_id is null then
SELECT 'L' || TO_CHAR(loan_id_seq.NEXTVAL,'fm000000000')
INTO :loan.loan_id
FROM DUAL;
end if;
end;


error message.

Error 201 at line 5, column 12
identifier 'DUAL' must be declared
Re: form trigger [message #144724 is a reply to message #144603] Thu, 27 October 2005 18:39 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
You have to connect to the database before you compile and run your form.

David
Previous Topic: form values.
Next Topic: Forms 4.5 calling function defined in database package not working
Goto Forum:
  


Current Time: Fri Sep 20 03:36:25 CDT 2024