[CP][BUGFIX] fix lrpad mysql pad len zero

This commit is contained in:
obdev
2024-02-09 07:07:47 +00:00
committed by ob-robot
parent 68638d77f1
commit b75fc423ec
3 changed files with 58 additions and 4 deletions

View File

@ -6124,7 +6124,7 @@ select lpad('a', 5, '');
+------------------+
| lpad('a', 5, '') |
+------------------+
| |
| NULL |
+------------------+
select lpad(NULL, 5, 'a');
+--------------------+
@ -6283,3 +6283,44 @@ select rpad('a', 8, '阿斯'), length(rpad('a', 8, '阿斯')) from dual;
| a阿斯阿斯阿斯阿 | 22 |
+------------------------+--------------------------------+
drop table if exists t1;
create table t1(c1 int);
insert into t1 values(18);
select lpad("", cast(c1 as decimal), "") from t1;
+-----------------------------------+
| lpad("", cast(c1 as decimal), "") |
+-----------------------------------+
| NULL |
+-----------------------------------+
select lpad("123", cast(c1 as decimal), "") from t1;
+--------------------------------------+
| lpad("123", cast(c1 as decimal), "") |
+--------------------------------------+
| NULL |
+--------------------------------------+
select lpad("", cast(c1 as decimal), "123") from t1;
+--------------------------------------+
| lpad("", cast(c1 as decimal), "123") |
+--------------------------------------+
| 123123123123123123 |
+--------------------------------------+
select rpad("", cast(c1 as decimal), "") from t1;
+-----------------------------------+
| rpad("", cast(c1 as decimal), "") |
+-----------------------------------+
| NULL |
+-----------------------------------+
select rpad("123", cast(c1 as decimal), "") from t1;
+--------------------------------------+
| rpad("123", cast(c1 as decimal), "") |
+--------------------------------------+
| NULL |
+--------------------------------------+
select rpad("", cast(c1 as decimal), "123") from t1;
+--------------------------------------+
| rpad("", cast(c1 as decimal), "123") |
+--------------------------------------+
| 123123123123123123 |
+--------------------------------------+
drop table t1;

View File

@ -116,4 +116,17 @@ select rpad('a', 6, '阿斯'), length(rpad('a', 6, '阿斯')) from dual;
select rpad('a', 7, '阿斯'), length(rpad('a', 7, '阿斯')) from dual;
select rpad('a', 8, '阿斯'), length(rpad('a', 8, '阿斯')) from dual;
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(c1 int);
insert into t1 values(18);
select lpad("", cast(c1 as decimal), "") from t1;
select lpad("123", cast(c1 as decimal), "") from t1;
select lpad("", cast(c1 as decimal), "123") from t1;
select rpad("", cast(c1 as decimal), "") from t1;
select rpad("123", cast(c1 as decimal), "") from t1;
select rpad("", cast(c1 as decimal), "123") from t1;
drop table t1;
--sleep 2