简体   繁体   中英

SDO_GEOMETRY not accepting variables

I'm trying to display the distance between to locations, however, when using l_lng and l_lat variables that are processed from a postcode a user enters, I'm getting the following error - ORA-13032: Invalid NULL SDO_GEOMETRY object

It's not a problem with the UPDATE as when I input latitude and longitude values, the distance is calculated. Also, when displaying the latitude and longitude values held in the l_lng and l_lat variables, they are also correct.

DECLARE

  l_lat VARCHAR2(100);
  l_lng VARCHAR2(100);
  l_postcode VARCHAR2(8) := :P2_POSTCODE;

BEGIN

    brian.GEOCODE_GM_XML (:P2_POSTCODE, l_lat, l_lng);

    UPDATE RESTAURANTS 
    SET DISTANCE =     (SELECT SDO_GEOM.SDO_DISTANCE(
                            restaurants.location, 
                            SDO_GEOMETRY(2001, 4326, SDO_POINT_TYPE(l_lng, l_lat, null), null, null), 
                            0.005, 'unit=mile') distance
                       FROM restaurants WHERE restaurants.restaurant_id = 36);
    htp.p(l_lat);
    htp.p(l_lng);

END;

Is there any mistake I'm making?

  • Change variable declarations for l_lat and l_lng from varchar2 to number .
  • I presume the restaurants.distance column is of type number .
  • Verify that the geometries have valid fields. To specify a NULL geometry, specify the whole SDO_GEOMETRY as NULL instead of setting each field to NULL . It seems you may have some values are NULL at the same time for both l_lat and l_lng of SDO_POINT_TYPE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM