使用MSSQL -i只能在存在同义词的情况下才能删除它:删除同义词(Transact-SQL)
但是在Oracle (11g)中,drop同义词会导致我的脚本出错,如果它不退出,有什么方法来模仿它存在的MSSQL吗?
发布于 2017-02-27 17:25:44
您可以使用PLSQL匿名块:
begin
execute immediate 'drop synonym YOUR_SYNONYM';
exception
when others then
if sqlcode != -1434 then
raise;
end if;
end;
/如果存在,它将删除您的同义词。如果它不存在,它只会抑制错误。它将向调用方引发“同义词不存在”以外的任何错误。
发布于 2017-02-28 17:23:32
显然你可以写:创建或替换同义词
发布于 2017-02-27 17:57:33
您可以使用杂注来定义异常,然后可以处理异常。假设你在循环中做什么.
declare
NOSYN exception;
pragma exception_init ( NOSYN, -1434 );
/* 1434 is the Oracle error for synonym does not exist */
begin
/*
* Loop here where you synonym name gets assigned to the variable mysyn
*/
begin
execute immediate 'drop synonym '||mysyn;
exception
when NOSYN then
dbms_output.put_line( 'Synonym does not exist... skipping' );
end;
end loop;
end;
/https://stackoverflow.com/questions/42491900
复制相似问题