简体   繁体   English

使用正则表达式根据oracle运算符解析字符串

[英]parsing string according to oracle operators with regex

Basically I was trying to replace the part of string with its actual value which comes immediately after oracle operators. 基本上,我试图用字符串的实际值替换字符串的一部分,该值在oracle运算符之后立即出现。 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 . "a = xyz" ,那么我将用"a = xyz" 3代替xyz But as you know we have bunch of operator namely "like,in,exists etc" . 但正如您所知,我们有一堆运算符,即"like,in,exists etc" So my string can also be this: "a like xyz" . 所以我的字符串也可以是: "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. 我建议不要使用正则表达式执行此操作(正则表达式无法执行此操作),而是使用现有的,经过验证的SQL解析器。

Have a look at this question on SO: SQL parser library for Java 看看SO的这个问题: Java的SQL解析器库

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#", eg " a = #xyz# ". 例如,要求字符串的格式为“目标运算符#variable#”,例如“ a = #xyz# ”。

Then, all you need to do is use REPLACE(input, '#xyz#', 3) . 然后,您需要做的就是使用REPLACE(input, '#xyz#', 3)

As noted above, you probably don't want to reinvent the Oracle SQL statement parser. 如上所述,您可能不想重新发明Oracle SQL语句解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM