Regular Expression to extract user defined function in sql
I want a regular expression
that can uniquely identify the user defined function in sql queries.
For example:
with someExp(parameter)
as
(
select parameter = convert(varchar(8000),'welcome')
union all
select parameter + 'user' from someExp where lengt开发者_开发问答hOfPara(parameter) < 100
)
select parameter from someExp
order by parameter
Regular expression should uniquely identify both the function convert and lengthOfPara
.
Thanks in advance.
This is not possible. SQL queries are not described by a regular langauge, so you cannot use a regex to isolate arbitrary constructs in this manner.
Regex is not context aware, it does not know it's working on a sql query. As far as regex is concerned, it's just plain text.
And in this text there is nothing that uniquely identifies functions as separate from other constructs that consist of a word and a brackets-pair, like someExp(parameter)
and varchar(8000)
in your example.
Edit: sorry, I misread the question. removing the irrelevant parts
As others have said, a regular expression won't work.
You could use a language parser (like Bison) with the full SQL grammar to detect it.
精彩评论