最明显的解释是你试图用一个字符串做数学......
尝试将字符串转换为数字失败,因为字符串不是有效的数字文字。在算术函数或表达式中只能使用数字字段或包含数字数据的字符字段。只有数字字段可以添加到日期或从日期中减去。
http://ora-01722.ora-code.com/
更新#1:
你的描述让我担心:
我正在尝试使用在 IN 子句中返回逗号分隔字符串的子查询。
您的子查询不应返回逗号分隔的字符串(除非g.group_id
是字符串并且需要逗号分隔的字符串)。您必须根据需要检索尽可能多的行中的单个项目(无论如何少于 1,000)。
更新#2:
只是为了说清楚:
SELECT *
FROM (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL
) FOO;
FOO_ID
----------------------
1
2
3
你可以这样做:
SELECT *
FROM (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL
) FOO
WHERE FOO_ID IN (1, 2);
FOO_ID
----------------------
1
2
但不是这个:
SELECT *
FROM (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL
) FOO
WHERE FOO_ID IN ('1,2');
SQL Error: ORA-01722: invalid number
因为您无法将 number1
与 string进行比较'1,2'
。子查询遵循类似的规则:
SELECT *
FROM (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL
) FOO
WHERE FOO_ID IN (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL
);
FOO_ID
----------------------
1
2
SELECT *
FROM (
SELECT 1 AS FOO_ID FROM DUAL UNION SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL
) FOO
WHERE FOO_ID IN (
SELECT '1,2' AS FOO_ID FROM DUAL
);
SQL Error: ORA-01722: invalid number