我有一根绳子是这样的:
(InstrTyp EQ DebtInstruments) AND (IntrnlTrdTyp EQ IntraGrpBP) AND (Entity EQ GSSTH)我想将它们保存在一个数组中,以便:
InstrTyp EQ DebtInstrumentsIntrnlTrdTyp EQ IntraGrpBPEntity EQ GSSTH新的PL/SQL,欣赏一个详细的答案。
发布于 2019-02-22 10:33:00
您可以使用regexp_substr提取括号之间的字符串。
DECLARE
TYPE string_array_typ IS
TABLE OF VARCHAR2(100);
split_strs string_array_typ := string_array_typ(); --define and declare an array of string
l_str_to_split VARCHAR2(1000) := '(InstrTyp EQ DebtInstruments) AND (IntrnlTrdTyp EQ IntraGrpBP) AND (Entity EQ GSSTH)'
;
BEGIN
FOR i IN 1..regexp_count(l_str_to_split,'\(.*?\)') --loop until as many number of strings between `()`
LOOP
split_strs.extend;
split_strs(i) := regexp_substr(l_str_to_split,'\((.*?)\)',1,i,NULL,1); -- Assign ith element to ith word between `()`
END loop;
FOR i IN 1..split_strs.count LOOP
dbms_output.put_line(split_strs(i) ); --display the contents of the array
END LOOP;
END;
/发布于 2019-02-22 10:24:44
我们可以分两步来做。首先,从输入字符串中删除所有括号,然后对模式\s*AND\s*上的数组执行regex拆分。
select
regexp_split_to_array(regexp_replace(txt, '[()]', '', 'g'), '\s*AND\s*')
from your_table;

https://stackoverflow.com/questions/54824817
复制相似问题