我正在尝试从PostgreSQL编写一个可在Oracle中运行的转换。
我的问题是我正在努力寻找一个替代Postgres @>
(包含)运算符的Oracle SQL语句。
Postgres中的查询如下所示:
CASE
WHEN descriptivegroup @> '{Building}' AND descriptiveterm IS NULL THEN 'Building Fill'
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm = '{"Multi Surface"}' THEN 'Multi Surface Fill'
等,这意味着'Building'或'General Surface'(在上面的示例中)应该包含在名为descriptivegroup的数组中。
我一直在浏览Stackoverflow和其他网站,我认为我在Oracle中为@>
找到的最接近的等价物是“成员”,如下例所示:
How to check if an array contains a particular string?
然而,我正在努力研究如何将这样的陈述写入CASE>什么类型的声明,所以我会非常感激地从这个社区获得任何帮助或建议!
非常感谢。
PS正如所承诺的,这是Postgres查询的截断版本。这不是一切,因为它太大了:
CREATE TABLE osmm.topo_area_style AS SELECT
a.*,
CASE
WHEN descriptivegroup @> '{Building}' AND descriptiveterm IS NULL THEN 'Building
Fill'
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm = '{"Multi
Surface"}' THEN 'Multi Surface Fill'
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm IS NULL AND make
= 'Natural' THEN 'Natural Fill'
WHEN descriptivegroup @> '{"Road Or Track"}' AND descriptiveterm IS NULL AND make =
'Manmade' THEN 'Road Or Track Fill'
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm IS NULL AND make
= 'Manmade' OR make = 'Unknown' THEN 'Manmade Fill'
WHEN descriptivegroup @> '{Roadside}' AND make = 'Natural' THEN 'Roadside Natural
Fill'
ELSE 'Unclassified'
END AS style_description,
CASE
WHEN descriptivegroup @> '{Building}' AND descriptiveterm IS NULL THEN 1
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm = '{"Multi
Surface"}' THEN 2
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm IS NULL AND make
= 'Natural' THEN 3
WHEN descriptivegroup @> '{"Road Or Track"}' AND descriptiveterm IS NULL AND make =
'Manmade' THEN 4
WHEN descriptivegroup @> '{"General Surface"}' AND descriptiveterm IS NULL AND make
= 'Manmade' OR make = 'Unknown' THEN 5
WHEN descriptivegroup @> '{Roadside}' AND make = 'Natural' THEN 6
WHEN descriptivegroup @> '{Roadside}' AND make = 'Manmade' OR descriptivegroup @>
'{Roadside}' AND make = 'Unknown' THEN 7
ELSE 99
END AS style_code
FROM osmm.topographicarea as a;
我无法访问此SQL编写的表,但是您可以看到正在创建的表是现有表的直接副本,但是此代码添加了另外2列,然后从描述性组中填充descriptiveterm。