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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Using dynamic query to create sequence

tinku981May 31 2013 — edited Jun 1 2013
Hello,

I created the sequence dynamically in a Procedure, but when I executed, it gave me an Insufficient privileges error:


SQL> create table dummy (id number, module_id varchar2(20), p_order number, status varchar2(1));

SQL> insert into dummy values (10, 'test', 0, 'D');

SQL> CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
V_MOD DUMMY.MODULE_ID%TYPE;
v_query1 varchar2(200);
v_query2 varchar2(200);
V_COUNT NUMBER;
begin
v_query1 := 'drop sequence unqid';
v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
SELECT COUNT(*)
INTO V_COUNT
FROM USER_SEQUENCES
WHERE SEQUENCE_NAME = 'UNQID';

IF V_COUNT = 0 THEN
execute immediate v_query2;
ELSE
execute immediate v_query1;
execute immediate v_query2;
END IF;

SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;

update dummy
set P_order = 0, status = 'D'
WHERE ID = P_ID
and module_id = v_mod;
--COMMIT;

execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = V_MOD AND STATUS = ''A''';
--COMMIT;

END PRO_SEQ_ARRNGE;


SQL> exec PRO_SEQ_ARRNGE(10);
BEGIN PRO_SEQ_ARRNGE(10); END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYSTEM.PRO_SEQ_ARRNGE", line 15
ORA-06512: at line 1

Can you please advise how to resolve it?


Thanks in advance,
Tinku

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 29 2013
Added on May 31 2013
14 comments
5,242 views