4

I have a table like this:

CREATE TABLE spatial_data (
  id NUMBER PRIMARY KEY,
  geometry SDO_GEOMETRY);

SDO_GEOMETRY has a field sdo_ordinates with the following type:

TYPE SDO_ORDINATE_ARRAY AS VARRAY(1048576) OF NUMBER

I can get the number of points for specified object:

select count(*)
from table(
    select s.geometry.sdo_ordinates
    from spatial_data s
    where s.id = 12345
);

How can I get count for several objects? It's not possible to use

where s.id in (1, 2, 3, 4, 5)

And I really care about performance. Maybe PL/SQL would be the right choice?

Dmitry D
  • 760
  • 12
  • 24

1 Answers1

6

I think that you can do it with one query:

select s.id, count(*)
  from spatial_data s, table(s.geometry.sdo_ordinates)
 group by s.id

or you can write a plsql simple function that returns the count attribute of the SDO_ORDINATE_ARRAY VARRAY:

create or replace function get_count(ar in SDO_ORDINATE_ARRAY) return number is
begin
   return ar.count;
end get_count;

or even nicer add a member function to SDO_GEOMETRY TYPE which return the count attribute

A.B.Cade
  • 16,735
  • 1
  • 37
  • 53
  • Thank you for your answer! I've compared these two queries and the second approach with pl/sql function works much faster. – Dmitry D Jan 25 '12 at 13:51