inserting a sequence based new record thru a procedure
29240Apr 9 2006 — edited Mar 8 2007Hi,
I just want to be able to insert new records with the primary key based on a sequence and it has been giving me all sorts of error even though the procedure compiled successfully.
Help me please, I am just learning
create table test(
id number(2) primary key,
name varchar2(10));
create sequence seq_id start with 1;
insert into test values(seq_id.nextval,'john');
insert into test values(seq_id.nextval,'best');
SQL> CREATE OR REPLACE PROCEDURE new_test (
2
3 p_id IN test.id%type,p_name IN test.name%type)
4
5 AS
6 --DECLARE
7
8 --V_id NUMBER(2);
9
10 BEGIN
11
12 --SELECT seq_id.NEXTVAL INTO v_id FROM DUAL;
13
14 INSERT INTO test(id, name)VALUES (p_id, p_name);
15 END;
16 /
Procedure created.
SQL>
SQL> exec new_test(seq_id.nextval,'peter');
BEGIN new_test(seq_id.nextval,'peter'); END;
*
ERROR at line 1:
ORA-06550: line 1, column 23:
PLS-00357: Table,View Or Sequence reference 'SEQ_ID.NEXTVAL' not allowed in
this context
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Many thanks
cube60