0

我正在编写一个 APEX 应用程序,它利用空间通过 Googlemaps API 进行邻近搜索,我已经构建了该函数并且它编译得很好,但是每当我尝试在 SQLDeveloper 中运行它时,我都会收到错误消息not enough arguments

我创建的用于设置新纬度/经度点的函数从我的stores表中输入一个邮政编码,然后它使用 Google 地图 API 返回该邮政编码的长纬度坐标,返回时构建一个SDO_GEOMETRY对象,该对象被返回并设置在表格的一location列中stores

功能代码:

CREATE OR REPLACE FUNCTION set_spatial_point
( 
    -- Only accept postcodes from the store table
    p_postcode stores.postcode%TYPE
)
    RETURN MDSYS.SDO_GEOMETRY
IS
    -- Build local variables
    l_lng      VARCHAR2(100);
    l_lat      VARCHAR2(100);
    n_spatial_object MDSYS.SDO_GEOMETRY;
BEGIN
    -- Populate long and lat parameters
    POSTCODE_TO_LAT_LNG_GM_API(p_postcode, l_lat, l_lng);

    -- Populate the new spatial object
    n_spatial_object := MDSYS.SDO_GEOMETRY
    (
        -- use 01 as we wish to add the point to the map
        2001, 
        -- SRID for WGS84 longitutde/latitude format
        8307,
         -- Set the information of the point ( we don't need a Z co-ord )
        SDO_POINT_TYPE
        (
            l_lng,
            l_lat,
            null
         ),
        null,   -- We have no SDO_ELEM_INFO_ARRAY
        null    -- We have no SDO_ORDINATE_ARRAY
    );

    -- Return the new spatial object
    dbms_output.put_line('sdo_gtype='||n_spatial_object.sdo_gtype);
    dbms_output.put_line('first element from sdo_ordinates='||n_spatial_object.sdo_ordinates(1));
    RETURN n_spatial_object;
END set_spatial_point;

为什么我得到参数不足错误,即使我用有效的调用它stores.postcode%TYPE,(我已经尝试更改为,VARCHAR2但这没有任何区别。)

编辑:创建函数后,我调用该方法:

DECLARE
   my_object    MDSYS.SDO_GEOMETRY;  
BEGIN
  my_object := set_spatial_value('MK80PB');
END;

我现在收到以下错误:

Error starting at line : 1 in command -
DECLARE
  my_object    MDSYS.SDO_GEOMETRY;  
BEGIN
my_object := set_spatial_value('MK80PB');
END;
Error report -
ORA-06550: line 4, column 14:
PLS-00201: identifier 'SET_SPATIAL_VALUE' must be declared
ORA-06550: line 4, column 1:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
4

1 回答 1

1

您得到的错误很明显:您将函数创建为 SET_SPATIAL_POINT() 但您调用了 SET_SPATIAL_VALUE() 并且显然失败,因为它不存在。

现在,让我们试试这个。由于我没有您对 STORES 表或 Google 调用的声明,因此我不得不替换您的一些代码,因此我对该调用的结果进行了硬编码:

CREATE OR REPLACE FUNCTION set_spatial_point
( 
    -- Only accept postcodes from the store table
    p_postcode varchar2
)
    RETURN SDO_GEOMETRY
IS
    -- Build local variables
    l_lng      VARCHAR2(100);
    l_lat      VARCHAR2(100);
    n_spatial_object SDO_GEOMETRY;
BEGIN
    -- Populate long and lat parameters
    -- POSTCODE_TO_LAT_LNG_GM_API(p_postcode, l_lat, l_lng);
    l_lat:=45.3;
    l_lng:= 3.7;

    -- Populate the new spatial object
    n_spatial_object := SDO_GEOMETRY
    (
        -- use 01 as we wish to add the point to the map
        2001, 
        -- SRID for WGS84 longitutde/latitude format
        8307,
         -- Set the information of the point ( we don't need a Z co-ord )
        SDO_POINT_TYPE
        (
            l_lng,
            l_lat,
            null
         ),
        null,   -- We have no SDO_ELEM_INFO_ARRAY
        null    -- We have no SDO_ORDINATE_ARRAY
    );

    -- Return the new spatial object
    dbms_output.put_line('sdo_gtype='||n_spatial_object.sdo_gtype);
    dbms_output.put_line('first element from sdo_ordinates='||n_spatial_object.sdo_ordinates(1));
    RETURN n_spatial_object;
END set_spatial_point;
/
show errors

这很好用。

让我们试一试:

SQL> select set_spatial_point('XXXX') from dual;
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at "SCOTT.SET_SPATIAL_POINT", line 38

同样,这很明显。错误在第 38 行:

        dbms_output.put_line('first element from sdo_ordinates='||n_spatial_object.sdo_ordinates(1));

这失败了(显然又一次),因为 n_spatial_object.sdo_ordinates() 是空的(就像你在第 32 行写的那样。

让我们删除那些调试行并重新定义函数。那我们试试看。它现在按预期工作:

SQL> select set_spatial_point('XXXX') from dual;

SET_SPATIAL_POINT('XXXX')(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INF
-------------------------------------------------------------------------------
SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(3.7, 45.3, NULL), NULL, NULL)

1 row selected.
于 2014-11-13T19:51:52.037 回答