How to create sequence. [message #662532] |
Fri, 05 May 2017 03:58 |
|
mashhoodnasir
Messages: 26 Registered: May 2017
|
Junior Member |
|
|
I have a block named:EMPLOYEE_DATA defined in oracle form.
i want to auto-generate emp_id. i tried following method but it didnt work:
STEP 1:
-------
CREATE SEQUENCE EMP_iD
START WITH 1001
INCREMENTED BY 1
NOMAXVALUE
NOCYCLE
NOCACHE;
STEP-2:
--------
CREATE TRIGGER AT FORM: WHEN-NEW-FORM-INSTANCE
SELECT EMP_NO.NEXTVAL INTO :EMP_NO FROM EMPLOYEE_DATA;
Kindly help me regarding this issue.
|
|
|
|
Re: How to create sequence. [message #662546 is a reply to message #662536] |
Fri, 05 May 2017 04:48 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Well WNFI is the wrong trigger to use - I assume you want users to be able to create more than one record, so putting it in a trigger that runs once per form makes no sense.
Also, as in your other thread - that'll only work if employee_data contains exactly one row.
If you need to run a function through a SQL statement use dual, that's what it's there for:
SELECT EMP_NO.NEXTVAL INTO :EMP_NO FROM DUAL;
Dual is a special oracle table that always contains exactly one row. It exists to do things like this.
As for the trigger - when-new-record-instance or pre-insert would make more sense.
[Updated on: Fri, 05 May 2017 04:48] Report message to a moderator
|
|
|
|
|
|
|
|
Re: How to create sequence. [message #662614 is a reply to message #662607] |
Mon, 08 May 2017 02:50 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
mashhoodnasir wrote on Sat, 06 May 2017 10:06yes you are right i already tried with dual table and its working fine but i want to try it with EMP table which is initially blank.
Don't know why you think you want to try that with emp, but you don't. If you want run a function once from a SQL (and sequence.nextval is a function) then you use dual, always.
mashhoodnasir wrote on Sat, 06 May 2017 19:25
but i want to restrict auto generation until the new record is committed in the database. i means to say whenever i open form it shows current value and once i insert data into it it will generate new next after reopening the form.
Why do you want to do that? It's not a standard way of working and it just makes your life, and the users life, harder than it needs to be.
Just set the form to allow the users to insert as many rows as they like.
|
|
|
|
|
Re: How to create sequence. [message #662643 is a reply to message #662628] |
Mon, 08 May 2017 13:01 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
mashhoodnasir wrote on Mon, 08 May 2017 06:40@cookiemonster
when_new_record_instance working fine for me. but still there is a problem. whenever i run the form it shows new value. my requirement is that it will generate next number only when other fields save in database.
Then you are in fantasy land. A sequence is meant to provide a unique value, most likely a primary key. In no way is it to be used to have be a gapless consecutive number for multiple reasons such a transaction failure, you are running RAC, etc.
|
|
|