我试图将 ref_cursor 分配给 for 循环内的变量,然后在函数结束时返回。如果获得超过 1 个结果,则循环遍历本地游标。
我已经注意到代码中出现错误的位置。我不知道如何创建一个循环,我可以在其中获取循环中当前点的 ref_cursor,将其分配给一个变量,然后将其返回给函数。有人可以帮我弄清楚该怎么做吗?以下是我基于谷歌搜索的阅读逻辑的第 i 次尝试。
错误是“PLS-00382:表达式类型错误”,我知道我显然没有根据这个错误分配正确的变量类型,但下面的错误代码说明了我想要做什么以及我想要做什么需要帮助完成。
FUNCTION GET_PARCEL(p_lat in number, p_long in number) return sys_refcursor
IS
v_distance number(10) := 100000000;
v_shortest_dist number(10) := v_distance;
v_centroid SDO_GEOMETRY;
v_rc_ref_cursor sys_refcursor;
v_ref_geom SDO_GEOMETRY := mdsys.SDO_GEOMETRY(2001, 8311, NULL, SDO_ELEM_INFO_ARRAY(1, 1, 1), SDO_ORDINATE_ARRAY(120.3214, -10.7088));
cursor query_cursor is select * from PARCEL_TABLE where code = 20134;
BEGIN
for query_row in query_cursor loop
v_centroid := SDO_GEOM.SDO_CENTROID(query_row.geometry, 0.05);
IF (v_centroid is not null) then
v_distance := SDO_GEOM.SDO_DISTANCE(v_centroid, v_ref_geom, 0.05);
IF v_distance < v_shortest_dist THEN
v_shortest_dist := v_distance;
v_rc_ref_cursor := query_row; -- Error on this line
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('Centroid is not initialised for some reason.');
END IF;
end loop;
return v_rc_ref_cursor;
END;