方法:把數(shù)據(jù)導(dǎo)入bom清單的方法是,把數(shù)據(jù)導(dǎo)入接口表中,讓其自動(dòng)運(yùn)行既可。上傳文件的時(shí)候,要注意使      用ascii字符模式。
1、自己建立一中轉(zhuǎn)表
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, --組件數(shù)量
  item_num    number, --項(xiàng)目序列
  operation_seq_num   number, --工序序列
  component_item_id   number,
  component_item   varchar2(50),  --組件
  planning_factor   number,  --計(jì)劃%d100
  component_yield_factor  number,  --產(chǎn)出率d1
  wip_supply_type   number,  --供應(yīng)類型
  supply_type    varchar2(50),
  supply_subinventory   varchar2(50), --供應(yīng)子庫(kù)存
  optional    number,  --可選的
  optional_disp    varchar2(10), --可選的
  mutually_exclusive_options   number,  --互不相容
  mutually_exclusive_o_disp  varchar2(10), --互不相容
  attribute1    varchar2(50),   --排序號(hào)
  row_num    number)
;
2、刪除中轉(zhuǎn)表中的數(shù)據(jù)
   delete cux_bill_temp;
3、把要導(dǎo)入的數(shù)據(jù)放在擴(kuò)展名為*.csv的文件中,且要相對(duì)應(yīng)于中轉(zhuǎn)表的字段,本例中的文件名為bill.csv。
   另外的腳本文件為bill.ctl,其內(nèi)容如下:
options (skip=1)  //跳過(guò)第一行,一般第一行為其字段說(shuō)明
load data
infile bill.csv  //bill.csv為數(shù)據(jù)文件
append
into table cux_bill_temp
fields terminated by "," optionally enclosed by '"'
(與中轉(zhuǎn)表相對(duì)應(yīng)的字段列表)
登錄進(jìn)入oracle數(shù)據(jù)庫(kù)服務(wù)器,利用命令:(sqlload 用戶名/密碼@數(shù)據(jù)庫(kù)名)載入文件bill.csv的數(shù)據(jù)入中轉(zhuǎn)表。
4、查看中轉(zhuǎn)表中的記錄數(shù)(以備導(dǎo)入數(shù)據(jù)后進(jìn)行對(duì)比)
   select count(*) from cux_bill_temp;
5、去除導(dǎo)入時(shí)在表bill.csv中的關(guān)鍵字段的空格字符,以免影響導(dǎo)入。
   update cux_bill_temp
   set assembly_item=replace(assembly_item,' ',''),
   component_item=replace(component_item,' ','');
6、查看是否有重復(fù)的選項(xiàng)(既是否重復(fù)了item)
  select assembly_item,component_item,min(row_num),count(*)
  from cux_bill_temp
  group by assembly_item,component_item
  having count(*)>1;
 如果有重復(fù)的item,則要?jiǎng)h除(或是重新合并)
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);
以下步驟為選做(如有重復(fù)才做,沒(méi)有重復(fù)不做7-10)
7、再重新建立一個(gè)臨時(shí)表(對(duì)于有重復(fù)數(shù)據(jù),則只取一條數(shù)據(jù),現(xiàn)取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表中把數(shù)據(jù)導(dǎo)入給cux_bill_temp表,完成把重復(fù)數(shù)據(jù)剔除的功能
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、再檢查一次表,是否有重復(fù)的數(shù)據(jù)
   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表中,既是在庫(kù)存表中,有沒(méi)有不存在的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時(shí),要把其刪除(或是把這些物品item導(dǎo)入到系統(tǒng)中)
  刪除: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、對(duì)沒(méi)有物品item的進(jìn)行處理,把其放入另一臨時(shí)表cux_item_temp中(以備查詢及導(dǎo)入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)
)
;
將找到?jīng)]有item的bom數(shù)據(jù)放到另一個(gè)表中,以備下次item導(dǎo)入后在導(dǎo)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加入中轉(zhuǎn)表cux_bill_temp表(從項(xiàng)目主組織)中
  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、查看是否有沒(méi)有物品id的編碼存在(既沒(méi)有物品的id被導(dǎo)入臨時(shí)表cux_bill_temp中)
   select row_num
     from cux_bill_temp
    where assembly_item_id is null or component_item_id is null;
17、對(duì)其中導(dǎo)入的數(shù)據(jù)進(jìn)行處理
   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中的數(shù)據(jù)處理是否有漏
  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、更新其內(nèi)的wip_supply_type;
  update cux_bill_temp
     set wip_supply_type=6
   where component_item like 'b%';
20、刪除表中的包(cux_bill_temp中),其相對(duì)應(yīng)于表bom_bill_of_materials(既在表中已經(jīng)存在了些選項(xiàng)包,不必導(dǎo)入包頭,只需導(dǎo)入包內(nèi)容既可)
  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、利用已經(jīng)寫好的包寫入數(shù)據(jù)(既寫入接口表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、對(duì)寫入的數(shù)據(jù)在接口表中的情況進(jìn)行查看
   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);
去提交請(qǐng)求
select count(*) from bom_inventory_comps_interface;
(導(dǎo)入成功后)對(duì)組件進(jìn)行排序
  exec cux_bom_temp.update_bill_item_num4;
  select count(*) from bom_inventory_comps_interface;
24、對(duì)于接口表中的數(shù)據(jù)進(jìn)行導(dǎo)入
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;