ORACLE分割字符串

create or replace function DRAG_GET_VINDICATE_ID(V_VINDICATE_CODE in varchar2)
return varchar2 is
Result varchar2(200);
v_team_code varchar2(200);
v_temp_code varchar2(200);
v_department_id varchar2(200);
v_count number;
begin
Result := '';
v_count := 0;
v_team_code := V_VINDICATE_CODE;
select INSTR(v_team_code, ';', 1, 1) into v_count from dual;
--如果不包含分号
if v_count = 0 then
select p.department_id
into Result
from pub_department p
where p.code = v_team_code;
--如果包含分号
else
while v_team_code is not null loop
--判断是否有分号
select INSTR(v_team_code, ';', 1, 1) into v_count from dual;
if v_count = 0 then
--如果没有,赋值为空 下次循环跳出
v_temp_code := v_team_code;
v_team_code := '';
else
--如果有,截取第一个分号
select substr(v_team_code, 0, INSTR(v_team_code, ';', 1, 1) - 1)
into v_temp_code
from dual;
end if;
--根据CODE找ID
select p.department_id
into v_department_id
from pub_department p
where p.code = v_temp_code;
Result := Result || v_department_id || ';';
--截取分号后的字符串
select substr(v_team_code,
INSTR(v_team_code, ';', 1, 1) + 1,
length(v_team_code))
into v_team_code
from dual;
--去掉最后一个分号
if v_team_code is null then
Result := substr(Result, 0, length(Result) - 1);
end if;
end loop;
end if;
return(Result);
end DRAG_GET_VINDICATE_ID;

下面这个就很简洁

select pub_department.department_id
from pub_department
where instr(';' || 'CAS4592;CAS4601' || ';',
';' || pub_department.code || ';') > 0;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值