create table force_powers (
id integer generated by default as identity not null primary key,
structure varchar2(50) not null,
name varchar2(100) not null
)
Table created.
insert into force_powers (structure, name) values ( '1', 'Universal' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '1.1', 'Telekinesis' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '1.1.1', 'Force Push' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '1.1.2', 'Force Pull' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '1.1.3', 'Force Jump' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '2', 'Light' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '2.1', 'Mind Trick' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '2.1.1', 'Force Persuation' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '3', 'Dark' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '3.1', 'Force wound' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '3.1.1', 'Force grip' )
1 row(s) inserted.
insert into force_powers (structure, name) values ( '3.1.2', 'Force choke' )
1 row(s) inserted.
select * from force_powers
ID | STRUCTURE | NAME | 1 | 1 | Universal | 2 | 1.1 | Telekinesis | 3 | 1.1.1 | Force Push | 4 | 1.1.2 | Force Pull | 5 | 1.1.3 | Force Jump | 6 | 2 | Light | 7 | 2.1 | Mind Trick | 8 | 2.1.1 | Force Persuation | 9 | 3 | Dark | 10 | 3.1 | Force wound | 11 | 3.1.1 | Force grip | 12 | 3.1.2 | Force choke |
---|
create or replace type t_numeric_structure force as object
(
c_level1 number(3,0),
c_level2 number(3,0),
c_level3 number(3,0),
constructor function t_numeric_structure(
i_struct varchar2 )
return self as result,
member function p$_position_for_level(
i_string varchar2,
i_level positiven ) return pls_integer,
member function structure return varchar2 deterministic
);
Type created.
create or replace type body t_numeric_structure as
constructor function t_numeric_structure(
i_struct varchar2 )
return self as result
as
begin
self.c_level1 := p$_position_for_level(i_struct, 1);
self.c_level2 := p$_position_for_level(i_struct, 2);
self.c_level3 := p$_position_for_level(i_struct, 3);
return;
end;
member function p$_position_for_level(
i_string in varchar2,
i_level in positiven ) return pls_integer
as
begin
return
nvl(to_number(
regexp_substr(i_string, '[0-9]+', 1, i_level)
),0);
end;
member function structure return varchar2 deterministic
as
l_result varchar2(50);
begin
if ( c_level1 > 0 ) then
l_result := to_char(c_level1);
end if;
if ( c_level2 > 0 ) then
l_result := l_result || '.' || to_char(c_level2);
end if;
if ( c_level3 > 0 ) then
l_result := l_result || '.' || to_char(c_level3);
end if;
return l_result;
end;
end;
Type created.
alter table force_powers
add struct t_numeric_structure
Table altered.
update force_powers
set struct = t_numeric_structure(structure)
12 row(s) updated.
alter table force_powers
drop column structure
Table altered.
create unique index idx_force_powers_uq_struct on
force_powers ( substr(struct.structure(),1,12) )
Index created.
insert into force_powers ( name, struct )
select 'some name', t_numeric_structure('4.0.0')
from dual connect by level <= 10
ORA-00001: unique constraint (SQL_OXGDMIHOAEBNXMRIZQZKIEVQW.IDX_FORCE_POWERS_UQ_STRUCT) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
update force_powers p
set struct = t_numeric_structure('4.0.0')
where p.struct.structure() like '3%'
ORA-00001: unique constraint (SQL_OXGDMIHOAEBNXMRIZQZKIEVQW.IDX_FORCE_POWERS_UQ_STRUCT) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
update force_powers p
set p.struct.c_level1 = 1
where p.struct.c_level1 = 2
ORA-00001: unique constraint (SQL_OXGDMIHOAEBNXMRIZQZKIEVQW.IDX_FORCE_POWERS_UQ_STRUCT) violated ORA-06512: at "SYS.DBMS_SQL", line 1721More Details: https://docs.oracle.com/error-help/db/ora-00001
select
p.id,
p.name,
p.struct.structure() structure
from force_powers p
where p.struct.structure() = '1.1.1'
ID | NAME | STRUCTURE | 3 | Force Push | 1.1.1 |
---|