Syntax

IMPORT FROM [<file_type>] <file_path> [INTO <table_name>] [WITH <import_from_option_list>]
Syntax Elements
<file_type> ::= CSV FILE | CONTROL FILE

The type of the file to be imported. You can specify either comma-separated values or control file formats. For more information on CSV and control file formats, see Examples.

待导入文件的类型,有两种类型的文件:
  • CSV FILE :该文件存储的为表数据
  • CONTROL FILE:该文件是控制文件,即将导入的脚本写在这个文件里,然后还是通过这个 IMPORT 语句执行这个脚本控制文件即可,这样就不需要将导数的语句直接贴在SQL编辑器里运行了
<file_path> ::= <string_literal>

The complete path and file name of the file to import.

文件路(注意是服务器上的,不是本机哦)
<table_name> ::= [<schema_name>.]<identifier><schema_name> ::= <unicode_name>

The target table name, with optional schema name, where the imported data will be stored.

将数据导到哪个表中
WITH <import_from_option_list> ::= <import_from_option>[{, <import_from_option>}...]
<import_from_option> ::= THREADS <number_of_threads>
| BATCH <number_of_records_of_each_commit>
| TABLE LOCK
| NO TYPE CHECK
| SKIP FIRST <number_of_rows_to_skip> ROW
| COLUMN LIST IN FIRST ROW [<with_schema_flexibility>]
| COLUMN LIST ( <column_name_list> ) [<with_schema_flexibility>]
| RECORD DELIMITED BY <string_for_record_delimiter>
| FIELD DELIMITED BY <string_for_field_delimiter>
| OPTIONALLY ENCLOSED BY <character_for_optional_enclosure>
| DATE FORMAT <string_for_date_format>
| TIME FORMAT <string_for_time_format>
| TIMESTAMP FORMAT <string_for_timestamp_format>
| ERROR LOG <file_path_of_error_log>
| FAIL ON INVALID DATA

A list of import options.
导入选项
THREADS <unsigned_integer>

The number of threads that can be used for concurrent import. The default value is 1 and maximum allowed is 256.

允许最大的并行线程数量,默认是1,最大是256
BATCH <number_of_records_of_each_commit> ::= <unsigned_integer>

The number of records to be inserted in each commit.

每批提交的条数,即多少条后提交
 
Note: THREADS and BATCH can be used to achieve high loading performance by enabling parallel loading and also by committing many records at once. In general, for column tables, a good setting to use is 10 parallel loading threads, with a commit frequency of 10,000 records or greater.
注: THREADS 、BATCH 这两个参数是用来提升并发导入数据的性能的参数,在通常情况中下对于列存储表,推荐使用10个并发线程,每批1万条就提交
TABLE LOCK

Can be used for faster data loading for column store tables. 可以加快列存储表数据的导入

It is recommended to specify this option carefully as it incurs table locks in exclusive mode as well as explicit hard merges and savepoints after data loading is finished. The performance gain from this option can vary according to the table constraints (like primary key) and optimization of other layers (like persistency or DML command).

NO TYPE CHECK

Specifies that the record will be inserted without checking the type of each field.

导入时不检查字段类型
SKIP FIRST <number_of_rows_to_skip> ROW
<number_of_rows_to_skip> ::= <unsigned_integer>

Skips the specified number of rows in the import file.

指定跳过多少行后开始导入,比如有表头时
COLUMN LIST IN FIRST ROW

Indicates that the column list is stored in the first row of the CSV import file.

第一行做为COLUMN LIST选项的值,这样就可以使用COLUMN LIST IN FIRST ROW选项替代了COLUMN LIST选项(COLUMN LIST选项见下面)
COLUMN LIST ( <column_name_list> )
<column_name_list> ::= <column_name> [{, <column_name>}...]

The column list for the data being imported. The name list has one or more column names. The ordering of the column names has to match the order of the column data in the CSV file and the columns in the target table.

指定CSV文件里的数据列将要存储到表中的哪些列中,因为有时CSV里提借的列数比表实际列数要少,或者CSV里的第一列要存储到表里的第三列,等...为了解决这些列数不配以及存储的位置不配时,需要通过这个选项来实现,请看后面的示例
RECORD DELIMITED BY <string_for_record_delimiter> ::= <string_literal>

The record delimiter used in the CSV file being imported.

行与行的分隔符
FIELD DELIMITED BY <string_for_field_delimiter> ::= <string_literal>

The field delimiter of the CSV file.

字段分隔符
OPTIONALLY ENCLOSED BY <character_for_optional_enclosure> ::= <character_literal>

The optional enclosure character used to delimit field data.

字符(串)使用什么引起来
DATE FORMAT <string_for_date_format> ::= <string_literal>

The format that date strings are encoded with in the import data:

指定日期格式

  • Y : year
  • MM : month
  • MON : name of month
  • DD : day
For example:

  • 'YYYYMMDD' = 20120520
  • 'YYYY-MM-DD' = 2012-05-20
  • 'YYYY-MON-DD' : 2012-MAY-20
TIME FORMAT <string_for_time_format> ::= <string_literal>

The format that time strings are encoded with in the import data:

指定时间格式

  • HH24 : hour
  • MI : minute
  • SS : second

For example:

  • 'HH24MISS' : 143025
  • 'HH24:MI:SS' : 14:30:25
TIMESTAMP FORMAT <string_for_timestamp_format> ::= <string_literal>

The format that timestamp strings are encoded with in the import data.

指定日期时间格式
For example:

  • 'YYYY-MM-DD HH24:MI:SS' : 2012-05-20 14:30:25
ERROR LOG <file_path_of_error_log> ::= <string_literal>

When specified, a log file of errors generated is stored in this file. Please ensure the file path you use is writeable by the database.

指定错误日志文件(含路径)

FAIL ON INVALID DATA

When specified, the IMPORT FROM command fails unless all the entries import successfully.

遇到无效数据会立即停止IMPORT FROM命令
<with_schema_flexibility> ::= WITH SCHEMA FLEXIBILITY

The option WITH SCHEMA FLEXIBILITY will create missing columns in flexible tables during CSV imports, as specified in the header (first row) of the CSV file or column list. By default, missing columns in flexible tables are not created automatically during data imports.

根据CSV里的表头行(第一行,使用COLUMN LIST IN FIRST ROW选项指定)或者是COLUMN LIST 选项中提供的列名来创建缺失的列,具体示例请参考后面示例。注:该选项是用在CREATE COLUMN TABLE...语句后面
For security reason, only CSV files located at paths defined in thecsv_import_path_filterconfiguration parameter are allowed to be loaded using the IMPORT FROM SQL statement. This feature can be disabled using theenable_csv_import_path_filterconfiguration parameter. Two related configuration parameters are specified in theimport_exportsection of the indexserver (nameserver in case of multi-DB) configuration, so you can turn off this feature or update path filter like follows:
由于安全原因,需要配置csv_import_path_filter服务器参数配置导入的CSV文件的路径,但该参数可以通过enable_csv_import_path_filter服务配置参数来禁用它,即将enable_csv_import_path_filter设置为false后,就不需要配置csv_import_path_filter路径参数了,即该参数失效
除了通过界面配置外,还可以通过下面命令来修改服务器配置参数:

ALTER SYSTEM ALTER CONFIGURATION ('indexserver.ini', 'system') set ('import_export', 'enable_csv_import_path_filter') = 'false' with reconfigure
ALTER SYSTEM ALTER CONFIGURATION ('indexserver.ini', 'system') set ('import_export', 'csv_import_path_filter') = '/A;/B' with reconfigure

Note that once you add a path '/A' to path filter every sub-path of '/A' will be automatically added as well.

注:一旦配置了'/A'路径,则其下面的子文件夹也会生效,不需要另外配置,就都可以做为CSV文件的导入路径了
This feature is used with restrictions and/or is extended by the following SAP HANA option:

  • Dynamic Tiering
Examples

Example 1 - Importing CSV Data

You create a table mytable to store the imported data.
CREATE TABLE mytable ( A INT, B VARCHAR(10), C DATE, D TIME, E DECIMAL );
 
You create a CSV text file /usr/sap/HDB/home/Desktop/data/data.csv and add the following contents.

1,"DATA1","2012-05-20","14:30:25",123456
2,"DATA2","2012-05-21","15:30:25",234567
3,"DATA3","2012-05-22","16:30:25",345678
4,"DATA4","2012-05-23","17:30:25",456789

You execute the following command to import the data. IMPORT FROM CSV FILE '/usr/sap/HDB/home/Desktop/data/data.csv' INTO "MYTABLE"

   WITH RECORD DELIMITED BY '\n'
   FIELD DELIMITED BY ',';
 

Example 2 - Importing using a control file

In the example below, you import the CSV data from Example 1 using a control file.
在这个示例中,我们使用控制文件来完成上面示例同样的功能
You can create a control file /usr/sap/HDB/home/Desktop/data/data.ctl and add the contents shown below to the file.
创建/usr/sap/HDB/home/Desktop/data/data.ctl控制文件,并在文件中输入以下内容:
IMPORT DATA INTO TABLE "MYTABLE" FROM '/usr/sap/HDB/home/Desktop/data/data.csv'
   RECORD DELIMITED BY '\n'
   FIELD DELIMITED BY ','
   OPTIONALLY ENCLOSED BY '"'

ERROR LOG '/usr/sap/HDB/home/Desktop/data/data.err'

 

You execute the following command to import the data using the control file.

IMPORT FROM CONTROL FILE '/usr/sap/HDB/home/Desktop/data/data.ctl';
执行后,不管是否产生了错误,都会生成data.err文件

Example 3 - Import using date formats

In the example below, the date format is of the CSV import data is different to the default date format 'YYYY-MM-DD'. In this import data the date format used is 'MM-DD-YYYY'. You create a CSV text file /usr/sap/HDB/home/Desktop/data/data_different_date.csv and add the following contents.

1,"DATA1","05-20-2012","14:30:25",123456
2,"DATA2","05-21-2012","15:30:25",234567
3,"DATA3","05-22-2012","16:30:25",345678
4,"DATA4","05-23-2012","17:30:25",456789
You execute the following command to import the data.

IMPORT FROM CSV FILE '/usr/sap/HDB/home/Desktop/data/data_different_date.csv' INTO "MYTABLE" WITH RECORD
   DELIMITED BY '\n'
   FIELD DELIMITED BY ','
   DATE FORMAT 'MM-DD-YYYY';

Example 4 - Import using COLUMN LIST

You create a table called COLLIST to store the imported data.

CREATE TABLE COLLIST ( A INT, B VARCHAR(10), C DATE, D DECIMAL );
You create a CSV text file '/usr/sap/HDB/home/Desktop/data/data_col_list.csv' and add the following contents.

现在

data_col_list.csv文件里的内容如下,B列值没有提供,并且CSV里的第一列要存到D列里,第二列要存到C里,第三列要存储到A列里
123456,"2012-05-20",1 234567,"2012-05-21",2 345678,"2012-05-22",3 456789,"2012-05-23",4
 

You execute the following commands to import the data using a column list.

IMPORT FROM CSV FILE '/usr/sap/HDB/home/Desktop/data/data_col_list.csv' INTO "COLLIST"
   WITH RECORD DELIMITED BY '\n'
   FIELD DELIMITED BY ','

COLUMN LIST ("D", "C", "A");

In order to import data without dealing with the proper table layout, it is possible to use WITH SCHEMA FLEXIBILITY as extended option of COLUMN LIST to import into a flexible table. You create a flexible table to store the imported data.

CREATE COLUMN TABLE FLEX ( X INT ) WITH SCHEMA FLEXIBILITY;--WITH SCHEMA FLEXIBILITY选项只能用于列式存储的表
创建一个可伸缩的表,只有X一列,使用上面的data_col_list.csv文件,文件里有3列,且都没存储到X列里

You execute the following commands to import previously created data_col_list.csv without explicitly adding columns.

IMPORT FROM CSV FILE '/usr/sap/HDB/home/Desktop/data/data_col_list.csv' INTO "FLEX"
   WITH RECORD DELIMITED BY '\n'
   FIELD DELIMITED BY ','
   COLUMN LIST ("A", "B", "C", "D") --注:如果使用了 WITH SCHEMA FLEXIBILITY选项,则一定要指定COLUMN LIST,或者使用COLUMN LIST IN FIRST ROW选项来指定CSV里的第一行为COLUMN LIST

WITH SCHEMA FLEXIBILITY;

 

在自动创建缺失的列时,好像无法指定类型,默认类型全为 nvarchar(5000)?这不太好吧!是否有办法指定呢?

IMPORT FROM 表数据导入的更多相关文章

  1. Excel表数据导入Sql Server数据库中

    Excel表数据导入Sql Server数据库的方法很多,这里只是介绍了其中一种: 1.首先,我们要先在test数据库中新建一个my_test表,该表具有三个字段tid int类型, tname nv ...

  2. 把execel表数据导入mysql数据库

    今天,是我来公司第二周的第一天. 作为新入职的实习生,目前还没适合我的实质项目工作,今天的学习任务是: 把execel表数据导入到mysql数据库,再练习下java操作JDBC. 先了解下execel ...

  3. SqlServer一张表数据导入另一张表,收藏使用,工作中更新数据错误很有用

    sql一张表数据导入另一张表   1.如果2张表的字段一致,并且希望插入全部数据,可以用这种方法:   INSERT INTO 目标表 SELECT * FROM 来源表;   2.比如要将 arti ...

  4. HBase(三): Azure HDInsigt HBase表数据导入本地HBase

    目录: hdfs 命令操作本地 hbase Azure HDInsight HBase表数据导入本地 hbase hdfs命令操作本地hbase: 参见  HDP2.4安装(五):集群及组件安装 , ...

  5. Excel表数据导入数据库表中

    ***Excel表数据导入到数据库表中 通过数据库表的模板做成‘Excel’表的数据导入到数据库相应的表中(注意:主表 和 从表的关系,要先导‘主表’在导入从表) 过程:通过数据库的导入工具—先导入为 ...

  6. C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库

    C# DateTime的11种构造函数   别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...

  7. java基于xml配置的通用excel单表数据导入组件(四、DAO主处理类)

    package XXXXX.manage.importexcel; import java.beans.IntrospectionException; import java.io.BufferedR ...

  8. 利用Sql实现将指定表数据导入到另一个数据库示例

    因为工作中经常需要将数据从一个数据库导入到另一个数据库中,所以将这个功能写成一个存储过程,以方便调用.现在粘贴出来供大家参考: 注意:1,以下示例中用到了syscolumns,sysobjects等系 ...

  9. java基于xml配置的通用excel单表数据导入组件(五、Action处理类)

    package xxxxxx.manage.importexcel; import java.io.File; import java.util.HashMap; import java.util.M ...

随机推荐

  1. AOP programming paradiag

    AOP https://en.wikipedia.org/wiki/Aspect-oriented_programming Typically, an aspect is scattered or t ...

  2. VSS转SVN

    我们都知道VSS和SVN都是源代码的版本控制软件:最近公司准备把多年使用的VSS代码全部转到SVN中进行管理,查询了一些资料,整理一下,分享给大家 基本分三大步进行,如下: 1.去掉VSS所有绑定 2 ...

  3. 在github分支上上传空文件夹

    GIT工具是依靠文件来识别文件夹的,对于空的文件夹是不能识别的.因此如果需要在代码中增加一个空文件夹,同时需要在文件夹中增加一个空文件.gitkeep 当批量增加空文件夹时,可以在GIT库的根目录下输 ...

  4. Url通配符映射

    原文:http://www.cnblogs.com/liukemng/p/3726897.ht 1.URL路径映射 1.1.对一个action配置多个URL映射: 我们把上一篇中的HelloWorld ...

  5. 在IE下,如果在readonly的input里面键入backspace键,会触发history.back()

    在IE下,如果在readonly的input里面键入backspace键,会触发history.back(), 用以下jQuery代码修正之 $("input[readOnly]" ...

  6. activiti 里面各个方法理解

    /** Return the intent that started this activity. */public Intent getIntent() { return mIntent;} pub ...

  7. kali安装谷歌浏览器的方法及启动问题的解决

    在kali上安装谷歌浏览器的时候,遇到了很多问题,经过不懈努力,终于解决,现在把方法总结一下,希望对遇到同样问题的人能有一定帮助.这是给最白的小白参考的,大牛勿喷哈. 说明:我是在kali rolli ...

  8. Spring Mvc + Mybatis + sqlserver maven

    mybatis config  datasource: <!-- 配置数据源 使用的是Druid数据源 --> <bean name="dataSource" c ...

  9. PMP考试

    今天是第二次PMP模拟考试,得了146分,比上次高25分,这次题目相对简单些,看来昨晚的复习没有白费,还是有效果的. 有些题目影响还是比较深刻,老外的项目管理思想是先规划好一切再执行(管理),比如信息 ...

  10. ios webView 放大网页解决/input 获得焦点focus 网页放大 解决

    新手遇到的问题: 终于找到原因,各种HTML viewport 都试过 setScalePageToFit 也试过,webViewDidFinishLoad加JS代码,动态算webView.scrol ...