如何理解lpad和rpad函数

发布时间:2021-11-12 15:45:39 作者:柒染
来源:亿速云 阅读:176

这篇文章将为大家详细讲解有关如何理解lpad和rpad函数,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

一、Lpad函数

lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad(string,n,[pad_string])

string:字符或者参数

n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;

pad_string:可选参数,这个字符串是要粘贴到string的左边,若这个参数未写,lpad函数将会在string的左边粘贴空格。

select lpad('tech', 7) from dual; 将返回' tech'
select lpad('tech', 2) from dual; 将返回'te'
select lpad('tech', 8, '0') from dual; 将返回'0000tech'
select lpad('tech on the net', 15, 'z') from dual; 将返回'tech on the net'
select lpad('tech on the net', 16, 'z') from dual; 将返回'ztech on the net'

SQL> select lpad('tech', 7) from dual;

LPAD('T
-------
   tech

SQL> select lpad('tech', 2) from dual;

LP
--
te

SQL> select lpad('tech', 8, '0') from dual;

LPAD('TE
--------
0000tech

SQL> select lpad('tech on the net', 15, 'z') from dual;

LPAD('TECHONTHE
---------------
tech on the net

SQL> select lpad('tech on the net', 16, 'z') from dual;

LPAD('TECHONTHEN
----------------
ztech on the net

SQL>


二、Rpad函数

rpad函数将右边的字符串填充一些特定的字符其语法格式如下:rpad(string,n,[pad_string])

string:字符或者参数

n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;

pad_string:可选参数,这个字符串是要粘贴到string的右边,如果这个参数未写,lpad函数将会在string的右边粘贴空格。

select rpad('tech', 7) from dual; 将返回' tech'
select rpad('tech', 2) from dual; 将返回'te'
select rpad('tech', 8, '0') from dual; 将返回'tech0000'
select rpad('tech on the net', 15, 'z') from dual; 将返回'tech on the net'
select rpad('tech on the net', 16, 'z') from dual; 将返回'tech on the netz'

SQL> select rpad('tech', 7) from dual;

RPAD('T
-------
tech

SQL> select rpad('tech', 2) from dual;

RP
--
te

SQL> select rpad('tech', 8, '0') from dual;

RPAD('TE
--------
tech0000

SQL> select rpad('tech on the net', 15, 'z') from dual;

RPAD('TECHONTHE
---------------
tech on the net

SQL> select rpad('tech on the net', 16, 'z') from dual;

RPAD('TECHONTHEN
----------------
tech on the netz

关于如何理解lpad和rpad函数就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. oracle lpad 的用法
  2. oracle LPAD和RPAD函数简介

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

lpad rpad

上一篇:web前端开发的重要性是什么

下一篇:Django中的unittest应用是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》