I'm working on altering sequence through sqlplus in a shell script. What I'm about to do is to get the max seq_no of the table, set the value in v_increment_num, and increase the sequence by v_increment_num. But it gets an error when alter statement runs.
The script is like below.
echo start load_my_adm_user.sh
sqlplus myId/myPassword <<EOF
set echo on
set time on
set timing on
set serveroutput on
spool TB_MY_ADM_USER.log
var v_increment_num varchar2(1000);
SELECT MAX(SEQ_NO) INTO :v_increment_num FROM TB_MY_ADM_USER;
alter sequence mydb.SQ_ADM_USER increment by v_increment_num;
select mydb.SQ_ADM_USER.nextval from dual;
alter sequence mydb.SQ_ADM_USER increment by 1;
spool off
EOF
exit
and the running result(TB_MY_ADM_USER.log) is like:
07:01:23 SQL> SELECT MAX(SEQ_NO) INTO :v_increment_num FROM TB_MY_ADM_USER;
MAX(SEQ_NO)
-----------
4
Elapsed: 00:00:00.00
07:01:23 SQL>
07:01:23 SQL> alter sequence mydb.SQ_ADM_USER increment by v_increment_num;
alter sequence mydb.SQ_ADM_USER increment by v_increment_num
*
ERROR at line 1:
ORA-01722: invalid number
Elapsed: 00:00:00.00
07:01:23 SQL>
07:01:23 SQL> select mydb.SQ_ADM_USER.nextval from dual;
NEXTVAL
----------
19
Elapsed: 00:00:00.02
07:01:23 SQL> alter sequence mydb.SQ_ADM_USER increment by 1;
Sequence altered.
Elapsed: 00:00:00.02
What exactly am I doing wrong? Thanks in advance.