You can extract the parameters with a regular expression '(.*?)'.*?'(.*?)'
. Then you should use parameters substitution into your SQL request, don't use simple string replacement.
UPDATED
Why you don't want to use a simple string replacement to form an SQL request? Because you expose yourself to an SQL injection hacking attack. Consider that someone provides you the following input:
What is the id where we have '\' as company name and ' OR 1=1;' as the device type?
Now you have two matching groups of characters between apostrophes:
group 1: a single backslash character
group 2: a string ' OR 1=1;'
After substitution this into the output string you'll get
select * from DIM_DEVICE_TYPE where COMPANY_NAME = '\' and DEVICE_TYPE = ' OR 1=1;'
What will happen next? For example MySQL treats a backslash in front of an apostrophe as an escape character, so it will treat this select as a search for a company with a very strange name ' and DEVICE_TYPE =
(yes, the company name starts with an apostrophe), and this search is combined with a condition OR 1=1. Since 1=1 condition is always true the whole condition for search is true and you'll get the full list of all entries in you DIM_DEVICE_TYPE table.