Saturday , April 20 2024

How To Export Data From SQL Plus to CSV

With Oracle 12.2.0.1, SQL * Plus is capable of displaying the result of a query as CSV.

Its use is as follows.

Options

DELIMI[TER] : The character used to separate column values. Only single characters are allowed. The default value is “,” (comma).

QUOTE : If this is ON, the column values that are text are shown in “” (double quotation marks). It can take ON or OFF values. The default value is OFF.

Generate CSV output in double quotes

Generate CSV output without double quotes

Generate CSV output using “| (pipe)” as delimiter

By using the -M parameter from the command line as follows, the output can be created in csv format by running the script.
With the command “sed ‘/^$/d'”, we ensure that the space that appears at the beginning and end of the output is not displayed. Otherwise, it will be displayed with spaces as follows.

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories