How to create id with AUTO_INCREMENT on Oracle?

后端 未结 16 1663
死守一世寂寞
死守一世寂寞 2020-11-21 04:52

It appears that there is no concept of AUTO_INCREMENT in Oracle, up until and including version 11g.

How can I create a column that behaves like auto increment in Or

16条回答
  •  星月不相逢
    2020-11-21 05:52

    FUNCTION UNIQUE2(
     seq IN NUMBER
    ) RETURN VARCHAR2
    AS
     i NUMBER := seq;
     s VARCHAR2(9);
     r NUMBER(2,0);
    BEGIN
      WHILE i > 0 LOOP
        r := MOD( i, 36 );
        i := ( i - r ) / 36;
        IF ( r < 10 ) THEN
          s := TO_CHAR(r) || s;
        ELSE
          s := CHR( 55 + r ) || s;
        END IF;
      END LOOP;
      RETURN 'ID'||LPAD( s, 14, '0' );
    END;
    

提交回复
热议问题