繁体   English   中英

将oracle迁移到mysql

[英]Migrate oracle to mysql

我正在尝试将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/zh-CN/pattern-matching.html

source_string REGEXP pattern

作为研究人员,您可以在MYSQL中使用INSTR,例如:

Set @col  = "sample";
select INSTR(@col,"le")

您可以引用此INSTR()

通过删除空格来获取长度:

select LENGTH((replace(@col," ","")))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM