Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: oracle的substrb(str2||str1,1+lengthb(str1),6)如何在tidb中实现
To improve efficiency, please provide the following information. A clear problem description can help resolve the issue faster:
[Overview] Scenario + Problem overview function modification
[Application Framework and Development Adaptation Business Logic]
[Background] Operations performed
[Phenomenon] Business and database phenomena
[Problem] Current issue encountered
[Business Impact]
[TiDB Version]
[Attachments] Relevant logs and monitoring
It should be the same, right? Are you specifically referring to the difference between substrb and substr?
SELECT SUBSTRING(CONCAT(str2, str1), LENGTH(str1) + 1, 6) FROM your_table;
TiDB is compatible with MySQL, so you can rewrite it using MySQL functions.
Isn’t this just converting Oracle to MySQL?
From the function name, it should be distinguished by the number of bytes and the number of characters.
It seems that no one is paying attention to the difference between substrb
and substr
!
substr(cast(concat(str2, str1) as binary), 1 + length(cast(str1 as binary)), 6)
What is this recording, can you write SQL like this 
I only found out after searching on Baidu~ 
These basic functions are generally available in every database, and it’s very simple to look up and modify them according to your own needs. Some time ago, I worked with a DBA from Tencent to convert Oracle functions to TDSQL. We broke them down into a bunch of small stored procedures and made the changes.
For single-byte encodings like English, substr and substrb are the same. However, when used with multi-byte characters like Chinese, substrb may result in garbled text. Since you are migrating from Oracle to TiDB, you might as well change it conveniently without insisting on it.
Literally, it’s the difference between string and string byte?
The difference is between bytes and characters. I specifically looked it up on Baidu to find out~ I hadn’t paid attention to it before.
Writing it this way has no performance to speak of, unless your result set is very small.