drop procedure proc_fi_deptment;
delimiter //
create procedure proc_fi_deptment()
begin
/* 標記是否出錯/
declare t_error int default 0;
/* 標記是否跳出迴圈/
declare flag int default 1;
#層級declare cj int default 0;
#下層級
declare cjnext int default 0;
#個數declare sl int default 0;
/** 如果出現sql異常,則將t_error設定為1後繼續執行後面的操作 */
declare continue handler for sqlexception set t_error=1; # 出錯處理
# 開始事務
start transaction;
#建立未分層級的臨時表
delete from ofs_fi_department_temporary ;
insert into ofs_fi_department_temporary
select a.kokrs,
b.spras,
a.prctr dept_code,
b.ktext dept_name,
a.zwdlxbm dept_type_code,
b.zwdlxmc dept_type_name,
a.zzhprctr parent_dept_code,
a.datab,
a.datbi,
a.lock_ind lock_ind,
a.delfg,
a.lastupdate,
null
from sap_fi_network a
left join sap_fi_network_children b
on a.kokrs = b.kokrs
and a.prctr = b.prctr
and a.datbi = b.datbi
where a.delfg is null
and sysdate() between a.datab and a.datbi ;
update ofs_fi_department_temporary ofd set ofd.`level` = 0,ofd.parent_dept_code = null
where ofd.dept_code = '001';
create or replace table ofs_fi_department
asselect * from ofs_fi_department_temporary where dept_code= '001';
alter table `ofs_fi_department`
add index `dept_code` (`dept_code`),
add index `parent_dept_code` (`parent_dept_code`),
add index `level` (`level`);
while flag = 1 do
select count(ofd1.dept_code) into sl from ofs_fi_department ofd1 where ofd1.`level`=cj ;
if sl > 0 then
set cjnext = cj+1;
insert into ofs_fi_department
select * from ofs_fi_department_temporary ofd2 where ofd2.parent_dept_code in (select ofd3.dept_code from ofs_fi_department ofd3 where ofd3.`level` = cj);
update ofs_fi_department ofd4 set ofd4.`level` = cjnext where ofd4.`level` is null;
commit;
set cj = cj+1;
else
set flag =0;
end if;
end while;
if t_error=1 then
rollback; -- 事務回滾
else
commit; -- 事務提交
end if;
end ;
delimiter ;
call proc_fi_deptment();
MySql 查詢表有多少列
查詢乙個表共有多少列數 select count from information schema.columns where table schema 庫名 and table name 表名 查詢某個資料庫中某個表的所有列名 select column name from information ...
三層四層二叉樹有多少種
rt,三層四層二叉樹有多少種,延伸下就是問題 二叉樹不同層數的有多少種?0層的二叉樹有1種 a0 1 一層的二叉樹有1種 a1 1 二層的二叉樹有3種 a2 2 a0 a1 a1 a1 3 三層的二叉樹有2 a0 a2 a1 a2 a2 a2 21種 四層的二叉樹有2 a0 a3 a1 a3 a2 ...
三層四層二叉樹有多少種
rt,三層四層二叉樹有多少種,延伸下就是問題 二叉樹不同層數的有多少種?0層的二叉樹有1種 a0 1 一層的二叉樹有1種 a1 1 二層的二叉樹有3種 a2 2 a0 a1 a1 a1 3 三層的二叉樹有2 a0 a2 a1 a2 a2 a2 21種 四層的二叉樹有2 a0 a3 a1 a3 a2 ...