开发者

parsing string according to oracle operators with regex

开发者 https://www.devze.com 2022-12-24 22:24 出处:网络
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

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开发者_JS百科 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.


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: SQL parser library for Java


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消