我找到了下面的解決方案,但我需要使用PL/SQL存儲過程完成此操作。將可空列轉換爲現有表中不可爲空的可重新運行的腳本
declare
l_nullable varchar2(1);
begin
select nullable into l_nullable
from user_tab_columns
where table_name = 'PV_REPORT_DETAILS'
and column_name = 'FEED_ID';
if l_nullable = 'Y' then
execute immediate 'alter table PV_REPORT_DETAILS modify (Feed_ID not null)';
end if;
select nullable into l_nullable
from user_tab_columns
where table_name = 'PV_REPORT_DETAILS'
and column_name = 'CURRENT_RUN_ID';
if l_nullable = 'Y' then
execute immediate 'alter table PV_REPORT_DETAILS modify (Current_Run_ID not null)';
end if;
select nullable into l_nullable
from user_tab_columns
where table_name = 'PV_REPORT_DETAILS'
and column_name = 'PREVIOUS_RUN_ID';
if l_nullable = 'Y' then
execute immediate 'alter table PV_REPORT_DETAILS modify (Previous_Run_ID not null)';
end if;
end;
:?有什麼問題,你已經找到了匿名塊是正確的,唯一要做的就是包裝,這是procecure。而肯定的,這是再因爲下一次來自user_tab_columns視圖的可空列將獲取「N」 –