我正在尝试将oracle迁移到mysql。
问题 1。
Instr('aa bb cc', ' ', -1,1)
我改了
CHAR_LENGTH('aa bb cc') - LOCATE(' ', REVERSE('aa bb cc'))+1
两者都返回
6
但我不知道如何进行查询
Instr('aa bb cc', ' ', -1, 2)
问题 2。
这是 Oracle 查询。
CASE WHEN Regexp_like(
REPLACE(SUBSTR(TRIM(col), INSTR(TRIM(col), ' ', -1,1),
(LENGTH(TRIM(col)) - INSTR(TRIM(col), ' ',-1, 1))
+ 1), ' ',
''),
'[0-9|0-9\-]') THEN
REPLACE(SUBSTR(TRIM(col), INSTR(TRIM(col), ' ', -1, 2),
(INSTR(TRIM(col), ' ', -1, 1) - INSTR(TRIM(col), ' ', -1, 2)
) +
1), ' ', '') END
如何将查询改为mysql查询?
最佳答案
MySQL也有instr()函数,但功能比Oracle少
ora :: Instr('aa bb cc', ' ', -1, 1) ==
my :: length('aa bb cc') - length(substring_index('aa bb cc', ' ', -1))
ora :: Instr('aa bb cc', ' ', -1, 2) ==
my :: length('aa bb cc') - length(substring_index('aa bb cc', ' ', -2))
MySQL也使用(因此无需更改):
CASE WHEN value THEN do-something END
MySQL 替换:
REPLACE(str, from, to)
https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace
其他问题应该都是一样的。
类似正则表达式
https://docs.oracle.com/cd/B12037_01/server.101/b10759/conditions018.htm
regexp(source_string, pattern, match_parameter)
https://dev.mysql.com/doc/refman/5.7/en/pattern-matching.html
source_string REGEXP pattern
关于mysql - 迁移oracle到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41842378/