plsql变量对象名已存在怎么办?
SQL code
declare
i number(4);
v_sql varchar2(512);
begin
select count(*) into i from user_all_tables where table_name = 'Grid_Boundary_point';
if i > 0 then
execute immediate 'drop table Grid_Boundary_point';
commit;
end if;
v_sql := 'create table Grid_Boundary_point(a number)';
execute immediate v_sql;
end;
这行 execute immediate v_sql; 报错name is already used by an existing object
这是怎么回事?怎么解决?
------解决方案--------------------当表对象存在时,对表进行删除操作时,语句改为如下:
if i>0 then
execute immediate 'drop table Grid_Boundary_point cascade constraints';
end if;
------解决方案--------------------if i > 0 then 改为if i >= 0 then
------解决方案--------------------where table_name = 'Grid_Boundary_point';这后面的表名要大写才行,不然查不到数据。
------解决方案--------------------select count(*) into i from user_all_tables where table_name = 'Grid_Boundary_point';
楼上改 Grid_Boundary_point 全为大写应该就可以了
如果还不行,将user_all_tables 改为all_tables一定就可以了