SELECT MAX(class_id) FROM classes;
-Execute and see the result=6;

CREATE SEQUENCE class_id_sec_car
 START WITH 7
 INCREMENT BY 1
 NOCACHE;

DECLARE
v_new_class_no NUMBER(6,0) DEFAULT 1;
v_c_id classes.course_id%type;
v_period classes.period%type;
v_f classes.frequency%type;
v_i classes.instr_id%type;
BEGIN
for i in 1..v_new_class_no 
loop
insert into classes (class_id, start_date,course_id,period,frequency,instr_id)
values (class_id_sec_car.nextval,sysdate,v_c_id,v_period,v_f,v_i);
commit;
end loop;
END;





DECLARE
x INTEGER;
v_new_class_no NUMBER(6,0) DEFAULT 1;
BEGIN
select max(class_id) into x from classes;
dbms_output.put_line(x);
execute immediate 'create sequence a start with 2';
END;
END;

create or replace procedure p
as
x integer;
begin
select max(class_id) into x from classes;
  execute immediate 'create sequence s start with x';
end;


create or replace procedure p
as
x integer;
begin
select max(class_id) into x from classes;
  execute immediate 'create sequence s start with x+1';
end;

declare
v_new_class_no NUMBER(6,0) DEFAULT 1;
v_c_id classes.course_id%type;
v_period classes.period%type;
v_f classes.frequency%type;
v_i classes.instr_id%type;
begin
p;
for i in 1..v_new_class_no 
loop
insert into classes (class_id, start_date,course_id,period,frequency,instr_id)
values (s.nextval,sysdate,v_c_id,v_period,v_f,v_i);
commit;
end loop;
end;

declare
v_new_class_no NUMBER(6,0) DEFAULT 1;
v_c_id classes.course_id%type;
v_period classes.period%type;
v_f classes.frequency%type;
v_i classes.instr_id%type;
x integer;
begin
select 'CREATE SEQUENCE scar START WITH '||MAX(class_id)+1||' INCREMENT BY 1 NOCACHE' into x from classes;
dbms_output.put_line(x);
for i in 1..v_new_class_no 
loop
insert into classes (class_id, start_date,course_id,period,frequency,instr_id)
values (s.nextval,sysdate,v_c_id,v_period,v_f,v_i);
commit;
end loop;

end;