如何在 MySQL 中设置数字通配符?
尝试创建一个 SQL 脚本,用于在两个不同的数据库中查找代码。设置一个带有数字通配符的参数。
代码通常写成这样,例如 将参数设置为 as 以返回以 ABC 开头的代码的所有可能变体,但这导致输出为空 ABC108ABC109DEF47213ABC[0-9]+
尝试了以下操作,期望输出在两个数据库中制作的最新代码:
SET @investment_code = 'ABC[0-9]+';
SELECT
investment_name,
i.service_client_id,
currency_symbol,
investment_code C_investment_codes
FROM client.investments i
LEFT JOIN client.currencies c
ON i.currency_id = c.id
WHERE i.investment_code COLLATE utf8mb4_unicode_ci LIKE @investment_code
ORDER BY investment_code DESC
LIMIT 1;
SELECT
`key`,
service_client_id,
`value` SD_investment_codes
FROM client_data.standing_data sd
WHERE sd.`value` COLLATE utf8mb4_unicode_ci LIKE @investment_code
ORDER BY `value` DESC
LIMIT 1;
这导致 output 为空。当使用时,得到了结果,但特别想将数字的参数设置为遵循 ABC。这是预期输出:SET @investment_code = 'ABC%';