早上好,我对代码有问题,我在卫生保健部门工作,并且抱怨代码必须为复选框,但他们要求提供包含治疗代码的报告,该代码将出现在数据库中,例如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;
答案 0 :(得分:1)
通常在听起来弦乐处理方面经常出现问题,因此已经发明了一个轮子,甚至对其进行了包装。
async function start() {
const services = Config.get('app.services');
try {
const serverPromises = services.map(async (service) => {
const server = await Server.deployment(service.host, service.port);
await server.start();
return server;
});
const servers = await Promise.all(serverPromises);
servers.forEach(server => {
console.log(`Server running at ${server.info.uri}`);
});
} catch (err) {
console.log('an error has been caught');
console.log(err);
process.exit(1);
}
}
答案 1 :(得分:0)
部分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;