I'm trying to run the following Oracle SQL script which should create a new column, TEMPLATE, and populate it with some base values, but I'm getting an error.
DECLARE v_cnt INT;
BEGIN
select count(*) into v_cnt
from user_tab_columns
where upper(table_name) = upper('myTable') and upper(column_name) = upper('template');
IF(v_cnt = 0) THEN
EXECUTE IMMEDIATE 'ALTER TABLE MYTABLE ADD TEMPLATE NVARCHAR2(255)';
UPDATE MYTABLE
SET TEMPLATE = 'BASE VALUE';
END IF;
END; /
The error that I'm getting is
ORA-06550: line 10, column 37:
PL/SQL: ORA-00904: "TEMPLATE": invalid identifier
When trying to run these statements manually, everything seems to be working fine. I believe the issue is related to the EXECUTE IMMEDIATE portion, with which I'm not familiar. After preliminary Googling I can't determine that this statement is asynchronous or anything like that, so in theory there should be no error thrown there.