我正在运行以下查询:
SDO_GEOMETRY
其中SDO_UTIL.TO_WKBGEOMETRY
是GEOMETRY
类型。问题是,当我运行此查询时,我收到以下错误,我认为在数据库中错误指定的ORA-29532: Java call terminated by uncaught Java exception: java.lang.RuntimeException: oracle.spatial.util.GeometryExceptionWithContext: For GTYPE_MULTICURVE, interpretation should be 1 or 2
记录上使用{{1}}时会发生此错误。
{{1}}
我想编写一个查询,该查询仅跳过导致引发此错误的记录(即返回一个表,该表具有GEOM_TABLE中的所有行,除了那些引发错误的行)。我是PL / SQL的新手,曾经尝试过一些涉及循环和异常的查询,但是我无法使它们正常工作。
答案 0 :(得分:1)
您应该能够将正在调用的功能包装在另一个捕获并吞并错误的函数中。像这样:
from ingredients import Ingredient
from inventory import Inventory
def main():
f = open('food_inv_new.txt')
lines = f.readlines()
items = {}
for line in lines:
line = line.strip('\n')
line = line.strip('\t')
item = Ingredient(title=line[0])
items[item] = line[1]
inventory = Inventory(items)
inventory.print_inventory()
if __name__ == "__main__":
main()
''' from Inventory class '''
def print_inventory(self):
for item in self.items:
print item, "-", self.items[item]
''' from Ingredient class '''
def __init__(self, title, description=''):
self.title = title
self.description = description
def __str__(self):
return self.title
''' In the .txt file: title is the first field(name of Item)
description is the number of inventory
'''
然后使用子查询过滤出错误并避免两次调用该函数:
CREATE FUNCTION to_wkbgeometry_silent (geometry IN SDO_GEOMETRY)
RETURN BLOB IS
BEGIN
RETURN SDO_UTIL.to_wkbgeometry (geometry);
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END to_wkbgeometry_silent;
(尽管,显然,最好是捕获并忽略要忽略的特定错误,而不是所有错误。)
答案 1 :(得分:0)
我不知道如何跳过错误,但是您可以使用CASE
来避免错误:
SELECT CASE GEOMETRY WHEN 1 THEN 1 WHEN 2 THEN 2 ELSE NULL END
FROM (SELECT 1 AS GEOMETRY FROM DUAL -- Fake Table
UNION ALL
SELECT 2 AS GEOMETRY FROM DUAL
UNION ALL
SELECT 3 AS GEOMETRY FROM DUAL);
在您的实例中:
SELECT
CASE GEOMETRY WHEN 1 THEN SDO_UTIL.TO_WKBGEOMETRY(GEOMETRY) WHEN 2 THEN SDO_UTIL.TO_WKBGEOMETRY(GEOMETRY) ELSE NULL END,
S_ROUTE,
BLOCK_ID
FROM GEOM_TABLE;