0

How could I get all the tables in .sql file with a lot of plsq/ anonymous blocks? The ideal would had been get it through data dictionaries but it's not possible because they're not in the database.

I was thinking read the text with regular expressions: does anybody have a better idea?

APC
  • 144,005
  • 19
  • 170
  • 281
NeDiaz
  • 349
  • 3
  • 14

1 Answers1

1

Unless you can guarantee that the SQL is in a certain format making it easy to pick out tables, what you will need is a PLSQL/SQL lexical analyser.

See this for details :

Where can I find an official grammar for the PL/SQL programming language?

To illustrate my point, take this example:

SELECT a, b
FROM tabA, tabB
WHERE x = y;

will work if you grep 'FROM[:space:]' | cut -d' ' -f2.

But, if you have:

SELECT a, b
FROM tabA,
     tabB
WHERE c IN ( SELECT x
             FROM tabC,
                  tabD
.
.

Then things get tricky, and you need Lex/Yacc type grammar analyser.

UPDATE, INSERT, DELETE should be fairly simple:

egrep '(UPDATE|INSERT|DELETE)[:space:]' src.sql | cut -d' ' -f2

Should get you started.

But, once you get more flowery layouts you will find it starts to miss things.

TenG
  • 3,843
  • 2
  • 25
  • 42