Last active
February 19, 2016 13:34
-
-
Save arbo-hacker/83a35269ba2ccae2e5bb to your computer and use it in GitHub Desktop.
Auto_increment en Oracle 12c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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