Home » Developer & Programmer » Forms » pre_insert (Form 6i, database 10g)
pre_insert [message #685705] Thu, 10 March 2022 02:51 Go to next message
shahzad-ul-hasan
Messages: 600
Registered: August 2002
Senior Member
Quote:

Table name: test
Fields
tid number;
tdate date;
composite primary key(tid,tdate);
Pre-insert Trigger code:
select nvl(max(tid),0)+1 into :test.tid from test;
i am using pre insert trigger on primary key field (tid). but it is not insert data into tid from last tow days. i have rewrite code of pre-insert but failed.please advised.
Re: pre_insert [message #685714 is a reply to message #685705] Thu, 10 March 2022 14:59 Go to previous message
Littlefoot
Messages: 21732
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
If table is empty, code you wrote will return 1 as a result:
SQL> select * from test;

no rows selected

SQL> select nvl(max(id), 0) + 1 from test;

NVL(MAX(ID),0)+1
----------------
               1

SQL>
So, what does exactly mean that "it is not inserted from last two days"? Did it work 3 days ago? Or what? Besides, did you COMMIT?



Anyway, what you're doing - you're doing it wrong. It'll work in a single user environment, but not when many users use the same form at the same time. Sooner or later, two of them will fetch the same MAX + 1 value, and that's probably not what you wanted.

Consider using a sequence instead, either in a form or in a BEFORE INSERT database trigger. As you're on 10g, you can't use an identity column.
Previous Topic: Capturing video web cam using API
Next Topic: disable button after press (Prevent multi click)
Goto Forum:
  


Current Time: Fri Jul 01 03:41:43 CDT 2022