暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

华为openGauss 二进制字符串函数和操作符

华为高斯 2020-06-01
1406

字符串操作符

SQL定义了一些字符串函数,在这些函数里使用关键字而不是逗号来分隔参数。

  • octet_length(string)

    描述:二进制字符串中的字节数。

    返回值类型:int

    示例:

    ``` postgres=# SELECT octet_length(E'jo\000se'::bytea) AS RESULT; result


      5
    

    (1 row) ```

  • overlay(string placing string from int [for int])

    描述:替换子串。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT overlay(E'Th\000omas'::bytea placing E'\002\003'::bytea from 2 for 3) AS RESULT; result


    \x5402036d6173 (1 row) ```

  • position(substring in string)

    描述:特定子字符串的位置。

    返回值类型:int

    示例:

    ``` postgres=# SELECT position(E'\000om'::bytea in E'Th\000omas'::bytea) AS RESULT; result


      3
    

    (1 row) ```

  • substring(string [from int] [for int])

    描述:截取子串。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT substring(E'Th\000omas'::bytea from 2 for 3) AS RESULT; result


    \x68006f (1 row) ```

  • trim([both] bytes from string)

    描述:从string的开头和结尾删除只包含bytes中字节的最长字符串。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT trim(E'\000'::bytea from E'\000Tom\000'::bytea) AS RESULT; result


    \x546f6d (1 row) ```

二进制字符串函数

openGauss也提供了函数调用所使用的常用语法。

  • btrim(string bytea,bytes bytea)

    描述:从string的开头和结尾删除只包含bytes中字节的最长的字符串。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT btrim(E'\000trim\000'::bytea, E'\000'::bytea) AS RESULT; result


    \x7472696d (1 row) ```

  • get_bit(string, offset)

    描述:从字符串中抽取位。

    返回值类型:int

    示例:

    ``` postgres=# SELECT get_bit(E'Th\000omas'::bytea, 45) AS RESULT; result


      1
    

    (1 row) ```

  • get_byte(string, offset)

    描述:从字符串中抽取字节。

    返回值类型:int

    示例:

    ``` postgres=# SELECT get_byte(E'Th\000omas'::bytea, 4) AS RESULT; result


    109
    

    (1 row) ```

  • set_bit(string,offset, newvalue)

    描述:设置字符串中的位。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT set_bit(E'Th\000omas'::bytea, 45, 0) AS RESULT; result


    \x5468006f6d4173 (1 row) ```

  • set_byte(string,offset, newvalue)

    描述:设置字符串中的字节。

    返回值类型:bytea

    示例:

    ``` postgres=# SELECT set_byte(E'Th\000omas'::bytea, 4, 64) AS RESULT; result


    \x5468006f406173 (1 row) ```

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据