–创建该存储,创建完成之后进行存储测试
右键该存储,Test测试
输入参数 owner 用户 tableName 需要重置的表名 然后运行。就会重新排列该表的id值。
以下是存储内容:
create or replace procedure P_ResetObjectID(owner in NVARCHAR2, tablename in NVARCHAR2)
is
reg_id pls_integer;
owner_l VARCHAR2(64);
table_l VARCHAR2(64);
pipe_name VARCHAR2(30);
max_id NUMBER;
stmt varchar2(512);
sequence_name VARCHAR2(64);
begin
owner_l := UPPER(owner);
table_l := UPPER(tablename);
stmt := 'SELECT registration_id FROM SDE.table_registry '||
'WHERE owner ='''|| owner_l ||''' AND table_name = '''|| table_l ||'''';
EXECUTE IMMEDIATE stmt INTO reg_id;
if reg_id is null then return;
end if;
pipe_name := 'ArcSDE_IdPipe' || TO_CHAR (reg_id);
--清除arcgis缓存管道
stmt := 'select sys.dbms_pipe.remove_pipe('''||pipe_name||''') from dual ';
EXECUTE IMMEDIATE stmt;
--更新oid
stmt := 'update '||table_l||' set objectid=rownum ';
EXECUTE IMMEDIATE stmt;
--获取最大oid
stmt := 'select max(objectid) from '||table_l;
EXECUTE IMMEDIATE stmt INTO max_id;
if max_id is NULL then return;
end if;
--修改序列的当前值
sequence_name := 'R' || TO_CHAR (reg_id);
stmt := 'drop sequence '||sequence_name||' ';
EXECUTE IMMEDIATE stmt;
stmt := 'create sequence '||sequence_name||' minvalue 1 maxvalue 2147483647 start with '||max_id||' increment by 16 cache 20';
EXECUTE IMMEDIATE stmt;
stmt := 'grant select on '||owner_l||'.'||sequence_name||' to public';
EXECUTE IMMEDIATE stmt;
end P_ResetObjectID;