|
-
Jul 4th, 2000, 10:42 PM
#1
Thread Starter
Member
Hi! is there somebody who can help?
My problem is something like this...
I want to add several records in a table. The table has a field whose value must be system generated but not autogenerated by the database. The value must come from "SELECT max(code) FROM table" statement.
Well, this is quite easy if you're on a standalone environment but my application is on a WAN with quite a large number of users and generating unique code is not easy considering users can ADD SEVERAL NEW RECORDS BEFORE SAVING. That complicates an easy problem.
Now, the question is how can i generate a sequential code on every record I inserted in the table before saving the records?
anybody? With Oracle Developer/2000, it can be accomplished with the Pre-Insert Trigger of a block.
thanks!
Mikey
A/P
Using VB6 SP4 Enterprise Ed.
-
Jul 4th, 2000, 11:37 PM
#2
Hyperactive Member
You want to have just a unique key, or must be a sequential number without skipping?
-
Jul 5th, 2000, 01:01 AM
#3
Lively Member
Use another table where you save the last key generate.
Before add a new record, get this number, add 1, save the result in the table and use the result like code for you new record.
-
Jul 5th, 2000, 01:21 AM
#4
Thread Starter
Member
yeah, that's a nice idea but that is almost the same as having an autogenerated key. Suppose the user changed his mind, the sequence number has already incremented. What i need here is to generate the code upon saving the records.
thanks anyway.
Mikey
A/P
Using VB6 SP4 Enterprise Ed.
-
Jul 6th, 2000, 12:30 AM
#5
Lively Member
In this case, the making of the record must be in memory. Before saving the new record, update the ID fields (with any method you want). Then save the record in the table.
-
Jul 6th, 2000, 12:45 AM
#6
Hyperactive Member
Maybe I'm wrong but...
I have good Oracle DB support people here who always do the setup of my tables so I am no Oracle guru. What little I do know about Oracle is that we always use a Sequence (Oracle term). By definition, when you do a select on the sequence (treat it like a table that is only ever selectable, not updateable), the sequence is auto incremented by 1 (or whatever you have specified in the sequence setup), regardless of whether we use the returned value or not!
Sounds perfect for what you want, and it is a 0 line solution. Surely I must be on the wrong track for what you need since it must be available in all version of Oracle?
Hope it helps...
Paul Lewis
-
Jul 6th, 2000, 01:08 AM
#7
Thread Starter
Member
yeah! I know what you're saying. That sequence is much like the same with the autonumber of Access but you need to execute a select nextval to generate code. I use also use that and my main concern is how to capture(if there is any) the event similar to PRE-INSERT TRIGGER of blocks in Oracle Developer/2000.
I cannot immediately get the sequence since it can't be decreased supposed the user changed his mind in adding records. In that way, your sequence has already incremented although the user haven't really inserted a record yet. Just imagine, if the user clicked on addnew then cancelupdate then addnew then cancelupdate and so on for a hundred times, your sequence has already incremented a hundred times. What if you have 100 users doing that everyday? That's what i'm trying to avoid. I need to fill the fields with codes only after the user trigger the SAVE button so that no matter how many times the user changes his mind, the sequence won't be affected at all.
KWell got my idea. The problem is, i want a more faster and simpler code that would do the job.
Mikey
A/P
Using VB6 SP4 Enterprise Ed.
-
Jul 6th, 2000, 01:23 AM
#8
Hyperactive Member
This is a problem for a long time already, in my memory, more than 20 years old problem. Disregard which database you are using.
In you are running in a single user environment (only one user update to the database), then you can easily achieve the objective.
If your are running under a multiple users environment, this is a no-solution problem. (There is only one ERP application I saw before which solve it by building a table containing all available numbers and set a temporary flag)
In multiple users environment, you either :
get the number when press 'New' - once you get the number from a table, you must commit changes, otherwise deadlock other users. But in this case, you will have skipping numbers.
get the number before save - this is the most common one, but this cannot solve your problem.
I can't see any alternative for the past 15 years, unless it is in a single user environment.
If any brilliant idea can solve this simply, I do think that quite a lot of ERP software vendor will be interested.
-
Jul 6th, 2000, 01:40 AM
#9
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|