130 likes | 371 Views
Oracle Sequence. Perancangan Basis Data. Sequence. What is sequence? How to use Alter Sequence Drop Sequence. What is sequence?. Sequence adalah object yang dapat men- generate unique sequential values . Nilai ini biasanya digunakan sebagai primary ataupun unique keys.
E N D
Oracle Sequence Perancangan Basis Data
Sequence • What is sequence? • How to use • Alter Sequence • Drop Sequence
What is sequence? • Sequenceadalah object yang dapat men-generate unique sequential values. Nilaiinibiasanyadigunakansebagaiprimaryataupununique keys. • Dapatdipanggilmenggunakanperintah SQL padapseudocolumnberikut: • CURRVAL: menampilkannilai sequence saatini • NEXTVAL: menampilkannilaiselanjutnya
How to Use – Create Sequence • Schema Sequence:
How to Use – Create Sequence (cont’d) • Membuat Sequence: CREATE SEQUENCE customers_seq START WITH 1000 INCREMENT BY 1 NOCACHE NOCYCLE; • Melihat Sequence: SELECTcustomers_seq.nextval FROM DUAL;
How to Use – Create Sequence (cont’d) • Inserting sequence values into a table: Example INSERT INTOemployeesVALUES (employees_seq.nextval, 'John', 'Doe', 'jdoe', '555-1212', TO_DATE(SYSDATE), 'PU_CLERK', 2500, null, null, 30); • Reusing the current value of a sequence: Example • INSERT INTOorders (order_id, order_date, customer_id) VALUES (orders_seq.nextval, TO_DATE(SYSDATE), 106); • INSERT INTO order_items (order_id, line_item_id, product_id) VALUES (orders_seq.currval, 1, 2359); • INSERT INTO order_items (order_id, line_item_id, product_id) VALUES (orders_seq.currval, 2, 3290); • INSERT INTO order_items (order_id, line_item_id, product_id) VALUES (orders_seq.currval, 3, 2381);
Alter Sequence • Schema:
Alter Schema (cont’d) • Deskripsi: ALTER SEQUENCE [schema.] sequence {INCREMENT BY integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } } ... ; • Syntax: • ALTER SEQUENCE customers_seq MAXVALUE 1500; • ALTER SEQUENCE customers_seq CYCLE CACHE 5;
Drop Sequence • Schema: • Deskripsi: DROP SEQUENCE [schema.] sequence_name ;
FAQ: • Question:Ketikamembuat sequence, apaarticachedannocache? Contohnya, membuat sequence dengan cache sebesar 20 sebagaiberikut: CREATE SEQUENCE supplier_seq MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 20; dan CREATE SEQUENCE supplier_seq MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE;
FAQ: • Bagaimanamelakukanperubahanlastvaluepada sequence? Sebagaicontoh, sekarangnilaiterakhirnyaadalah 100, dan sequence selanjutnyaadalah 300.