Oracle is a commonly used enterprise-level database, which is often used in enterprises to store data. After storing data in Oracle database, we sometimes need to export some of that data to other formats, such as CSV files, Excel files, or other database systems. At this point, Oracle provides some easy-to-use tools to export data. This article introduces methods for exporting Oracle data.
SQL Developer is a free Oracle database client tool. In addition to executing SQL queries, it can also easily export data to other format files, including CSV, Excel, JSON, etc. The following takes exporting a CSV file as an example to introduce how to use SQL Developer to export data.
First, open the SQL Developer tool and connect to the Oracle database where the data needs to be exported. Find the table in the left panel, right-click the table you want to export, and select the "Export" menu.
Next, set the export parameters:
After the setting is completed, click the "Next" button. On the second page, select the columns of the table to be exported. You can select all columns or custom columns. After the settings are completed, click the "Next" button. On the last page, you can check the export settings. After confirming that they are correct, click the "Export" button to start exporting data.
Data Pump is a tool for Oracle database that can be used to export and import data. Data Pump can export data to folders, pipes, or between databases. It can also export an entire database instance or specified database objects. The following takes exporting the entire table as an example to introduce how to use Data Pump to export data.
First, run the following command in the SQLPlus interface to enter Data Pump mode:
$ expdp username/password directory=’导出目录’ dumpfile=’导出文件.dmp’ tables=’要导出的表格’
Among them, username/password is the username and password to log in to the Oracle database, directory is the export directory, and dumpfile is the exported File name, tables is the name of the table to be exported.
After the settings are completed, press the "Enter" key to start exporting data. After completion, the exported data files can be found in the specified export directory.
SQLPlus is another form of Oracle Database client tool that can be used to perform SQL queries and export data. SQLPlus can save query results as text files and direct output to external files. The following is how to use SQL*Plus to export data:
The first step is to enter the SQLPlus tool. Enter the following command in the console to enter SQLPlus interactive mode:
$ sqlplus username/password
where username/password is the username and password to log in to the Oracle database.
The second step is to enter the following command to set the output file format:
$ set col separator ‘,’ $ set pagesize 0 $ set trimspool on $ set linesize 1000 $ spool ‘导出文件名.csv’
Among them, set col separator specifies the column separator of the output file; set pagesize sets the page size; set trimspool on sets the removal Spaces in the output; set linesize sets the maximum length of output lines; spool sets the name of the output file.
The third step is to execute the SQL query in SQL*Plus and select the data to be output. For example, to select all data in the table, enter the following command and press the "Enter" key:
$ select * from ‘表格名’;
The fourth step is to turn off the output to file function of SQLPlus and exit SQLPlus. Enter the following command to close the output file and exit SQL*Plus:
$ spool off $ exit
After completion, the exported file can be found in the specified output directory.
To summarize, the above three methods can effectively export data in Oracle database to other format files. No matter which method you choose, you need to understand the table structure and data volume so you can choose the best method to export the data based on your specific needs.
The above is the detailed content of How to export data in oracle. For more information, please follow other related articles on the PHP Chinese website!