如何理解lpad和rpad函数

网友投稿 80 2023-12-28

如何理解lpad和rpad函数

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

一、Lpad函数lpad函数将左边的字符串填充一些特定的字符其语法格式如下:lpad(string,n,[pad_string])string:字符或者参数n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;pad_string:可选参数,这个字符串是要粘贴到string的左边,若这个参数未写,lpad函数将会在string的左边粘贴空格。select lpad(tech, 7) from dual; 将返回 techselect lpad(tech, 2) from dual; 将返回teselect lpad(tech, 8, 0) from dual; 将返回0000techselect lpad(tech on the net, 15, z) from dual; 将返回tech on the netselect lpad(tech on the net, 16, z) from dual; 将返回ztech on the netSQL> select lpad(tech, 7) from dual; LPAD(T-------   techSQL> select lpad(tech, 2) from dual;LP--teSQL> select lpad(tech, 8, 0) from dual;LPAD(TE--------0000techSQL> select lpad(tech on the net, 15, z) from dual;LPAD(TECHONTHE---------------tech on the netSQL> select lpad(tech on the net, 16, z) from dual;LPAD(TECHONTHEN----------------ztech on the netSQL> 二、Rpad函数rpad函数将右边的字符串填充一些特定的字符其语法格式如下:rpad(string,n,[pad_string])string:字符或者参数n:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;pad_string:可选参数,这个字符串是要粘贴到string的右边,如果这个参数未写,lpad函数将会在string的右边粘贴空格。select rpad(tech, 7) from dual; 将返回 techselect rpad(tech, 2) from dual; 将返回teselect rpad(tech, 8, 0) from dual; 将返回tech0000select rpad(tech on the net, 15, z) from dual; 将返回tech on the netselect rpad(tech on the net, 16, z) from dual; 将返回tech on the netzSQL> select rpad(tech, 7) from dual;RPAD(T-------techSQL> select rpad(tech, 2) from dual; RP--teSQL> select rpad(tech, 8, 0) from dual;RPAD(TE--------tech0000SQL> select rpad(tech on the net, 15, z) from dual;RPAD(TECHONTHE---------------tech on the netSQL> select rpad(tech on the net, 16, z) from dual; RPAD(TECHONTHEN----------------tech on the netz

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Oracle DBMS_SCHEDULER调用操作系统脚本怎么编写
下一篇:如何解决在做vue和oracle账号关联时容易出现的错误:third invalid attempt
相关文章

 发表评论

暂时没有评论,来抢沙发吧~