我有一个 Oracle 18c PL/SQL 函数,可以使用它来查找名为 SDE.ST_GEOMETRY 的用户定义空间类型中的问题值。
查找具有问题形状的行(SDE.ST_GEOMETRY 空间类型)
with function check_shape(anno_shape sde.st_geometry, boundary_shape sde.st_geometry) return varchar2
is
v_test_result varchar2(10); --<--look here
begin
select
sde.st_intersects (boundary_shape, anno_shape)
into --<--look here
v_test_result --<--look here
from
dual;
return 'no error';
exception
when others then
return 'error';
end;
select
anno.objectid,
anno.shape as anno_shape,
check_shape(anno.shape, boundary.shape) as check_shape
from
city.boundary boundary
cross join
infrastr.gcsm_hc_anno anno
where
check_shape(anno.shape, boundary.shape) = 'error'
我从在线示例脚本中拼凑了该函数,它按预期工作。话虽如此,我想确保代码尽可能简单和正确。
在我未经训练的眼睛看来,
into
和v_test_result
似乎没有必要;他们似乎什么也没做。该函数选择一个值到变量中,但该变量似乎没有被 return
使用。
我的直觉是删除这些行:
v_test_result varchar2(10);
...
into
v_test_result
但是当我删除这些行时,我收到错误:
with function check_shape(anno_shape sde.st_geometry, boundary_shape sde.st_geometry) return varchar2
is
-- v_test_result varchar2(10); --<--look here
begin
select
sde.st_intersects (boundary_shape, anno_shape)
-- into --<--look here
-- v_test_result --<--look here
from
dual;
return 'no error';
exception
when others then
return 'error';
end;
select
anno.objectid,
anno.shape as anno_shape,
check_shape(anno.shape, boundary.shape) as check_shape
from
city.boundary boundary
cross join
infrastr.gcsm_hc_anno anno
where
check_shape(anno.shape, boundary.shape) = 'error'
ORA-06553: PLS-428: an INTO clause is expected in this SELECT statement
06553. 00000 - "PLS-%s: %s"
为什么这个函数需要
into
?有没有办法通过删除它来简化功能?
SELECT
语句的语法为:
select_into_statement ::=
从中您可以看到
INTO
或 BULK COLLECT INTO
子句是强制性的。
如果您没有这些子句中的任何一个,那么您的代码在语法上无效并且将引发异常。