早上好,伙计们,我的代码有问题,我在医疗保健上工作,投诉代码必须是复选框,但他们要求包含治疗代码的报告,该代码将出现在数据库中,如1:15:2:3等,所以我需要单独计算每个代码,我必须计算,直到我得到":“然后我需要采取数字,可以是1或2位数,然后与其他表进行内部连接可以有人帮助我修复这个函数和循环中的问题,并获得每个数字
create or replace function hcc_get_tcd_codes (p_id in number )
return varchar2 is
x number := 0 ;
y number := 0 ;
z number ;
code1 number ;
code_name varchar2(15);
begin
for i in 0 .. x
loop
select length(t.tcd_codes ) into x from hcc_patient_sheet t where t.id = p_id ; --- (9)العدد كامل
select instr(tcd_codes, ':') into y from hcc_patient_sheet t where t.id = p_id ; ---- عدد الكود الاو(3)ل
select instr(tcd_codes, ':')+1 + y into z from hcc_patient_sheet t where t.id = p_id ; --عدد الكود كامل +1
enter code here
i := x -y ;
select substr(t.tcd_codes,z, instr(tcd_codes, ':')-1) into code1
--,select substr(t.tcd_codes, 0, instr(tcd_codes, ':')-1) as code2
from Hcc_Patient_Sheet t
where t.id = 631 ;
select t.alt_name into code_name from hcc_complaint_codes t where t.code = code1 ;
select instr(tcd_codes, ':') into y from hcc_patient_sheet t where t.id = p_id ; ---- عدد الكود الاول
return code_name ;
end loop ;
end;发布于 2018-07-02 08:47:29
经常出现发音频繁的字符串处理问题,已经发明了一个轮子,甚至打包了。
select * from table(apex_string.split('THIS:IS:GREAT',':'));

发布于 2018-07-01 19:04:46
部分SUBSTR似乎不是最好的选择;我建议您将冒号分隔值字符串拆分成行,如下所示:
SQL> with test (col) as
2 (select '1:15:2:3' from dual)
3 select regexp_substr(col, '[^:]+', 1, level) one_value
4 from test
5 connect by level <= regexp_count(col, ':') + 1;
ONE_VALUE
--------------------------------
1
15
2
3
SQL>并在查询中使用这样的选项;如下所示:
select ...
into ...
from some_table t
where t.id in (select regexp_substr(that_string, '[^:]+', 1, level) one_value
from dual
connect by level <= regexp_count(that_string, ':') + 1
);如果必须逐行执行,请使用上面的选项作为游标for循环的源,如下所示
for cur_r in (select regexp_substr(that_string, '[^:]+', 1, level) one_value
from dual
connect by level <= regexp_count(that_string, ':') + 1
)
loop
do_something_here
end loop;https://stackoverflow.com/questions/51122612
复制相似问题