Getting error: "Missing keyword" when using case in where clause
Getting error: "Missing keyword" when using case in where clause
SELECT *
FROM corp_action_restriction car1
LEFT OUTER JOIN investment_account inv
ON CASE
WHEN REGEXP_LIKE(REGEXP_SUBSTR(car1.restriction_value,
'[^|]+',
1,
1),
'^[[:digit:]]*$') THEN
TO_NUMBER(REGEXP_SUBSTR(car1.restriction_value, '[^|]+', 1, 1)) =
inv.investment_account_id
ELSE
car1.restriction_value = TO_CHAR(inv.investment_account_id)
END
我遇到了缺少关键字的错误。
谁能告诉我这个查询有什么问题?
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 4 Column: 61
那就是
SELECT *
FROM CORP_ACTION_RESTRICTION CAR1
LEFT OUTER JOIN INVESTMENT_ACCOUNT INV
ON INV.INVESTMENT_ACCOUNT_ID =
CASE
WHEN REGEXP_LIKE (REGEXP_SUBSTR (CAR1.RESTRICTION_VALUE,
'[^|]+',
1,
1),
'^[[:digit:]]*$')
THEN
TO_NUMBER (REGEXP_SUBSTR (CAR1.RESTRICTION_VALUE,
'[^|]+',
1,
1))
ELSE
CAR1.RESTRICTION_VALUE
END;
换句话说,将 inv.investment_account_id
放入 ON
子句中,然后将其(使用 =
)与 case 表达式的结果进行比较。
因为return_expr
或else_expr
不能是布尔表达式类型。
而且REGEXP_SUBSTR()
的第三个和第四个参数(1
&1
)是多余的。
确实不需要CASE..WHEN
表达式,如果数据库版本是12cR2+
,那么考虑使用
SELECT *
FROM corp_action_restriction car1
LEFT JOIN investment_account inv
ON TO_NUMBER(
REGEXP_SUBSTR(
car1.restriction_value,
'[^|]+'
)
DEFAULT NULL ON CONVERSION ERROR
) = inv.investment_account_id
这样就不会因为转换而报错
SELECT *
FROM corp_action_restriction car1
LEFT OUTER JOIN investment_account inv
ON CASE
WHEN REGEXP_LIKE(REGEXP_SUBSTR(car1.restriction_value,
'[^|]+',
1,
1),
'^[[:digit:]]*$') THEN
TO_NUMBER(REGEXP_SUBSTR(car1.restriction_value, '[^|]+', 1, 1)) =
inv.investment_account_id
ELSE
car1.restriction_value = TO_CHAR(inv.investment_account_id)
END
我遇到了缺少关键字的错误。
谁能告诉我这个查询有什么问题?
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Error at Line: 4 Column: 61
那就是
SELECT *
FROM CORP_ACTION_RESTRICTION CAR1
LEFT OUTER JOIN INVESTMENT_ACCOUNT INV
ON INV.INVESTMENT_ACCOUNT_ID =
CASE
WHEN REGEXP_LIKE (REGEXP_SUBSTR (CAR1.RESTRICTION_VALUE,
'[^|]+',
1,
1),
'^[[:digit:]]*$')
THEN
TO_NUMBER (REGEXP_SUBSTR (CAR1.RESTRICTION_VALUE,
'[^|]+',
1,
1))
ELSE
CAR1.RESTRICTION_VALUE
END;
换句话说,将 inv.investment_account_id
放入 ON
子句中,然后将其(使用 =
)与 case 表达式的结果进行比较。
因为return_expr
或else_expr
不能是布尔表达式类型。
而且REGEXP_SUBSTR()
的第三个和第四个参数(1
&1
)是多余的。
确实不需要CASE..WHEN
表达式,如果数据库版本是12cR2+
,那么考虑使用
SELECT *
FROM corp_action_restriction car1
LEFT JOIN investment_account inv
ON TO_NUMBER(
REGEXP_SUBSTR(
car1.restriction_value,
'[^|]+'
)
DEFAULT NULL ON CONVERSION ERROR
) = inv.investment_account_id
这样就不会因为转换而报错