我正在编写一个APEX应用程序,它通过Googlemaps API利用空间进行邻近搜索,我已经构建了该函数并且编译得很好,但每当我尝试在SQLDeveloper中运行它时,我都会收到错误not enough arguments
。
我创建的用于设置新纬度/长点的函数从我的stores
表中获取一个邮政编码输入,然后使用Google地图API返回该邮政编码的长整数,其中return构建一个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:
答案 0 :(得分: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()为null(就像你在第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.