SqlPlus有时会出现非预期的折行,比如这样:
SQL> select id,level,lpad(' ',(level-1)*3)||name as name 2 from emp3 3 start with mngid is NULL 4 connect by mngid=prior id; ID LEVEL ---------- ---------- NAME -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 1 Andy 2 2 Bill 4 3 Douglas ID LEVEL ---------- ---------- NAME -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5 3 Edin 3 2 Cindy 6 3 Felix ID LEVEL ---------- ---------- NAME --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
简直不能忍,好在有 “column name format a40”命令的帮忙。
这一句的意思是指定name列的宽度是40个字符。
再弄就好了。
SQL> column name format a40; SQL> select id,level,lpad(' ',(level-1)*3)||name as name 2 from emp3 3 start with mngid is NULL 4 connect by mngid=prior id; ID LEVEL NAME ---------- ---------- ---------------------------------------- 1 1 Andy 2 2 Bill 4 3 Douglas 5 3 Edin 3 2 Cindy 6 3 Felix 8 4 Hitler 10 5 Jeep 9 4 Idiot 11 5 King 12 6 Linconn ID LEVEL NAME ---------- ---------- ---------------------------------------- 7 3 Green 已选择12行。
当然,除了 ”column 列名 format a宽度“ 命令,SqlPlus还提供了如”set linesize 宽度“之类的命令,大家可以试试效果。
参考资料:
https://blog.51cto.com/meiling/1775065
END