Using Sequences in PL/SQL
CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
SAL NUMBER(7, 2),
DEPTNO NUMBER(2));
CREATE SEQUENCE s_id;
CREATE PROCEDURE add_new_emp
AS
v_id BINARY_INTEGER;
BEGIN
v_id := s_id.nextval;
DBMS_OUTPUT.PUT_LINE('v_id = ' || v_id);
INSERT INTO emp (empno)VALUES (v_id);
DBMS_OUTPUT.PUT_LINE('s_id.currval = ' || s_id.currval);
v_id := s_id.nextval;
DBMS_OUTPUT.PUT_LINE('v_id = ' || v_id);
INSERT INTO emp (empno)VALUES (v_id);
DBMS_OUTPUT.PUT_LINE('s_id.currval = ' || s_id.currval);
END add_new_emp;
/
SET SERVEROUTPUT ON
CALL add_new_emp();
SELECT * FROM emp;
Home »
Oracle »
Table »
Oracle »
Table »
Sequence:
- Creating a Sequence
- Retrieving Information on Sequences
- Using a Sequence
- Populating a Primary Key Using a Sequence
- Modifying a Sequence
- Using Sequences in PL/SQL
- Dropping a Sequence
Related: