Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need to drop and recreate sequence in side procedure inside a package

User_H7I9VNov 7 2017 — edited Jan 19 2019

create table emp(empid number,name varchar2(20));

empid name

----- ---

1 ss

2 s

3 sd

create table empbkp( name varchar2(20));

name

---

ff

rr

create sequence seq_empid start with 1 increment by 1;

create or replace package data_load

as

procedure emp_data_load;

end;

create or replace package body data_load

as

procedure emp_data_load

is

ln_id number;

begin

delete from empfinal;

insert into empfinal

(empid,name)

(select empid,name from emp);

execute immediate 'drop sequence seq_empid';

select max(empid)+1 into ln_id  from  empfinal;

execute immediate 'create sequence seq_empid start with ' ||ln_id||   'increment by 1';

execute immediate 'GRANT SELECT ON seq_empid TO xy_role';

insert into empfinal

(empid,name)

(select seq_empid.nextval,name from empbkp);

commit;

exception

when OTHERS then   

  ROLLBACK;

end emp_data_load;

end data_load;

call data_load.emp_data_load();

When i am executing the package , sequence is dropped and but it is not creating and giving below error.

getting ORA-01031: insufficient privileges error

I have tried with AUTHID CURRENT_USER creating standalone stored proc then it is dropping and recreating ,but in side package i can't do.

Could you please hep any one.

Thanks in Advance

This post has been answered by unknown-7404 on Nov 7 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 5 2017
Added on Nov 7 2017
4 comments
1,867 views