SQLFormat - CSV, JSON, XML - Format output of SQL in SQLDeveloper

A lot of time we want results of our SQL statements in CSV, JSON, XML formats or wish to generate insert statement for our data. For these requirements, we can use SET SQLFormat in our favorite database tools - SQL Developer and SQLcl.

Oracle has provided a lot of SQLFormat options, the most commonly used are -

SET SQLFORMAT CSV
SET SQLFORMAT CSV

SET SQLFORMAT JSON

SET SQLFORMAT INSERT
SQL Developer also provides us option to directly put the SQLFORMAT in the comment in SQL itself as

Apart from these wonderful SQLFORMAT, we can use XML, HTML and LOADER with SQLDeveloper and SQLcl. There are others too but are not commonly used, and if you want to learn, explore the Oracle Documentation.

Related Posts:
- Oracle SQL Developer - Autotrace - Insufficient Privileges
- SQL Loader Express Mode - Loading data in Oracle database can't be more easy
- JSON in Oracle Database with Examples
- Top 18 features of Oracle 18c
- Oracle 12c Partitioning New Features - Top 10

6 comments:

  1. Hello Nimish,

    Is there any way to change the position of the column , for E.g:-

    TableA
    --
    Name
    Tel
    Email
    Address
    I want to add a new column (mobile) in between Tel & Email:

    TableA
    --
    Name
    Tel
    Mobile
    Email
    Address

    ReplyDelete
  2. Hi Nimish,
    I am using Oracle 12.1.0.1 and when I am trying to execute the “SET SQL FORMATCSV” it is throwing an error i.e “SP2-0158: unknown SET option "SQL" , Please share your comments.

    ReplyDelete
    Replies
    1. instead of "SET SQL FORMATCSV", run "SET SQLFORMAT CSV". Note this, it works only in SQLDeveloper. not in SQLPLUS. Also, run your select query using F5 (and not F9).

      Delete
  3. Even I am receiving the error when i use set sqlformat csv

    ReplyDelete