0 down vote favorite share [g+] share [fb] share [tw]

I have a long String which is dynamic. Wherever % XXX % is found, I have to get the XXX value and replace it with some other value. There will be multiple % XXX %. How can I get the value within the % %?

For Eg.

"POLICY_NO = %POLNO%  and b.ACTION_TIME = (select max(ACTION_TIME) from POLICY_DETAILS where POLICY_NO = %POLICYID%)"

How can I read each value between 2 %? And I have to take POLNO and compare it with some session variables(Eg,POLNO=1234567,POLICYID=3) and if it is matched then i have to replace the session variable value. Then the query sholud become as

"POLICY_NO = 1234567 and b.ACTION_TIME = (select max(ACTION_TIME) from POLICY_DETAILS where POLICY_NO = 3)"