Site icon Database Tutorials

How To Export Tables to csv in Oracle

 

It is possible to export the data in tables in the database in csv format depending on a specific condition. We can use the UTL_FILE package for this operation.

With the following procedure, we can create a csv format file in a directory on the server that we specify with the virtual directory, with or without specifying the data in a table.

In the procedure, the “|” sign is used to separate column names. The “;” sign is used to separate the data. You can use any separator with the l_separator variable.

Procedure Usage:

First, the virtual directory must be created as follows.

For example, a virtual directory named CSV_DUMP_DIR is created that represents the /tmp directory.

The user who will execute the procedure must be authorized to read and write in the virtual directory created.

We can execute the procedure as follows. When specifying a condition, you must use double quotes, as in the following example. If we do not specify a condition, the parameter p_condition can be sent empty. The user who will run the procedure must be able to query the table he is trying to export.

Example with Condition:

Example without Condition:

Exit mobile version