Create a gist now

Instantly share code, notes, and snippets.

Auto_increment en Oracle 12c
CREATE SEQUENCE dept_seq;
CREATE TABLE departments (
ID NUMBER(10) NOT NULL,
DESCRIPTION VARCHAR2(50) NOT NULL);
CREATE OR REPLACE TRIGGER dept_bir
BEFORE INSERT ON departments
FOR EACH ROW
BEGIN
SELECT dept_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
/
-- Para leer la explicación completa entra en http://arbo.com.ve/2016/02/19/auto_increment-en-oracle-novedades-oracle-12c/
-- Primer metodo
CREATE SEQUENCE dept_seq;
CREATE TABLE dpto (
DPTO_CODE NUMBER(10) DEFAULT dept_seq.NEXTVAL,
DPTO_DESC VARCHAR2(50) NOT NULL);
-- Segundo metodo
CREATE TABLE t1 (id NUMBER GENERATED AS IDENTITY);
-- O especificando el incremento en cada inserción a la tabla
CREATE TABLE t2 (id NUMBER GENERATED
BY DEFAULT AS IDENTITY (START WITH 100 INCREMENT BY 10));
-- Para leer la explicación completa entra en http://arbo.com.ve/2016/02/19/auto_increment-en-oracle-novedades-oracle-12c/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment