mysql查询bom清单,ORACLE ERP导数据(BOM清单)-数据库专栏,ORACLE

方法:把数据导入bom清单的方法是,把数据导入接口表中,让其自动运行既可。上传文件的时候,要注意使      用ascii字符模式。

1、自己建立一中转表

drop table cux_bill_temp;

create table cux_bill_temp(

bill_sequence_id  number,

assembly_item_id number,

organization_id number,

assembly_item  varchar2(50),   –bom

component_sequence_id   number,

component_quantity   number, –组件数量

item_num    number, –项目序列

operation_seq_num   number, –工序序列

component_item_id   number,

component_item   varchar2(50),  –组件

planning_factor   number,  –计划%d100

component_yield_factor  number,  –产出率d1

wip_supply_type   number,  –供应类型

supply_type    varchar2(50),

supply_subinventory   varchar2(50), –供应子库存

optional    number,  –可选的

optional_disp    varchar2(10), –可选的

mutually_exclusive_options   number,  –互不相容

mutually_exclusive_o_disp  varchar2(10), –互不相容

attribute1    varchar2(50),   –排序号

row_num    number)

;

2、删除中转表中的数据

delete cux_bill_temp;

3、把要导入的数据放在扩展名为*.csv的文件中,且要相对应于中转表的字段,本例中的文件名为bill.csv。

另外的脚本文件为bill.ctl,其内容如下:

options (skip=1)  //跳过第一行,一般第一行为其字段说明

load data

infile bill.csv  //bill.csv为数据文件

append

into table cux_bill_temp

fields terminated by “,” optionally enclosed by “

(与中转表相对应的字段列表)

登录进入oracle数据库服务器,利用命令:(sqlload 用户名/密码@数据库名)载入文件bill.csv的数据入中转表。

4、查看中转表中的记录数(以备导入数据后进行对比)

select count(*) from cux_bill_temp;

5、去除导入时在表bill.csv中的关键字段的空格字符,以免影响导入。

update cux_bill_temp

set assembly_item=replace(assembly_item, ,),

component_item=replace(component_item, ,);

6、查看是否有重复的选项(既是否重复了item)

select assembly_item,component_item,min(row_num),count(*)

from cux_bill_temp

group by assembly_item,component_item

having count(*)>1;

如果有重复的item,则要删除(或是重新合并)

delete cux_bill_temp

where row_num in (select min(row_num) from cux_bill_temp

group by assembly_item,component_item

having count(*)>1);

以下步骤为选做(如有重复才做,没有重复不做7-10)

7、再重新建立一个临时表(对于有重复数据,则只取一条数据,现取row_num最小的一条)

drop table cux_bill_a;

create table cux_bill_a

as

select assembly_item,

component_item,

component_quantity,

planning_factor,

component_yield_factor,

supply_type,

supply_subinventory,

optional_disp,

mutually_exclusive_o_disp,

attribute1,

min(row_num) row_num

from cux_bill_temp

group by assembly_item,

component_item,

component_quantity,

planning_factor,

component_yield_factor,

supply_type,

supply_subinventory,

optional_disp,

mutually_exclusive_o_disp,

attribute1;

8、删除cux_bill_temp表

delete cux_bill_temp;

9、再重cux_bill_a表中把数据导入给cux_bill_temp表,完成把重复数据剔除的功能

insert into cux_bill_temp(

assembly_item,

component_item,

component_quantity,

planning_factor,

component_yield_factor,

supply_type,

supply_subinventory,

optional_disp,

mutually_exclusive_o_disp,

attribute1,

row_num)

select assembly_item,

component_item,

component_quantity,

planning_factor,

component_yield_factor,

supply_type,

supply_subinventory,

optional_disp,

mutually_exclusive_o_disp,

attribute1,

row_num

from cux_bill_a;

10、删除表cux_bill_a

drop table cux_bill_a;

11、再检查一次表,是否有重复的数据

select assembly_item,component_item,min(row_num),count(*)

from cux_bill_temp

group by assembly_item,component_item

having count(*)>1;

12、查看在mtl_system_items表中,既是在库存表中,有没有不存在的item.

select distinct item

from (

select distinct assembly_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.assembly_item and organization_id=2)

union

select distinct component_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2)

)

order by item;

13、如果在mtl_system_items中,有不存在的物品item时,要把其删除(或是把这些物品item导入到系统中)

删除:delete cux_bill_temp b

where  not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2);

delete cux_bill_temp a

where not exists  (select null from mtl_system_items where segment1=a.assembly_item  and organization_id=2);

14、对没有物品item的进行处理,把其放入另一临时表cux_item_temp中(以备查询及导入mtl_system_items表中)

delete cux_item_temp;

insert into cux_item_temp(

segment1,description)

select distinct item,item

from (

select distinct assembly_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.assembly_item and organization_id=2)

union

select distinct component_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2)

)

;

将找到没有item的bom数据放到另一个表中,以备下次item导入后在导bom

create table cux_bom_temp1

select distinct item

from (

select distinct assembly_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.assembly_item and organization_id=2)

union

select distinct component_item item

from cux_bill_temp b

where not exists (select null from mtl_system_items where segment1=b.component_item and organization_id=2)

)

———————————————————————————————————–

15、从表mtl_system_items中把物品的编码id加入中转表cux_bill_temp表(从项目主组织)中

update cux_bill_temp b

set assembly_item_id=(select inventory_item_id from mtl_system_items

where segment1=b.assembly_item and organization_id=2),

component_item_id=(select inventory_item_id from mtl_system_items

where segment1=b.component_item and organization_id=2);

16、查看是否有没有物品id的编码存在(既没有物品的id被导入临时表cux_bill_temp中)

select row_num

from cux_bill_temp

where assembly_item_id is null or component_item_id is null;

17、对其中导入的数据进行处理

update cux_bill_temp

set optional=1

where upper(optional_disp) like y%;

update cux_bill_temp

set optional=2

where optional is null;

update cux_bill_temp

set mutually_exclusive_options=1

where upper(mutually_exclusive_o_disp) like y%;

update cux_bill_temp

set mutually_exclusive_options=2

where mutually_exclusive_o_disp is null;

18、查看cux_bill_temp中的数据处理是否有漏

select count(*)

from cux_bill_temp

where optional is null

or mutually_exclusive_options is null

or assembly_item_id is null

or component_item_id is null;

19、更新其内的wip_supply_type;

update cux_bill_temp

set wip_supply_type=6

where component_item like b%;

20、删除表中的包(cux_bill_temp中),其相对应于表bom_bill_of_materials(既在表中已经存在了些选项包,不必导入包头,只需导入包内容既可)

delete cux_bill_temp t

where exists (select null from bom_bill_of_materials where assembly_item_id=t.assembly_item_id and organization_id=2);

21、利用已经写好的包写入数据(既写入接口表bom_bill_of_mtls_interface)

exec cux_bom_temp.insert_bill_15(1);

select count(*) from cux_bill_temp temp

where exits (select null from bom_inventory_components  b

where temp.bill_sequence_id=b.bill_sequence_id

and temp.component_item_id=b.component_item_id);

delete cux_bill_temp temp

where exists (select null from bom_inventory_components  b

where b.bill_sequence_id=temp.bill_sequence_id

and b.component_item_id=temp.component_item_id);

exec cux_bom_temp.insert_bill_10(1);

22、对写入的数据在接口表中的情况进行查看

select count(*) from bom_bill_of_mtls_interface;

23、接着更新

exec cux_bom_temp.insert_bill_15(1);

select count(*) from cux_bill_temp where bill_sequence_id is null;

exec cux_bom_temp.insert_bill_20(1);

去提交请求

select count(*) from bom_inventory_comps_interface;

(导入成功后)对组件进行排序

exec cux_bom_temp.update_bill_item_num4;

select count(*) from bom_inventory_comps_interface;

24、对于接口表中的数据进行导入

delete bom_bill_of_mtls_interface;

insert into bom_bill_of_mtls_interface(

assembly_type,assembly_item_id,

organization_id,

process_flag,transaction_type)

select  distinct 1,assembly_item_id,

1,

1,create

from cux_bill_temp;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值