I am trying to use autoincrement on my package without using trigger.. Can someone explain me how I have to use it in my package.. I did this way didnt work its complaining abt variable not being declared or type not assigned.. I saw other autoincrement questions but nobody has used auto increment without trigger on package
PROCEDURE insertExample (
user_id_in IN sample.seq_user_id.nextval,
name_in IN sample.name%TYPE,
age_in IN sample.age%TYPE )
IS
BEGIN
INSERT INTO sample
(seq_user_id.nextval, name, age)
VALUES
(user_id_in, name_in, age_in);
END insertExample;
Are you wanting to allow a custom user_id to be passed in or always use the sequence?
In the first case, you would need something like:
CREATE OR REPLACE PROCEDURE insertexample (
user_id_in in sample.user_id%type,
name_in in sample.name%type,
age_in in sample.age%type
)
IS
BEGIN
insert into sample
(user_id, name, age
)
values (nvl(user_id_in, seq_user_id.nextval), name_in, age_in);
END insertexample;
If you always want to use the sequence (which is probably the right choice), just take out that input parameter and the NVL:
CREATE OR REPLACE PROCEDURE insertexample (
name_in in sample.name%type,
age_in in sample.age%type
)
IS
BEGIN
insert into sample
(user_id, name, age
)
values (seq_user_id.nextval, name_in, age_in);
END insertexample;
You want something like
PROCEDURE insertExample (
name_in IN sample.name%TYPE,
age_in IN sample.age%TYPE )
IS
BEGIN
INSERT INTO sample
(user_id, name, age)
VALUES
(seq_user_id.nextval, name_in, age_in);
END insertExample;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With