Hi,
I found a tricky situation.
- I create a change set with an sql statement like following.
<changeSet id=“1” author=“Stephane Clinckart” dbms=“oracle”>
DECLARE
table_name VARCHAR2(30);
column_name VARCHAR2(30);
sequence_start NUMBER;
stmt VARCHAR2(2000);
BEGIN
table_name :=‘alf_transaction’;
column_name :=‘id’;
stmt := ‘select nvl(max(’ || column_name || ‘),0)+1 from ’ || table_name;
dbms_output.put_line(‘Executing ‘’’ || stmt || ‘’’’);
EXECUTE immediate stmt INTO sequence_start;
stmt := ‘create sequence ’ || table_name || ‘_seq ’ ||’ start with ’ || to_char(sequence_start) ;
dbms_output.put_line(‘Executing ‘’’ || stmt || ‘’’’);
EXECUTE immediate stmt;
END;
This is working correctly in most of the situation (let say on different envirronment).
But… now I found some new envirronement where this sql script can’t run like it is written.
The correct script should be:
<changeSet id=“1” author=“Stephane Clinckart” dbms=“oracle”>
DECLARE
table_name VARCHAR2(30);
column_name VARCHAR2(30);
sequence_start NUMBER :=1;
stmt VARCHAR2(2000);
table_exist INTEGER;
BEGIN
table_name :=‘alf_transaction’;
column_name :=‘id’;
stmt := ‘select nvl(max(’ || column_name || ‘),0)+1 from ’ || table_name;
dbms_output.put_line(‘Executing ‘’’ || stmt || ‘’’’);
EXECUTE immediate ‘select count(*) from user_tables where table_name = ‘’’ || table_name || ‘’’’ INTO table_exist;
IF(table_exist > 0)
THEN
EXECUTE immediate stmt INTO sequence_start;
END IF;
stmt := ‘create sequence ’ || table_name || ‘_seq ’ ||’ start with ’ || to_char(sequence_start) ;
dbms_output.put_line(‘Executing ‘’’ || stmt || ‘’’’);
EXECUTE immediate stmt;
END;
In fact, I try to “correct” the script himself… who is running in same situation and not in another one in the original release.
But, if I try to run this correct script on an existing system, I will get a checksum error.
So, How to handle this tricky situation?
Thanks a lot for help
Stephane Clinckart