数据从mysql迁移至oracle时知识点记录(一)

最近在做数据的迁移,再将数据从mysql迁移至oracle时,部分sql语句进行了修改,在此对部分知识点进行记录:

参考资料:https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_substring-index

1、【mysql】find_in_set:

  语法:find_in_set(str,strList)  -----> Return the index position of the first argument within the second argument  

  功能:在字符串列表strList中查找字符串str,并返回str所在的索引位置。str要查找的字符串,strList以“,”分割的字符串。

  定义:

    1、Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings.

      如果字符串str在由N个字符串组成的字符串列表strlist内,则返回1到N范围内的值。

    2、A string list is a string composed of substrings separated by , characters.

      字符串列表是由字符串分隔的子字符串组成的字符串。

    3、If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit arithmetic.

         如果第一个参数是常量字符串,第二个参数是SET类型的列,则FIND_IN_SET()函数被优化以使用位运算 

    4、Returns 0 if str is not in strlist or if strlist is the empty string.

      如果字符串str不在字符串列表strlist内或者字符串列表strlist是空字符串,则返回0。

    5、Returns NULL if either argument is NULL.

      如果任意参数为null,则返回null。

    6、This function does not work properly if the first argument contains a comma (,) character.

      如果第一个参数包含了逗号(,)字符,则此函数无法正常工作。

  实际应用:

    某表中某字段值由两部分以“|”连接组成,如:A|B,A表示某C类型的编号,B表示某D类型的编号。

    在查询时,按C类型编号和D类型编号作为两种条件进行查询:

    在mysql中使用find_in_str(?,REPLACE('A|B','|',','))可实现查询,而在oracle中该函数没有,那我们可以换种方式:

    用oracle中的 REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)函数 获取所需的部分 与条件值进行比对进行查询:

      如上述应用中可用 REGEXP_SUBSTR('A', '[^|]+', 1, 1) =? 作为C类型编号查询条件, REGEXP_SUBSTR('B', '[^|]+', 1, 2) =?作为D类型编号查询条件。

2、【mysql】substring_index (暂记录其中一种,其他后续补充)

  语法:substring_index(str,delim,count)  ------>Return a substring from a string before the specified number of occurrences of the delimiter

  功能:在指定的分隔符出现之前从字符串返回一个子字符串。str被截取的字符串,delim分隔符,count分隔符出现的次数。

  定义: 

    1、Returns the substring from string str before count occurrences of the delimiter delim. 

      在分隔符出现之前返回字符串str中的子字符串。

    2、If count is positive, everything to the left of the final delimiter (counting from the left) is returned.

      如果count为正数,则返回最终分隔符左侧的所有内容(从左侧计数)。即,从左边开始计数,获取第count个分隔符左侧的内容。

    3、If count is negative, everything to the right of the final delimiter (counting from the right) is returned.

      如果count为负数,则返回最终分隔符右侧的所有内容(从右侧计数)。即,从右边开始计数,获取第count个分隔符右侧的内容 。

    4、SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

     SUBSTRING_INDEX()在搜索delim时执行区分大小写匹配。

  实际应用:

     某表中某字段值由两部分以“|”连接组成,如:A|B,A表示某C类型的编号,B表示某D类型的编号。

     在查询时,查询出C类型编号和D类型编号并进行展示:

     在mysql中,我们可以使用substring_index(str,delim,count)函数来实现该需求,而在oracle中,我们依然可以通过REGEXP_SUBSTR(String, pattern, position, occurrence, modifier) 来实现该需求

3.【mysql】UUID:

  在实际应用当中,有时我们会用到UUID()函数来实现唯一值。

  在mysql中我们可以使用:select replace(uuid(),'-','') as uuid; 来获取唯一值,而在oracle中,我们得使用:select lower(sys_guid()) as uuid  from dual;来获取

  

上一篇:k8s滚动更新(六)--技术流ken


下一篇:oracle 数据库——知识点总结(加示例)