JaviOverflow
JaviOverflow

Reputation: 1480

Regular expression to detect table names in oracle code

I would like to detect which tables are used to get data from in procedure and function code in oracle.

... from <tablename>;
... from <tablename> <alias>;
... from <tablename> <alias> where ...;
... from <tablename> <alias> (, <tablename> <alias>)* where ...
... from <tablename> <alias> (<join> <tablename> <alias> on <onclause>)* where ...

These are some of the possible constructions.

I would like to use the module 're' in python. Any insights of how can i achieve this?

This is what I came up with so far:

[(procedure.split()[0], re.findall('FROM \w+ \w* [WHERE|,|;]*', procedure, flags=re.IGNORECASE)) for procedure in procedures]

Upvotes: 0

Views: 114

Answers (0)

Related Questions