如何在MySQL中右对齐的列对齐?
您可以LPAD()
从MySQL使用它。让我们首先创建一个表-
mysql> create table DemoTable(
FullName varchar(100)
);
使用插入命令在表中插入记录-
mysql> insert into DemoTable values('John Smith');mysql> insert into DemoTable values('David Miller');
mysql> insert into DemoTable values('Sam Williams');
mysql> insert into DemoTable values('Carol Taylor');
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------------+| FullName |
+--------------+
| John Smith |
| David Miller |
| Sam Williams |
| Carol Taylor |
+--------------+
4 rows in set (0.00 sec)
以下是将列右对齐的查询-
mysql> select lpad(FullName,70,' ') from DemoTable;
这将产生以下输出-
+------------------------------------------------------------------------+| lpad(FullName,70,' ') |
+------------------------------------------------------------------------+
| John Smith |
| David Miller |
| Sam Williams |
| Carol Taylor |
+------------------------------------------------------------------------+
4 rows in set (0.00 sec)
以上是 如何在MySQL中右对齐的列对齐? 的全部内容, 来源链接: utcz.com/z/355625.html