1、Oracle 存储过程中传入参数('A,B','C')比如'A,B'要用到 in 的时候,需要用正则函数:
regexp_substr(参数,'[^,]+'),对参数进行格式化,相当于:
where 条件 in (select * from 临时表)
例子:
where a.discardflagv ='N'
and (a.errmessage='~' or a.errmessage is null)
and c.code in (regexp_substr(zbcode1,'[^,]+'))
这种只能取到第一个参数值;
想在存过里面用in 的话换成:
and instr(','||zbcode1||',',','||c.code||',')>0等价于
and c.code in ('JW0003-0001','JW0004-0001','JW0005-0001');
zbcode1(入参)='JW0003-0001,JW0004-0001,JW0005-0001'
c.code=条件查询的字段;
2、可以在存过里面写,替换逗号为',' 符合的写法:
zbcode1='aaa,bbb,ccc'
cshu:=REPLACE(zbcode1,',',chr(39)||','||chr(39));
cshu='aaa','bbb','ccc'
3、输出语句: dbms_output.put_line(chr(39)||REPLACE(zbcode1,',',chr(39)||','||chr(39))||chr(39));
chr(39)||REPLACE(zbcode1,',',chr(39)||','||chr(39))||chr(39)='aaa','bbb','ccc'