以下内容摘自我在检查backup_schedule
表中的schema_info
值后创建逻辑备份的过程:
CREATE OR REPLACE PROCEDURE BACKUP_EXECUTE
(
[...]
) AS
[...]
schemas varchar2(255):=' ';
cursor schema_name is select upper(schema_name) schema_name from schema_info
where backup_schedule like '%'||to_char(sysdate, 'D')||'%'
and exists (select * from dba_users where username=upper(schema_name));
type sl is table of schema_name%ROWTYPE
index by pls_integer;
schema_list sl;
BEGIN
open schema_name;
fetch schema_name bulk collect into schema_list;
close schema_name;
if schema_list.count != 0 then
for indx in 1..schema_list.count loop
if(schemas not like '%'||schema_list(indx).schema_name||'%') then
if indx>1 then
schemas:=schemas||',';
else
schemas:=null;
end if;
schemas:=schemas||''''||schema_list(indx).schema_name||'''';
end if;
end loop;
[...]
end if;
EXCEPTION
[...]
END;
除了事实,这可以做得更好,我想专注于一件事。我们知道like
不符合null
值。我应该保留上面的代码并写下一些后来被删除的起始值,还是最好在nvl(schemas,' ')
语句中使用if
?