【发布时间】:2020-08-05 00:37:32
【问题描述】:
DECLARE
v_column_exists number := 0;
BEGIN
Select count(*) into v_column_exists
from user_tab_cols
where upper(column_name) = 'MyCoolColumn'
and upper(table_name) = 'MyCoolTable';
if (v_column_exists = 0) then
execute immediate 'alter table MyCoolTable add (MyCoolColumn varchar2(255))';
execute immediate 'update MyCoolTable set MyCoolColumn = 'NULL'';
end if;
end;
/
不幸的是,我收到了 oracle 错误
ORA-06550
PLS-00103 预期时遇到符号“NULL”......
上线:
execute immediate 'update MyCoolTable set MyCoolColumn = 'NULL'';
我知道我正在插入单词“Null”而不是空值。我正在将此列添加到现有表中,并且需要将其设为 Not Null 和主键以及其他两个主键列。如果我删除问题行,则语句执行正常。
我没有正确地转义“Null”吗?
【问题讨论】: