zoukankan      html  css  js  c++  java
  • oracle xmltype导入并解析Excel数据 (五)中间表数据入库

    此处给出例子,具体根据业务需求


    create or replace procedure P_CART_Sheet1(p_id in NUMBER) is
    --车辆管理功能
    v_str varchar2(4000);
    v_building_id number;
    begin
    --获取 building_id
    select t.expandtype into v_str from t_excel_import_datasrc t where t.id = p_id;
    v_building_id := to_number(v_str);

    --跨库查询注意授权: eg:grant select on t_bas_datadict to estate ,否则编译不通过
    -- 查找并更新单元名称不存在的数据 --单元名称与单元id关联关系
    update t_excel_import_generation t
    set t.errormsg = '单元名称不存在'
    where t.businessid = p_id and t.businesstype = 'CART_Sheet1' and t.errormsg is null
    and t.cell1 not in (
    SELECT U.NAME UNIT_NAME
    FROM BAS_CART T
    RIGHT JOIN BAS_BUILDING_UNIT U ON T.UNIT_ID=U.UNIT_ID
    WHERE 1 = 1
    AND U.STATE = '1' AND U.BUILDING_ID = v_building_id
    );
    commit;
    --将单元名称更新为单元id
    update t_excel_import_generation t
    set t.cell1 = (
    select distinct k.unit_id from (
    SELECT U.NAME UNIT_NAME,U.Unit_Id
    FROM BAS_CART T
    RIGHT JOIN BAS_BUILDING_UNIT U ON T.UNIT_ID=U.UNIT_ID
    WHERE 1 = 1 AND U.STATE = '1' AND U.BUILDING_ID = v_building_id
    ) k where k.unit_name = t.cell1
    )
    where t.businessid = p_id and t.businesstype = 'CART_Sheet1' and t.errormsg is null;
    commit;

    MERGE INTO BAS_CART t
    USING (
    select to_number(Cell1) Cell1,Cell2,Cell3,Cell4,Cell5,Cell6,Cell7
    from t_excel_import_generation t
    where t.errormsg is null and t.businesstype = 'CART_Sheet1' and t.businessid = p_id
    ) k
    ON (t.lic_plate_no = k.cell2 and t.unit_id = k.Cell1)
    WHEN MATCHED THEN
    UPDATE SET
    t.model = k.Cell3,
    t.color = k.Cell4,
    t.parking_space = k.Cell5,
    t.update_time = sysdate,
    t.link_man = k.Cell6,
    t.link_phone = k.Cell7
    WHEN NOT MATCHED THEN
    INSERT (ID,UNIT_ID,LIC_PLATE_NO,MODEL,COLOR,PARKING_SPACE,UPDATE_TIME,DEL_FLAG,LINK_MAN,LINK_PHONE)
    VALUES(
    SEQ_BAS_CART_ID.NEXTVAL,k.Cell1,k.cell2,k.Cell3,k.Cell4,k.Cell5,sysdate,1, k.Cell6,k.Cell7
    );

    Exception
    when others then
    dbms_output.put_line('----------插入表失败啦---------表id: '||p_id);
    dbms_output.put_line('原始错误信息: 行号:'||dbms_utility.format_error_backtrace()||' '||sqlerrm);
    PKG_EXCEL_UTILS.p_log(p_id,sqlerrm,dbms_utility.format_error_backtrace(),'ERROR',SQLCODE);
    raise;
    end P_CART_Sheet1;


  • 相关阅读:
    获取AppSettings配置,获取连接字符串
    类在初始化的时候做了什么事
    Easyui Tabs 添加怎么添加。
    Tree数据格式 Easyui
    使用CodeFirst建表的时候要知道的特性
    从数据导出模型到pd设计器
    orm的几种排序写法
    Parallel.ForEach 并行循环的使用
    kendo gird 刷新数据源的几种方式
    表格设置宽度在ie9上无效
  • 原文地址:https://www.cnblogs.com/zkongbai/p/5681007.html
Copyright © 2011-2022 走看看