我有一个sql select(sel=“sql select text”),其中变量定义为:var_name
select ... from (
select ... from (
select ... from table1
where session_started between toDateTime(:DatumOd) and toDateTime(:DatumDo)
and session_id in (select distinct ... from table2
where session_start>=toDateTime('2019-01-01 10:11:12') and session_module=:channel
and session_start between toDateTime(:DatumOd) and toDateTime(:DatumDo)
and ( domain_name in (:domain) or 'All domains' in (:domain) )
and (technology in (:technology) or 'All' in (:technology))
and (CASE when session_principal_role='Self care' then agent_name else session_principal_role end in (:application)
or 'All' in (:application) ) )
order by session_id desc , execution_id desc, step_started desc, step_id desc)
) where step_type=:step_type and ...
变量以“:”开头,以括号或空格结尾。
我必须用${var_name}替换每个:var_name。
目前我正在使用:
回复:sub(r):(\w+),r“${\1}”,sel),给出:
select ... from (
select ... from (
select ... from table1
where session_started between toDateTime(${DatumOd}) and toDateTime(${DatumDo})
and session_id in (select distinct ... from table2
where session_start>=toDateTime('2019-01-01 10${11}${12}') and session_module=${channel}
and session_start between toDateTime(${DatumOd}) and toDateTime(${DatumDo})
and ( domain_name in (${domain}) or 'All domains' in (${domain}) )
and (technology in (${technology}) or 'All' in (${technology}))
and (CASE when session_principal_role='Self care' then agent_name else session_principal_role end in (${application})
or 'All' in (${application}) ) )
order by session_id desc , execution_id desc, step_started desc, step_id desc)
) where step_type=${step_type} and ...
除2019-01-01 10:11:12日期常数外,一切正常。由于其中有“:”字符,其余字符被识别为变量名。
只有在“:”字符之后,我才应该替换下一个字符。
怎么做?