I tried to insert a set of rows as soon as a table is created using the following query in Java as followed:
DECLARE tbl_exist PLS_INTEGER;
BEGIN
select count(*) into tbl_exist from user_tables where table_name = 'REPRO_PRINTING_JOB_STATE';
if tbl_exist = 0 then
execute immediate 'create table REPRO_PRINTING_JOB_STATE (
ID varchar2(2) not null primary key,
NAME varchar(255) not null )';
execute immediate 'insert into REPRO_PRINTING_JOB_STATE (ID, NAME) values ('QU','IN THE QUEUE')';
execute immediate 'insert into REPRO_PRINTING_JOB_STATE (ID, NAME) values ('IN','INCIDENT')';
execute immediate 'insert into REPRO_PRINTING_JOB_STATE (ID, NAME) values ('CM','COMPLETED')';
execute immediate 'insert into REPRO_PRINTING_JOB_STATE (ID, NAME) values ('PR','PROCESSING')';
execute immediate 'insert into REPRO_PRINTING_JOB_STATE (ID, NAME) values ('CN','CANCELLED')';
end if;
END;
It failed. Was this because the use of “execute immediate” statement?
Based on your first iteration of the question, it probably fails because your first insert is into a totally different table:
In other words, you’re using
PRINTING_JOB_STATEinstead ofREPRO_PRINTING_JOB_STATE.However, now that you’ve confirmed that was just a simple typo on your part, you need to check your use of the single quotes in the insert statements. The fact that your dynamic string is surrounded by
'characters means that using'inside the string (around things likeQU) will be problematic.You’ll probably need to escape the quotes by using duplicated quotes, such as with:
That’s two single quotes on either side of the
QUandQUEUED, not a double quote.