| What am I doing wrong here... [message #563523] |
Tue, 14 August 2012 11:09  |
 |
gblackiv
Messages: 15 Registered: August 2012 Location: Springfield VA
|
Junior Member |
|
|
I am a relative novice at PL SQL... That said... What I would like to do is reset my sequence to 10,000 (or 10,001 is fine as well).
I'm having issues executing the proc. Also, I couldn't figure out how to insert directly from a grouped insert statement into a variable... so I used a cursor with only one record, to do this... there's probably a far easier way to do this, but I didn't know it.
I' getting this as my error message:
Quote: ORA-06550: line 1, column 42:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted for "end-of-file" to continue.
Any help would be greatly appreciated!
CREATE OR REPLACE
PROCEDURE S00050_RESET_POINVASS_SEQUENCE
AS
v_SEQUENCE_NAME VARCHAR2 (50) := 'POINVASS_ID_SEQ';
v_STATEMENT VARCHAR2(2000);
v_MAX_POINVASS_ID NUMBER;
CURSOR cv_RESET_SEQUENCE_cursor IS
SELECT MAX(POINVASS_ID) MAX_POINVASS_ID
FROM P0100_PO_INV_ASSETS;
BEGIN
OPEN cv_RESET_SEQUENCE_cursor;
LOOP
FETCH cv_RESET_SEQUENCE_cursor
INTO v_MAX_POINVASS_ID;
EXIT WHEN cv_RESET_SEQUENCE_cursor%NOTFOUND;
END LOOP;
v_STATEMENT := 'ALTER SEQUENCE ' || v_SEQUENCE_NAME ||' INCREMENT BY -' || TO_CHAR(v_MAX_POINVASS_ID, '99,999');
EXECUTE IMMEDIATE v_STATEMENT;
v_STATEMENT := 'SELECT '|| v_SEQUENCE_NAME ||'.NEXTVAL FROM dual';
EXECUTE IMMEDIATE v_STATEMENT; --This should bring the sequence to zero
v_STATEMENT := 'ALTER SEQUENCE ' || v_SEQUENCE_NAME ||' INCREMENT BY 10000';
EXECUTE IMMEDIATE v_STATEMENT;
v_STATEMENT := 'SELECT '|| v_SEQUENCE_NAME ||'.NEXTVAL FROM dual';
EXECUTE IMMEDIATE v_STATEMENT; --This should bring the sequence to 10000
v_STATEMENT := 'ALTER SEQUENCE ' || v_SEQUENCE_NAME ||' INCREMENT BY 1';
EXECUTE IMMEDIATE v_STATEMENT; --This should make the next NEXTVAL = 10,001
END S00050_RESET_POINVASS_SEQUENCE;
END;
/
Thanks for taking the time to look at this,
-Gary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: What am I doing wrong here... [message #563532 is a reply to message #563528] |
Tue, 14 August 2012 12:11   |
joy_division
Messages: 4267 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
|
It's the old "privileges granted through roles do not translate to stored procedures." You must have the privilege granted directly to you by a SYS or another user with DBA rights.
|
|
|
|
|
|