如何在oracle中使用sqlldr有条件地加载数据
我有一个txt文件,如下所示。第一个 machine_no
、第二个 emp_no
、第三个 shift_type
(1 表示进入,3 表示退出)、第四个 work_date
、第四个是时间。
001,0000000021,01,2011/06/21,06:50,
001,0000000026,01,2011/06/21,14:00,
001,0000000018,01,2011/06/21,07:00,
001,0000000021,03,2011/06/21,14:00,
001,0000000018,03,2011/06/21,16:50,
001,0000000026,03,2011/06/21,16:55,
我想加载表中的数据。字段time1
有时间如果 time_type
为 1,如果 time_type
为 则字段 time2
具有时间 3. 请告诉我如何将其包含在控制文件中。
预先感谢您的帮助..Macky。
下面是oracle中的txt文件和表。
表格如下:
desc data_trans;
Name Null? Type
------------------------------- -------- ----
MACHIAN VARCHAR2(4)
YEAR NUMBER(4)
MONTH VARCHAR2(2)
WDAY VARCHAR2(2)
TIME1 VARCHAR2(5)
TIME2 VARCHAR2(5)
TIME3 VARCHAR2(2)
SHIFT_NO NUMBER(1)
TIME_TYPE NUMBER(1)
WORK_DATE DATE
EMP_NO VARCHAR2(10)
I have a txt file as follows. 1st machine_no
,2nd emp_no
, 3rd shift_type
(1 for entry,3 for exit), 4th work_date
, 4th is time.
001,0000000021,01,2011/06/21,06:50,
001,0000000026,01,2011/06/21,14:00,
001,0000000018,01,2011/06/21,07:00,
001,0000000021,03,2011/06/21,14:00,
001,0000000018,03,2011/06/21,16:50,
001,0000000026,03,2011/06/21,16:55,
I want to load data in the table. The field time1
to have time iftime_type
is 1 and the field time2
to have time if time_type
is
3. Please let me know how I can have this in the control file.
Thanks in advance for your help..Macky.
Below is the txt file and table in oracle.
The table as follows:
desc data_trans;
Name Null? Type
------------------------------- -------- ----
MACHIAN VARCHAR2(4)
YEAR NUMBER(4)
MONTH VARCHAR2(2)
WDAY VARCHAR2(2)
TIME1 VARCHAR2(5)
TIME2 VARCHAR2(5)
TIME3 VARCHAR2(2)
SHIFT_NO NUMBER(1)
TIME_TYPE NUMBER(1)
WORK_DATE DATE
EMP_NO VARCHAR2(10)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用外部表来读取此文件,然后您可以简单地从中进行 SELECT 并在 SQL 中轻松执行您想要的任何条件转换。
注意:有一些假设,您似乎将“time_type”与“shift_type”互换,并且数据文件等中不存在表列。
从给出的信息来看,这是一个接近的近似值。
希望有帮助。
Why don't you use an external table to read this file and then you can simply SELECT from it and perform any conditional transformation you want to easily in SQL.
N.B. There are a few assumptions, you seem to interchange "time_type" with what seems to be "shift_type" and there are table columns that are not present in your data file etc.
From the info given this is a close approximation.
Hope it helps.
这在 SQL*Loader 中是不可能的。使用 外部表,然后使用 解码 函数到 旋转。
This is not possible in SQL*Loader. Use an External Table, then copy it into your real table using the decode function to pivot.