Batch Data Import in Oracle using Excel

Source: Internet
Author: User

This article from: http://www.cnblogs.com/heyanzheng/articles/1573636.html

 

 

Enter all the doctor information of several hospitals in Excel and import it to Oracle. Of course, Oracle cannot directly read the Excel content, but we can turn to achieve it.

You can simply think that the content in an Excel table corresponds to the fields in a table in the database one by one. You can simply insert them one by one. In practice, it may not be so simple, but the principle is the same. If there is an associated table, you need to insert the generated field ID, then set it to the primary key,
You can use the index to obtain the current value to continue the operation. The principle is the same.
If your team also works collaboratively, the format in Excel is as follows:

Each row contains information about a doctor. If your team also has a division of labor and collaboration, send the format to the corresponding personnel so that they can enter the data. We started to consider how to import them into the table.
An Imported table is nothing more than a series of insert statements. The data in each statement is the data in each row in Excel. Therefore, we need to export the data in Excel to a file. Each doctor's data row is separated by a token,
You can easily obtain the values of each doctor and corresponding item.
Excel comes with many export methods. Data in XML format can be read everywhere. If you have a dedicated tool to read or write a program to read the XML format, you can also. Note that, after being converted to XML format, for example, "Doctor's fax"
If there is no value, the file in the TXT format can also be exported without this parameter in the xmlnode tree. However, after export, the original format is retained. With tabs, we cannot easily obtain each item of data. It is best to specify the interval between each item during export.
Identifier. So we thought of access.
There is no problem with importing and exporting Microsoft products. Import Excel Data to access ("open" in access), which is opened in the form of an external chain table. In this case, data cannot be modified in access, but can only be modified in Excel of the corresponding link,
After modification, the data in access will also change accordingly. Check that there is no problem with the data in access, and you are ready to export the data from access.
Right-click the external chain table, select export, select the keep directory, select text file, and next;
Select the export format. To facilitate reading values, select "with separator" and next;
Select a separator. If the data to be imported contains a small amount of data and is not complex, you can select a semicolon or comma. However, the data to be imported contains text and may contain commas, so I select "Others" and select an uncommon one, such as "#". The text identifier can be removed.
You can manually add batch SQL statements. Next step;
OK.
The exported data is as follows:

At this time, it is not difficult to read data. Locate the. txt file and use the file stream to read one row. After reading the file, it is separated by "#" And corresponds to each field in the insert statement. Batch import is complete.
One of the most important problems is that, if the Java Io stream is used to directly read from the file, all Chinese characters are garbled. We need to convert the file encoding format. Convert to GBK format using newstr = new string (oldstr. getbytes ("ISO-8859-1"), "GBK ");
You can use it normally.
Of course, this is perfect. Some items in the middle may be empty. If you want to add a judgment item, read the image and record the position. In Excel, there is a place where the numbers are stored. After being exported from access, every one changes to x.00.
If the field is of the number (n) type, an error occurs during data import. So this also needs to be processed. And so on. These are all simple tasks. With this idea, everything else is simple.

Enter all the doctor information of several hospitals in Excel and import it to Oracle. Of course, Oracle cannot directly read the Excel content, but we can turn to achieve it.

You can simply think that the content in an Excel table corresponds to the fields in a table in the database one by one. You can simply insert them one by one. In practice, it may not be so simple, but the principle is the same. If there is an associated table, you need to insert the generated field ID, then set it to the primary key,
You can use the index to obtain the current value to continue the operation. The principle is the same.
If your team also works collaboratively, the format in Excel is as follows:

Each row contains information about a doctor. If your team also has a division of labor and collaboration, send the format to the corresponding personnel so that they can enter the data. We started to consider how to import them into the table.
An Imported table is nothing more than a series of insert statements. The data in each statement is the data in each row in Excel. Therefore, we need to export the data in Excel to a file. Each doctor's data row is separated by a token,
You can easily obtain the values of each doctor and corresponding item.
Excel comes with many export methods. Data in XML format can be read everywhere. If you have a dedicated tool to read or write a program to read the XML format, you can also. Note that, after being converted to XML format, for example, "Doctor's fax"
If there is no value, the file in the TXT format can also be exported without this parameter in the xmlnode tree. However, after export, the original format is retained. With tabs, we cannot easily obtain each item of data. It is best to specify the interval between each item during export.
Identifier. So we thought of access.
There is no problem with importing and exporting Microsoft products. Import Excel Data to access ("open" in access), which is opened in the form of an external chain table. In this case, data cannot be modified in access, but can only be modified in Excel of the corresponding link,
After modification, the data in access will also change accordingly. Check that there is no problem with the data in access, and you are ready to export the data from access.
Right-click the external chain table, select export, select the keep directory, select text file, and next;
Select the export format. To facilitate reading values, select "with separator" and next;
Select a separator. If the data to be imported contains a small amount of data and is not complex, you can select a semicolon or comma. However, the data to be imported contains text and may contain commas, so I select "Others" and select an uncommon one, such as "#". The text identifier can be removed.
You can manually add batch SQL statements. Next step;
OK.
The exported data is as follows:

At this time, it is not difficult to read data. Locate the. txt file and use the file stream to read one row. After reading the file, it is separated by "#" And corresponds to each field in the insert statement. Batch import is complete.
One of the most important problems is that, if the Java Io stream is used to directly read from the file, all Chinese characters are garbled. We need to convert the file encoding format. Convert to GBK format using newstr = new string (oldstr. getbytes ("ISO-8859-1"), "GBK ");
You can use it normally.
Of course, this is perfect. Some items in the middle may be empty. If you want to add a judgment item, read the image and record the position. In Excel, there is a place where the numbers are stored. After being exported from access, every one changes to x.00.
If the field is of the number (n) type, an error occurs during data import. So this also needs to be processed. And so on. These are all simple tasks. With this idea, everything else is simple.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.