1. 程式人生 > >使用PL/SQLDeveloper把excel資料匯入到資料庫

使用PL/SQLDeveloper把excel資料匯入到資料庫

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

原創作品,出自 “深藍的blog” 部落格,歡迎轉載,轉載時請務必註明以下出處,否則追究版權法律責任。

深藍的blog:http://blog.csdn.net/huangyanlong/article/details/45165707

舉例一個行政區劃的excel資料表,如下:

把檔案儲存成txt文件,如下:

使用PL/SQL Developer將資料匯入到oracle中,在Tools欄找到Text importer選項,如下:

txt檔案路徑新增到工具中,如下:

進行相關設定,如下:

點選Import按鈕完成資料的匯入。

 

勘誤:

日期:201564日星期四

注意在上文中,在新增完txt文件這步以後,需要切換到“Data to Oracle”專案下,進行對應關係設定,參考如下圖說明:

        剛剛發現了這個錯誤,沒來的及再從頭到尾演示一遍了,暫時補充上了這一步說明一下,上圖中只是把思路說明了一下。因為這一步的設定是必須的,否則無法完成欄位的對應,如果不進行“Data to Oracle

”設定。import按鈕會為“灰”,是無法點選的。

 

今天把這部分的官方文件貼下面,可以參考下。

 

PL/SQL Developer官方文件該功能的官方文件說明如下:

21.7 Text Importer

With the text importer you can import ASCII files into the database. Most line oriented formats like

comma and tab separated fields are supported. The importer will try to determine the file format

automatically, so most of the time you don’t need to define anything, just select the file, select a table,

and that’s it.

When you open the text importer and load a text file, you will get something like the following:

The importer loads the first 100 lines from the file. This raw data is shown in the top “File Data”

section. The middle section allows you to configure the file definition. The bottom “Result Preview”

has a grid with the data as it would be imported.

PL/SQL Developer 10.0 User’s Guide 185

The toolbar has buttons to select a text file, or paste text from the clipboard. Files can be of virtually

unlimited size, they are not read entirely into memory. The “New” button will clear everything in the

text importer. The open and save definition buttons allow you to re-use the definition.

If you want to import the text into a new table, press theCreate table button. This will invoke the Table

Definition Editor with a column definition that matches the configuration.

The configuration is auto determined as soon as you load a file, but if this is not correct, you can create

of modify this yourself. Set the Fieldcount to the correct number, and select a field from the field list to

define a field definition. In the file data section, the specified field data is highlighted, allowing you to

check if the field definition is correct. You have the following options to configure the text import

definition:

• General – Fieldcount

The number of fields per record.

• Gereral – End at line end

Indicates that the record data ends at the end of a line.

• General – Name in Header

Indicates if the first record holds the fieldnames.

• General – Skip empty lines

When enabled, empty lines in the text file will be skipped.

• General – Quote Character

Indicates the string delimiter, usually double or single quotes.

• General – Comment line

Here you can select a character or the characters that indicate a comment line in the text file.

• General – Import lines

The first and last lines in the text file that will be imported. If you leave this empty, the entire file

will be imported.

• Field Start – Relative Position

The field starts at a relative position to the end of the previous field. 0 indicates that the field starts

where the previous field ended.

• Field Start – Absolute Position

This indicates that the field starts at a fixed position.

• Field Start – Character

This indicates that the field starts with a specific character. This is relative to the end of the

previous field.

• Field End – Length

Indicates that the field has a fixed length.

• Field End – Character

Indicates that the field end with a specific character.

For standard comma separated files (csv) all fields will have a relative start position of 0, end the field

end character should be a comma. The line end (cr/lf or lf or cr) will also indicate field end, so for the

last field on a line, the end character doesn’t matter.

To filter the file contents you can enter any valid SQL expression in theFilter field. You can refer to a

field value through a bind variable with the field name. For example, to include only employees from

department 10 with a job other than 'CLERK', you can enter the following filter expression:

:deptno = 10 and :job <> 'CLERK'

186 PL/SQL Developer 10.0 User’s Guide

When you have a correct file definition, you need to select an Oracle table and indicate which text fields

should be imported in which Oracle fields. You can do this on the second tab page:

The top section has some general import parameters. The “Fields” section allows you to associate text

file fields and Oracle fields. The bottom section is the result preview for your information.

You can set the following general preferences:

• Owner / Table

The Oracle table (or view) you want to import the data to. After selecting a table, the importer will

try to determine the field and field types automatically. This will only work if the text file has a

header.

• Clear table

When enabled, the all records in the table will be deleted before the import.

• Commit every…

Indicates after how many records you want to do a commit. If you set this to 0, all data will be

committed at the end of the entire import.

• Overwrite Duplicates

A duplicate record will be updated in the database. Duplicates are based on the primary key

value(s) of the table.

• Ignore Duplicates

Duplicate records will be ignored.

• Initializing Script / Finalizing Script

These scripts will be executed before / after importing the text file. You can use any SQL

command or PL/SQL Block, separated by semi-colons or forward slashes.

PL/SQL Developer 10.0 User’s Guide 187

In the field definition you see a list with fields from the text file. For every field you can set the

following:

• Field

The Oracle field you want to associate with the text field. You can leave this empty if you don’t

want to import this field.

• Fieldtype

The basic fieldtype: String, Number or Date.

• SQL function

This option allows you to define additional SQL processing. For date fields a to_date function is

added automatically. This is a very powerful option, allowing you to convert the imported data.

Basically, you can enter anything that can be processed by Oracle. You can add a # to indicate the

data. The “Create SQL” button will fill this field with a to_date function for date fields.

When the definition is complete, you can decide to save it. The toolbar has buttons to save and load

definition files. The text importer will remember which definition file was used for which text file, and

the definition file will be loaded automatically the next time you open the same text file.

You have two import buttons, “Import” and “Import to Script”. The first option will start importing the

data into the selected table. The second option will create an SQL script with insert statements.

 

原創作品,出自 “深藍的blog” 部落格,歡迎轉載,轉載時請務必註明以下出處,否則追究版權法律責任。

深藍的blog:http://blog.csdn.net/huangyanlong/article/details/45165707

           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述