ORACLE - Create Sequences for autonumber fields
numerical encoding such a product can be made with the creation of a automatically generated sequence of integers in ascending order, is not necessary to remember what was the last number assigned, thus avoiding the duplication of codes.
The sequence is an object that generates unique integer values \u200b\u200bare used to create numeric primary key, using the following command: CREATE SEQUENCE
codigo_producto INCREMENT BY 1 START WITH 100;
In this case the first number generated will be 100, because we put that start from 100
To register a new code with the previously defined sequence used codigo_producto.NEXTVAL column, which will give us the following value that corresponds to the sequence.
For the current value of the sequence, ie, the last assigned code is used codigo_producto.CURRVAL column from system table DUAL, whose purpose is to consult pseudo_columnas:
SELECT user, sysdate, codigo_producto. currval FROM DUAL;
where: 1 .-
user is the user name
2 .- sysdate is the date the system
codigo_producto.currval 3 .- is the last value assigned to the sequence.
EXAMPLE:
PRODUCTOS_SUC INSERT INTO VALUES (codigo_producto.NEXTVAL, 'SHOES');
0 comments:
Post a Comment