Regex plsql中的字符串构造问题

Regex plsql中的字符串构造问题,regex,replace,plsql,Regex,Replace,Plsql,我有一根像这样的绳子 LEAST("col1", "col2") GREATEST("col1", "col2") 从这个字符串,我想得到一个结果字符串,比如 col1 IN LEAST(v_col1, v_col2) AND col2 IN GREATEST(v_col1, v_col2) 其中v_u追加到列名后,它们表示预定义的变量。 列数可以是动态的。 我尝试了太多的选择,但没有达到预期的效果 请建议 这是我正在尝试的几个选择,但似乎没有朝着正确的方向前进 declare txt va

我有一根像这样的绳子

LEAST("col1", "col2") GREATEST("col1", "col2")
从这个字符串,我想得到一个结果字符串,比如

col1 IN LEAST(v_col1, v_col2) AND col2 IN GREATEST(v_col1, v_col2)
其中v_u追加到列名后,它们表示预定义的变量。 列数可以是动态的。 我尝试了太多的选择,但没有达到预期的效果

请建议

这是我正在尝试的几个选择,但似乎没有朝着正确的方向前进

declare txt varchar2(1000);
anstxt varchar2(1000);
begin
txt := 'LEAST("col1","col2")';
select REGEXP_SUBSTR(TXT,'"([^"]*)"',1,1,'',1) into anstxt from dual;
DBMS_OUTPUT.PUT_LINE(anstxt);
end;


declare 
v_Var5 varchar2(50);
v_Var6 varchar2(1000);
v_Var7 varchar2(10);
v_Var8 varchar2(10);
CURSOR c3 IS
    SELECT column_expression  FROM all_ind_expressions WHERE table_owner = 'schemaname' AND table_name = 'mytable';    

names_t  c3%ROWTYPE;
    TYPE names_ntt IS TABLE OF names_t%TYPE; -- must use type
    l_names  names_ntt;
BEGIN
v_Var7 := ' IN (';
v_Var8 := ');';
--FOR i in c3
OPEN  c3;
    FETCH c3 BULK COLLECT INTO l_names;
    CLOSE c3;

    FOR indx IN 1..l_names.COUNT LOOP
    IF(l_names.COUNT > 1) THEN
      v_Var6 := v_Var6 || REPLACE(l_names(indx).column_expression, '"', '');
        DBMS_OUTPUT.PUT_LINE(l_names(indx).column_expression);
    ELSE
      v_Var6 := REPLACE(l_names(indx).column_expression, '"', '');
    END IF;
    END LOOP;
    v_Var6 := v_Var7 || REPLACE(v_Var6, ' ', ' AND ') || v_Var8;
--DBMS_OUTPUT.PUT_LINE(v_Var5);
DBMS_OUTPUT.PUT_LINE(v_Var6);
END;

问候。

经过这么多的考验,我终于得到了我想要的东西。 我将此分享给论坛参考

DECLARE
v_Var5 varchar2(1000);
v_Var6 varchar2(1000);
v_Var7 varchar2(10);
v_Var8 varchar2(10);
v_Var9 varchar2(1000);
v_Counter NUMBER;
CURSOR c3 IS
    SELECT column_expression  FROM all_ind_expressions WHERE table_owner = 'myschema' AND table_name = 'mytable';    

names_t  c3%ROWTYPE;
    TYPE names_ntt IS TABLE OF names_t%TYPE; -- must use type
    l_names  names_ntt;
BEGIN
  v_Counter := 1;
  v_Var7 := ' IN (';
  v_Var8 := ');';

  OPEN  c3;
    FETCH c3 BULK COLLECT INTO l_names;
  CLOSE c3;

  FOR indx IN 1..l_names.COUNT 
  LOOP
    --v_Counter := l_names.COUNT;
    IF(l_names.COUNT > 1) THEN
      v_Var6 := REPLACE(l_names(indx).column_expression, '"', '');
      FOR i IN 1..l_names.COUNT LOOP
        v_Var6 := REPLACE(v_Var6, REGEXP_SUBSTR(l_names(i).column_expression,'"([^"]*)"',1,i,'',1),'v_' || REGEXP_SUBSTR(l_names(i).column_expression,'"([^"]*)"',1,i,'',1));
      END LOOP;
      v_Var9 := REGEXP_SUBSTR(l_names(indx).column_expression,'"([^"]*)"',1,indx,'',1) || ' IN (';   
      CASE 
        WHEN indx < l_names.COUNT THEN 
          v_Var5 := v_Var5 || v_Var9 || v_Var6 || ') AND ';
        WHEN indx = l_names.COUNT THEN 
          v_Var5 := v_Var5 || v_Var9 || v_Var6 || ');';
      END CASE;
     ELSE
      v_Var6 := REPLACE(l_names(indx).column_expression, '"', '');
      v_Var6 := REPLACE(v_Var6, REGEXP_SUBSTR(l_names(indx).column_expression,'"([^"]*)"',1,indx,'',1),'v_' || REGEXP_SUBSTR(l_names(indx).column_expression,'"([^"]*)"',1,indx,'',1));
      v_Var9 := REGEXP_SUBSTR(l_names(indx).column_expression,'"([^"]*)"',1,indx,'',1) || ' IN ';  
      v_Var5 := v_Var5 || v_Var9 || v_Var6;
    END IF;
  END LOOP;
    --DBMS_OUTPUT.PUT_LINE('v_Var9' || CHR(13) || v_Var9);
    --DBMS_OUTPUT.PUT_LINE('v_Var6' || CHR(13) ||v_Var6);
  DBMS_OUTPUT.PUT_LINE('v_Var5' || CHR(13) ||v_Var5);
END;

你可以发布到目前为止你尝试过的内容,其他人可能会对你有所帮助。Xing,编辑我的帖子,添加我尝试过的一些内容。Xing和其他人,请看一看,并建议是否有更好、更短的方法。