Oracle兼容-函数-INSTRB()函数
1. 语法
INSTRB( string, sub_string [, start_position [, nth_appearance ] ] )
2. 定义和用法
参数:
string
,指定需要在其中搜索子字符串的字符串。sub_string
,指定需要搜索的子字符串。start_position
,可选参数,指定字符串从字节搜索开始的位置。默认值为1。INSTRB()
函数从字符串末尾算起start_position
的字节数,如果指定的值为负数,则向字符串开头进行搜索。nth_appearance
,可选参数,指定子字符串的第n个匹配。预设值为1。
3. Oracle兼容说明
函数 INSTRB()
的作用是按字节在 string
字符串中查找 sub_string
字符串。
注意: 当参数 string
和 sub_string
的类型不一致时,在GreatSQL和Oracle中的类型转换处理方式可能存在不同,Oracle有些会进行特殊转换处理(如参数sub_string为小数类型,在转换为字符类型时,当整数部分为0时,会舍弃整数部分)。例如:
-- 在GreatSQL中得到1
greatsql> SELECT INSTRB('0.3333', 0.3) FROM DUAL;
+-----------------------+
| INSTRB('0.3333', 0.3) |
+-----------------------+
| 1 |
+-----------------------+
-- 在Oracle中得到2
SQL> SELECT INSTRB('0.3333', 0.3) FROM DUAL;
INSTRB('0.3333',0.3)
--------------------
2
-- 在Oracle中,小数位和字符串表示方式分别如下
SQL> SELECT 0.3, '0.3' FROM DUAL;
0.3 '0.
---------- ---
.3 0.3
4. 示例
greatsql> SELECT INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高');
+---------------------------------------------------------------------------------------------------+
| INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高') |
+---------------------------------------------------------------------------------------------------+
| 15 |
+---------------------------------------------------------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高', 1, 1);
+---------------------------------------------------------------------------------------------------------+
| INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高', 1, 1) |
+---------------------------------------------------------------------------------------------------------+
| 15 |
+---------------------------------------------------------------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高', 1, 2);
+---------------------------------------------------------------------------------------------------------+
| INSTRB('GreatSQL具备高可用、高性能、高兼容、高安全等多个核心特性', '高', 1, 2) |
+---------------------------------------------------------------------------------------------------------+
| 27 |
+---------------------------------------------------------------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S');
+----------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S') |
+----------------------------------------------+
| 6 |
+----------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S', 1, 2);
+----------------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S', 1, 2) |
+----------------------------------------------------+
| 27 |
+----------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S', -1);
+--------------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S', -1) |
+--------------------------------------------------+
| 27 |
+--------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S', -1, 2);
+-----------------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S', -1, 2) |
+-----------------------------------------------------+
| 6 |
+-----------------------------------------------------+
-- 参数中的小数转整数
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S', 1, 1.6);
+------------------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S', 1, 1.6) |
+------------------------------------------------------+
| 6 |
+------------------------------------------------------+
greatsql> SELECT INSTRB('GreatSQL is a branch of MySQL', 'S', 0.6, 1);
+------------------------------------------------------+
| INSTRB('GreatSQL is a branch of MySQL', 'S', 0.6, 1) |
+------------------------------------------------------+
| 0 |
+------------------------------------------------------+
问题反馈
联系我们
扫码关注微信公众号