我有organization
表,其结构如下:
create table organization (
id number(10) not null,
parent_id number(10),
title varchar2(255 char),
hierarchy_code varchar2(255 char)
);
alter table organization
add constraint fk_parent_id foreign key (parent_id)
references organization (id);
具有名为hierarchy_code
的列,其中包含每个组织的层次结构代码,例如,如果我们具有以下组织:
department A
|
|__ office 1
| |
| |__ room A
| | |__ room A1
| | |__ room A2
| |
| |__ room B
此表的记录如下:
________________________________________________
| id | parent_id | title | hierarchy_code |
|-------------------------------------------------
| 1 | null | department A | 1 |
|-------------------------------------------------
| 2 | 1 | office 1 | 1001 |
|-------------------------------------------------
| 3 | 2 | room A | 1001001 |
|-------------------------------------------------
| 3 | 3 | room A1 | 1001001001 |
|-------------------------------------------------
| 4 | 3 | room A2 | 1001001002 |
|-------------------------------------------------
| 5 | 2 | room B | 1001002 |
------------------------------------------------
我通过以下过程生成hierarchy_code
的值:
create or replace procedure after_save_organization(id_var number, old_parentid number, new_parentid number) is
old_hierarchy_code varchar2(255 char);
new_hierarchy_code varchar2(255 char);
parent_new_hierarchy_code varchar2(255 char);
sub_str1 varchar2(255 char);
str1 varchar2(255 char);
number_ number(10);
begin
select p.hierarchy_code
into old_hierarchy_code
from organization p
where p.id = id_var;
select hierarchy_code
into parent_new_hierarchy_code
from organization
where id = new_parentid;
select max(p.hierarchy_code)
into str1
from organization p
where p.parentid = new_parentid
and p.hierarchy_code != old_hierarchy_code;
if str1 is not null then
sub_str1 := substr(str1, 0, length(str1) - 3);
number_ := to_number(substr(str1,
length(str1) - 2,
length(str1)));
number_ := number_ + 1;
new_hierarchy_code := sub_str1 || case
when length(number_) = 1 then
'00'
when length(number_) = 2 then
'0'
end || number_;
else
new_hierarchy_code := parent_new_hierarchy_code || '001';
end if;
update organization po
set po.hierarchy_code = new_hierarchy_code ||
substr(po.hierarchy_code,
length(old_hierarchy_code) + 1,
length(po.hierarchy_code))
where exists (select pp.id
from organization pp
where po.id = pp.id
connect by prior pp.id = pp.parentid
start with pp.id = id_var);
end;
一切正常,但是对于自定义组织,更改parent_id
后,调用过程以重新生成层次结构代码时,过程完全执行,但是当要提交更改时,出现此错误:
ORA-00604: error occurred at recursive SQL level 1
ORA-20000: Oracle Text error:
DRG-50610: internal error: drexdsync
DRG-50857: oracle error in drekrtd (reselect rowid row locator)
ORA-00942: table or view does not exist
ORA-06512: at "CTXSYS.SYNCRN", line 1
ORA-06512: at line 1