topics

全部话题 - 话题: isthere
(共0页)
w****g
发帖数: 1
1
in Oracle, try this one.
declare
isThere varchar2(1);
begin
select 'Y' into isThere
from user_tables
where table_name = 'MYTABLE';
if isThere = 'Y' then
truncate table MYTABLE;
else
create table MYTABLE (....);
end if;
end;
s***t
发帖数: 7
2
it won't work. An error will be generated if more than
one table have the same name under different schemas.
declare
isThere varchar2(1) := 'N';
begin
select 'Y' into isThere
from dual
where exists
(select null from all_tables
where table_name = 'ABC');
if isThere = 'Y' then
dbms_output.put_line('exists');
end if;
exception
when no_data_found then
dbms_output.put_line('not exists');
end;
(共0页)