Oracle function error: ORA-00932: inconsistent datatypes: expected CHAR got MDSYS.SDO.GEOMETRY

Oracle function error: ORA-00932: inconsistent datatypes: expected CHAR got MDSYS.SDO.GEOMETRY

我正在尝试创建一个要从 web 地图调用的函数(在数据库级别)。该功能是使当用户点击一个点时关联的区域(多边形)也是selected/highlighted。点和区域通过名为 code 的列中的值在属性级别相关联(知道。不是空间)。

我创建了以下代码,但它 returns 出现错误:

ORA-00932: inconsistent datatypes: expected CHAR MDSYS.SDO_GEOMETRY (?)

代码:

create or replace function region_select 
  ( 
      p_geom in sdo_geometry   
  )  

RETURN SDO_GEOMETRY
DETERMINISTIC

IS 
  v_pointId number;
  v_code number;
  geom_out sdo_geometry;

BEGIN

select point_id into v_pointId from points where geom = p_geom;
select code into v_code from points where point_id = v_pointId;


    if (v_pointId is not null)
    then
    select geom into geom_out from regions where code  = v_code;
    RETURN geom_out;
    end if;

-- error handling
exception
when others then
    raise_application_error(-20001,'An error was encountered - '|| 
sqlcode ||' -error- '|| sqlerrm);
    rollback;
end;

首先,where geom = p_geom 表明空间选择 使用(不是针对 REGIONS,而是针对 POINTS)——并且您不能使用 [= 检查几何相等性10=]。您应该使用 select point_id into v_pointId from points t where SDO_EQUALS(t.geom,p_geom) = 'TRUE' - 这假定存在 POINTS.geom 的空间索引。如果你没有空间索引并且 table POINTS 真的很小,你可以使用 where sdo_geom.relate(t.geom,'determine',p_geom)='EQUAL' - 但它会很慢......

其次,我同意@Alex Poole 的观点,这种错误处理不仅毫无意义,而且有害。按照它的编写方式,你会得到错误(无论如何你都会得到错误)但你会失去例如哪里 发生了这个错误。你应该首先摆脱它,运行 代码,看看你是否能得到更好的错误描述(CHAR MDSYS.SDO_GEOMETRY?什么 "CHAR"?在哪一行?)。如果您得到的结果没有任何效果,我们随时为您提供帮助...

顺便说一句,我不确定这个函数是否确实是确定性的——你必须确保它是确定性的(为什么要这样声明它?这里的目标是什么?)。最后,最好将几何变量声明为“MDSYS.SDO_GEOMETRY”,而不仅仅是 "SDO_GEOMETRY" - 旧错误可能会回来咬你......

HTH,如果您还需要什么,请告诉我。