μλμΌλ‘ λ³κ²½λλ κ°μ νλνκΈ° μν κΈ°λ₯
π¨ μνμ€ νΈμΆ μ΄ν λ€μ λ€λ‘ λμκ°μκ° μλ€.
CREATE SEQUENCE μνμ€μ΄λ¦
START WITH μμνλμ«μκ° (κΈ°λ³Έκ° 1) -> 1λΆν°
INCREMENT BY μ¦κ°ν μ«μκ° (κΈ°λ³Έκ° 1) -> 1μ© μ¦κ°
MINVALUE μ΅μκ° 1
MAXVALUE μ΅λκ° 6
CYCLE | NOCYCLE μνμ¬λΆ
CACHE μ«μ | NOCACHE μΊμ±μ¬λΆ (κΈ°λ³Έκ° 20) --μΊμλ©λͺ¨λ¦¬ : μμμ°½κ³
μνμ€μ΄λ¦.nextval : μνμ€κ° νλ (SELECT μνμ€μ΄λ¦.nextval FROM dual);
μνμ€μ΄λ¦.currval : νμ¬ μνμ€κ° μ‘°ν(νμΈλ§) (SELECT μνμ€μ΄λ¦.currval FROM dual);
DROP SEQUENCE μνμ€μ΄λ¦;
μνμ€ μ€μ λ³κ²½
ALTER SEQUENCE μνμ€μ΄λ¦
λ°κΏ μ€μ
νμ¬ κ° νμΈ
INCREMENT BY μ‘°μ (λ€μ nextval λΆλ μλ 1μ΄ λλλ‘)
nextval μ€ν
INCREMENT BY μ‘°μ
--μνμ€ μμ±
CREATE SEQUENCE sample_seq
START WITH 100
INCREMENT BY 1
MAXVALUE 110
MINVALUE 90
CYCLE;
--μνμ€ μ¬μ©
SELECT sample_seq.nextval FROM dual;
--νμ¬ μνμ€ νμΈ
SELECT sample_seq.currval FROM dual;
π¨
--μ»¬λΌ : id, no, member_id, point, grade-date
INSERT INTO T_MEMBER_POINT
VALUES (T_MEMBER_POINT_PK_SEQ.nextval,
(SELECT NVL(MAX(no), 0)+1 FROM T_MEMBER_POINT
WHERE member_id = 'abc1'),
'abc1',
30,
SYSDATE);
==> T_MEMBER_POINT_PK_SEQ μνμ€κ°μ idμ μ¬μ©νκ³
==> μ΄λ κ² λμ€κ² νκΈ°μν΄μλ noλ abc1 μ μλ², def1 μ μλ²μ λ»νλκΉ
(SELECT NVL(MAX(no), 0)+1
FROM T_MEMBER_POINT
WHERE member_id = 'abc1')
(SELECT NVL(MAX(no), 0)+1
FROM T_MEMBER_POINT
WHERE member_id = 'def1')
NVL(νΉμ 컬λΌ, κΈ°λ³Έ λ체κ°) -> NULLκ°μ λ€λ₯Έ κΈ°λ³Έκ°μΌλ‘ λ체 -> μ²μμ 1μ΄ λλλ‘ μΈν
νκ³ !
κ°κ° μλ²μ λ§κ² λμ€λλ‘ νλ€!