Oracle 12c - SQL * Loader条件加载

时间:2016-12-29 14:36:39

标签: oracle12c sql-loader controlfile

我正在尝试使用SQL Loader,在将数据插入表格时,我需要检查一些条件并插入数据。
示例:

SELECT sq.team_id, avg(sq.time_owned) as median_val FROM (
SELECT t1.row_number, t1.time_owned, t1.team_id FROM(
SELECT IF(@prev!=d.team_id, @rownum:=1, @rownum:=@rownum+1) as `row_number`, d.time_owned, @prev:=d.team_id AS team_id, d.task_id
FROM task_timer d, (SELECT @rownum:=0, @prev:=NULL) r
ORDER BY team_id, time_owned
) as t1 INNER JOIN  
(
  SELECT count(*) as total_rows, team_id 
  FROM task_timer d
  GROUP BY team_id
) as t2
ON t1.team_id = t2.team_id
WHERE 1=1
AND t1.row_number>=t2.total_rows/2 and t1.row_number<=t2.total_rows/2+1
)sq
group by sq.team_id

我们可以在SQL Loader控制文件中使用这些case语句吗?无论如何都找不到好的例子。

2 个答案:

答案 0 :(得分:1)

尝试在控制文件中添加代码,如:

load data
  APPEND INTO TABLE XXX
  fields terminated by "\t"
  TRAILING NULLCOLS
  ( --Condition which you can add.
    START_DATE "CASE WHEN length(:START_DATE ) < 10 THEN null ELSE :START_DATE END"      

  ) 

其中START_DATE是表格的列

答案 1 :(得分:0)

对于更复杂的测试或您可以重用的其他需求,您还可以调用返回值的函数或包成员:

...
START_DATE "UTILITY_PKG.VALIDATE_DATE(:START_DATE)" 

或查询(必须附在perentheses中):

START_DATE "(select sysdate from dual)",