Maliki Hassani
asked on
ORACLE 10g: Function - insert unique identifier using sequence
Experts,
I have a function that truncates a table and inserts new data. The data that is being inserted doesn't have a unique ID nor does it have a field that is unique in records. Therefore, I want to create a unique id for each row, which has to be numbers only. Any ideas on how to accomplish this?
Example:
Colum1 (ID)
1
2
3
4
5
etc
Thanks!
I have a function that truncates a table and inserts new data. The data that is being inserted doesn't have a unique ID nor does it have a field that is unique in records. Therefore, I want to create a unique id for each row, which has to be numbers only. Any ideas on how to accomplish this?
Example:
Colum1 (ID)
1
2
3
4
5
etc
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also, if this is 12c, you can associate a sequence with a column to create an "identity column" like you see in other databases.
ASKER
Great I will give this a try!
ASKER
I used rownum and that that worked. Do I need to have a sequence added and applied or just use rownum?
ASKER
Let me rephrase that.. as for speed is it better to use sequence or row number? Thanks
the difference will be very minor, but rownum should probably be minorly more efficient since it never has to update the data dictionary but a sequence with a large cache value will minimize that.
Best way to verify is to simply run both on your system and test results.
Best way to verify is to simply run both on your system and test results.