How to loop through a delimited list in Oracle PLSQL(如何循环遍历 Oracle PLSQL 中的分隔列表)
问题描述
我正在研究一个 Oracle 过程,该过程在其中调用另一个过程.我的参数之一 (parm1)
可以在逗号分隔列表中包含一个或多个值.如何遍历这些值以将它们一次传递给另一个过程?
I am working on an Oracle procedure that calls another procedure within it. One of my parameters (parm1)
can contain one or more values in a comma separated list. How can I loop through these values to pass them one at a time to another procedure?
这是我希望它做的一个例子:
Here is an example of what I would like it to do:
When Parm1 = 123,312
callProcedure2(123)
callProcedure2(321)
-或-
When Parm1 123
callProcedure2(123)
我认为这可以使用循环来完成,但我不知道如何让它将每个值用作循环内的单独调用.
I think this can be accomplished using a loop but I can't figure out how to get it to use each value as a separated call within the loop.
任何帮助将不胜感激!
谢谢!
推荐答案
只需循环子串:
declare
parm1 varchar2(1000) := '123,234,345,456,567,789,890';
vStartIdx binary_integer;
vEndIdx binary_integer;
vCurValue varchar2(1000);
begin
vStartIdx := 0;
vEndIdx := instr(parm1, ',');
while(vEndIdx > 0) loop
vCurValue := substr(parm1, vStartIdx+1, vEndIdx - vStartIdx - 1);
-- call proc here
dbms_output.put_line('->'||vCurValue||'<-');
vStartIdx := vEndIdx;
vEndIdx := instr(parm1, ',', vStartIdx + 1);
end loop;
-- Call proc here for last part (or in case of single element)
vCurValue := substr(parm1, vStartIdx+1);
dbms_output.put_line('->'||vCurValue||'<-');
end;
这篇关于如何循环遍历 Oracle PLSQL 中的分隔列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何循环遍历 Oracle PLSQL 中的分隔列表


基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01