Formatting output of queries in SQLPlus

北城余情 提交于 2019-11-29 10:42:43

Okay, start with this in SQL Plus:

SET LINESIZE 20000 TRIM ON TRIMSPOOL ON
SPOOL output.txt

-- run your queries here

SPOOL OFF
EXIT

Also, René Nyffenegger has a whole section dedicated to Beautifying SQL*Plus Output and additional resources on SQL*Plus.

The biggest culprits for messy sql output are long character columns, i.e. varchar2(360). sqlplus allocates exactly that much space for the output, even though you may only be using 20 at most. You can change this by using the column directive. Assume that employees table has an address column with 360 characters:

column address format A20
select address from employees;--sqlplus will allocate only 20 characters for the address width

Given that I work with a database with lots of (unnecessarily) long character columns this works perfectly for me.

Your result is in a complete mess because of two things:
You are using a shell
You screen is small thus output lines are wrapped.

What to do?
Since it is oracle, forget about ubuntu/windows. Download Oracle SQL Developer or Aqua data studio.
They are easy to use, readable output format, and savable sql scripts. It will save you time reading/analyzing query outputs.

gpoo

The answer from Benoit is what you are looking for. To install SQLPlus in Ubuntu, just download the compressed files from Oracle (otn) and follow the instructions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!