views:

59

answers:

2

Hi,

Basically I was trying to replace the part of string with its actual value which comes immediately after oracle operators. I can do this for limited operators list like {=,>,<} but I wonder that is there any way out to gather all the operators rather than giving them by hands? For instance, I have this string; "a = xyz", then I will replace xyz with lets say 3. But as you know we have bunch of operator namely "like,in,exists etc". So my string can also be this: "a like xyz".

So what do you suggest me?

Thanks.

+1  A: 

So what do you suggest me?

I suggest not to do this with regex (regex are not able to do so), but use an existing, proven SQL parser.

Have a look at this question on SO: http://stackoverflow.com/questions/660609/sql-parser-library-for-java

Bart Kiers
A: 

Make your job simpler - require a very strict syntax on behalf of the caller.

For example, require that the string be in the form "target operator #variable#", e.g. "a = #xyz#".

Then, all you need to do is use REPLACE(input, '#xyz#', 3).

As noted above, you probably don't want to reinvent the Oracle SQL statement parser.

Jeffrey Kemp