Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 每次迭代都在过程中传递值对_Sql_Loops_Plsql_Cursor - Fatal编程技术网

Sql 每次迭代都在过程中传递值对

Sql 每次迭代都在过程中传递值对,sql,loops,plsql,cursor,Sql,Loops,Plsql,Cursor,我正在创建一个过程,其中一个输入参数是: 1-由分号分隔的数字字符串 for example: lv_string VARCHAR2(100) := '10; 20; 30'; 然后,我有一个光标,可以获取数字 for example: lv_cur that stores values 1, 2, 3 我有一个程序,我很难找到解决方案,如何通过: 1. iteration procedure process_input(pin_one => first value from

我正在创建一个过程,其中一个输入参数是: 1-由分号分隔的数字字符串

for example: lv_string VARCHAR2(100) := '10; 20; 30';
然后,我有一个光标,可以获取数字

for example: lv_cur that stores values 1, 2, 3
我有一个程序,我很难找到解决方案,如何通过:

1. iteration 
   procedure process_input(pin_one => first value from lv_string,
                           pin_two => first value from lv_cur
                          )
2. iteration
   procedure process_input(pin_one => second value from lv_string,
                           pin_two => second value from lv_cur
                          )
3. iteration
   procedure process_input(pin_one => third value from lv_string,
                           pin_two => third value from lv_cur
                          )

你能帮我找到解决这个问题的办法吗?是否有可能编写一个游标来返回这些值对?

关键组件是创建一个例程,它可能只是一个查询,可以将分隔字符串解析为单个数字并返回结果。最简单的方法是创建一个函数,该函数接受带分隔符的数字列表和指定的分隔符,并返回数字集合。还可以创建一个架构级集合oracle提供了一些您可以使用的集合

-- create a schema level collection of numbers
create or replace 
type list_of_numbers_t 
     is table of number; 
 
-- create a function that parses a string containing a delimited list on numbers
-- and returns the collection defined above
create or replace 
function parse_delimited_list_of_numbers
              (list_of_delimited_numbers_in varchar2 
              ,delimiter_in  varchar2
         )
 return list_of_numbers_t 
 is
     l_parsed_numbers list_of_numbers_t;
     l_regex_pattern  varchar2(16) := '[^<dlm>]+';
begin 
    l_regex_pattern := replace(l_regex_pattern,'<dlm>',delimiter_in); 
    select to_number(trim(regexp_substr(list_of_delimited_numbers_in,l_regex_pattern,1,level)))
      bulk collect 
      into l_parsed_numbers
      from dual connect by 
                regexp_substr(list_of_delimited_numbers_in,l_regex_pattern,1,level) is not null;
    return l_parsed_numbers; 
end parse_delimited_list_of_numbers;

请看这里的示例。

太棒了!感谢您的清晰解释和示例。我感谢你的帮助!如果提供的答案解决了您的问题,请接受。不要将已回答的问题留待讨论。接受的答案有助于以后可能有相同/类似问题的提问者。