SELECT *
FROM table_name
WHERE (x,y) IN ((-1,-2), (1,1))
或者,如果要将arg作为字符串传递,则使用LIKE:
SELECT *
FROM table_name
WHERE TRANSLATE('[(-1;-2),(1;1)]', '[]', ',,') LIKE '%,(' || x || ';' || y || '),%'
或者,如果圆括号可以用作术语分隔符,则可以更简单:
SELECT *
FROM table_name
WHERE '[(-1;-2),(1;1)]' LIKE '%(' || x || ';' || y || ')%'
其中,对于示例数据:
CREATE TABLE table_name (PositionId, X, Y) AS
SELECT 1, -1, -2 FROM DUAL UNION ALL
SELECT 2, -1, -1 FROM DUAL UNION ALL
SELECT 3, 1, 2 FROM DUAL UNION ALL
SELECT 4, 1, 1 FROM DUAL;
WITH data(positionid, x, y) AS (
SELECT 1, -1, -2 FROM DUAL UNION ALL
SELECT 2, -1, -1 FROM DUAL UNION ALL
SELECT 3, 1, 2 FROM DUAL UNION ALL
SELECT 4, 1, 1 FROM DUAL -- UNION ALL
),
expr(s) AS (
SELECT regexp_replace( '[(-1;-2), (1;1)]', '\[(.*)\]', '\1') FROM DUAL
),
pairs(n, s) AS (
SELECT LEVEL, TRIM(regexp_replace( TRIM(regexp_substr(s,'[^,]+',1,LEVEL)) , '\((.*)\)', '\1')) as s
FROM expr
CONNECT BY regexp_substr(s,'[^,]+',1,LEVEL) IS NOT NULL
)
, lopairs(x,y) AS (
SELECT x, y FROM (
SELECT n, LEVEL AS c, TO_NUMBER(regexp_substr(s,'[^;]+',1,LEVEL)) AS v
FROM pairs
CONNECT BY regexp_substr(s,'[^;]+',1,LEVEL) IS NOT NULL AND PRIOR n = n AND PRIOR SYS_GUID() IS NOT NULL
)
PIVOT (
MAX(v) FOR c IN (1 AS x, 2 AS y)
)
)
SELECT positionid, x, y FROM data
WHERE (x,y) IN (
SELECT x,y FROM lopairs
)
;
2条答案
按热度按时间j8yoct9x1#
使用多维
IN
:或者,如果要将
arg
作为字符串传递,则使用LIKE
:或者,如果圆括号可以用作术语分隔符,则可以更简单:
其中,对于示例数据:
全部输出:
| 职位ID| X轴|Y型|
| - -|- -|- -|
| 一个|-1个|-2个|
| 四个|一个|一个|
fiddle
djmepvbi2#
如果arg是一个字符串,你可以将它转换成一个数字列表(x,y):