Data export in Oracle (2)

Export the data in the Oracle database to other systems for use

How to achieve the above requirements?

Here I use the spool script method to export data, among which the data in Oracle is exported (1) http://t.csdn.cn/k5AOZ

The use of the spool command has been described. In this article, I will use the spool command script to export data. The following are the specific steps for using the spool command script:

1. For the convenience of management, first create a folder for storing data. I created it on the D drive , and the folder name is [ SQL ]. Start Explorer, select Disk→File→New→Folder, and name it. As shown below:

 2. Open Notepad on the computer desktop, and write the following command in the text:

set line 120
set pagesize 10000
set heading off
spool D:\SQL\data.txt    
select deptno||','||dname||','||loc from dept;
spool off
  • If we export a lot of data rows, we can set the pagesize larger;
  • In the SQL query, I use the connector "||" to separate the output fields with commas, and store the output data results in the data.txt text file in the SQL folder under the D drive;
  • The set heading off command is a command of SQL*Plus in the Oracle database, which is used to control the format of the output result. The specific function is to close the column headers (headings) in the query results , and only keep the data rows , so as to facilitate data processing and export operations. After using the set heading off command, the query results will not display the column names . This helps to reduce the amount of output, making it more efficient when processing large amounts of data, saving time and space resources. For example, when using the SPOOL command to store query results to a file, it is often necessary to turn off the column headers and only save the actual data rows.

Notice:

Turning off column headers may make query results difficult to understand or to distinguish the meaning of each column of data, so in some scenarios it is still necessary to turn on column headers. In practical applications, you can reasonably choose whether to enable or disable column headers according to specific situations.

 3. Select the file → save command, or directly [ ctrl+s ] shortcut command to save the text document. Still this text, then select File→Save As, select the SQL folder of the D drive , then enter data.sql in the drop-down box corresponding to [File Name] , and finally click the Save button, as shown in the following figure:

4. Start the DOS interface (win+r, enter cmd to enter the small black room), enter the d: command to switch to the D drive, enter cd sql to switch to the D:\SQL directory, and then enter the sqlplus scott/tiger command to enter SQL*PLUS and Log in to the Oracle database as user Scott, as shown in the following figure:

 5. Enter @data and click the enter key to run the SQL script file data.sql I just created, as shown in the figure below:

The four pieces of data shown below are the results of the data I want to query.

6. At this time, I went to open the D:\SQL directory and found that there was a text data.txt file under this folder. This file is the data file defined in the data.sql script file, as shown in the figure:

7. Double-click to open the data.txt file , and you can see that all the exported data are the same as those output by the DOS interface, as shown in the figure:

all right! The above steps are to simply use the spool command script file to export data. If you want to export database data in the future, you don’t need to enter commands one by one in the DOS interface. We can actually directly change the SQL query statement in the script file, and then in the DOS interface. Just switch the path and call it directly. Did you find it a lot more convenient! I will summarize a more convenient data export method in Data Export in Oracle (3). Stay tuned!

Guess you like

Origin blog.csdn.net/m0_71406734/article/details/131018029