在oracle中,查找当前编码的一级部门

create table A
(
DEPTID INTEGER not null, --部门ID
DEPT_CODE VARCHAR2(720) not null, --部门编码
PARENT_ID VARCHAR2(720) not Null --父节点('-1'为顶级节点,'-'1的下级节点为一级部门)
);
alter table A add constraint DEPT_CODE_PK primary key (DEPT_CODE);

Insert Into A (DEPTID,DEPT_CODE,PARENT_ID) Values('1004', '106707000000', '281' );
Insert Into A (DEPTID,DEPT_CODE,PARENT_ID) Values('281' , '106700000000', '43' );
Insert Into A (DEPTID,DEPT_CODE,PARENT_ID) Values('43' , '100000000000', '7289');
Insert Into A (DEPTID,DEPT_CODE,PARENT_ID) Values('7289', '000000000000', '-1' );
Commit;

--查找当前编码的一级部门
With all_id As (
Select t.parent_id , t.deptid From A t
Start With t.dept_code = '106707000000'
Connect By Prior t.parent_id = t.deptid )
Select deptid From all_id a Where a.parent_id =
(Select b.deptid From all_id b Where b.parent_id = '-1')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值