sqlldr 导入数据时保留原有表里特定数据的问题

ckkwing 2009-03-03 09:31:04
控制函数:
OPTIONS (skip=1,rows=128)
LOAD DATA
INFILE "test.csv"
REPLACE INTO TABLE usr_pms.pmm_safestock
Fields terminated by ","
Optionally enclosed by '"'
trailing nullcols
(
ps_id RECNUM,
ps_item,
ps_des,
ps_qty,
ps_type
)
数据csv:
ITEM,Des.,safestock,type
4170001800,MCU包装,100,1
4170001802,MCU包装,100,1
4170001800,MCU包装,100,1
4170001800,MCU包装,100,1
4170001803,MCU包装,101,2
4170001803,MCU包装,103,3
问题:每次运行控制文件时都会把原来表里的数据清空,然后写入新的数据,我想实现的功能是保留原有表中的特定行,列如:导入新数据csv:
ITEM,Des.,safestock,type
4170001802,MCU包装,101,2
4170001804,MCU包装,103,3
4170001804,MCU包装,103,3
4170001804,MCU包装,103,5
保留表中原有type=1的数据,然后把type!=1的数据清空,再把新的数据添加到表里,不知道是否能实现这个功能,如果能的话,请大家教我一下(刚接触sqlldr不太懂),谢谢!
...全文
217 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oraclelogan 2009-03-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hdhai9451 的回复:]
先导入到一个临时表,再用merge into语句可以实现
merge into作用如果表中记录已经存在,则更新,如果不存在则插入
也可以有where条件条件限制,
[/Quote]

学习了!
ckkwing 2009-03-03
  • 打赏
  • 举报
回复
sqlldr 里delete怎么用,能告诉我一下吗?举个简单的例子行吗?谢谢
vc555 2009-03-03
  • 打赏
  • 举报
回复
添了再delete
ckkwing 2009-03-03
  • 打赏
  • 举报
回复
merge into 也是sqlldr 里的语法吗?还有append into好像是添加数据的,可是表里的部分数据是需要清空的
vc555 2009-03-03
  • 打赏
  • 举报
回复
别用REPLACE INTO,
用append into
Andy__Huang 2009-03-03
  • 打赏
  • 举报
回复
先导入到一个临时表,再用merge into语句可以实现
merge into作用如果表中记录已经存在,则更新,如果不存在则插入
也可以有where条件条件限制,
zcs_1 2009-03-03
  • 打赏
  • 举报
回复
楼主的要求不能实现,下面是Oracle文档介绍的导入非空表的几个选项,只能是在原表基础上增加数据,或者删除原表的数据,并增加新的数据。楼主的要求1楼给出了一个好办法。

Loading Data into Nonempty Tables
If the tables you are loading into already contain data, you have three options:

APPEND

REPLACE

TRUNCATE

APPEND
If data already exists in the table, SQL*Loader appends the new rows to it. If data does not already exist, the new rows are simply loaded.

REPLACE
With REPLACE, all rows in the table are deleted and the new data is loaded. The table must be in your schema, or you must have DELETE privilege on the table.

TRUNCATE
The SQL TRUNCATE statement quickly and efficiently deletes all rows from a table or cluster, to achieve the best possible performance.

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧