SQL LOAD DATA INFILE但保持一个字段静态

时间:2018-08-15 18:25:43

标签: oracle sql-loader

我正在运行以下命令将数据加载到表中

OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt' 
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|" 
TRAILING NULLCOLS
(
DIMENSION,
PARENT,
CHILD,
ALIAS,
ATTRB01
)

这工作正常,但是我想将ATTRB01字段保留为静态值,我想为所有记录加载“ Alloc”,即使我从其他字段的文件?

2 个答案:

答案 0 :(得分:1)

您将加载一个常量,例如

bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("YlOrRd", domain = states$density, bins = bins)

m %>% addPolygons(
  fillColor = ~pal(density),
  weight = 2,
  opacity = 1,
  color = "white",
  dashArray = "3",
  fillOpacity = 0.7)

这是一个例子:测试表:

OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt' 
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|" 
TRAILING NULLCOLS
(
DIMENSION constant Account,
PARENT,
CHILD,
ALIAS,
ATTRB01  constant 'Alloc'       --> this
)

控制文件:

SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- -------------
 ID                                                 NUMBER
 ATTRB01                                            VARCHAR2(20)

加载会话和结果:

load data 
infile *
replace
into table test
fields terminated by ","
trailing nullcols
(
id,
attrb01 constant 'Alloc'
)

begindata
1,xxx
2,yyy
3,zzz

答案 1 :(得分:0)

最后使用set尝试

OPTIONS (Skip=1)
LOAD DATA
INFILE 'D:\EPM\import\test.txt' 
APPEND
INTO TABLE HYP.HS_MEMBER_D
FIELDS TERMINATED BY "|" 
TRAILING NULLCOLS
(
DIMENSION constant Account,
PARENT,
CHILD,
ALIAS,
ATTRB01
)
set ATTRB01='default_value'