I've got an (at least i thought so) simple task: Comparing 2 tables by columnnames, datatypes and length only to verify they have the same structure so far. It should be done in an existing perl script which is connecting to two different databases.
First I simply queried each databases user_tab_columns
and compared the result. Now I found out the hard way that user_tab_columns
is not live but has to be refreshed by analyzing the table ( http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4462.htm#REFRN26277 ), which I absoultly had no idea of.
describe
gets the actual table definition, but doesn't seem to work through perls dbi:Oracle, so I stumbled upon the table_info()
and column_info()
methods. But where do they get their information from? If they just query *_tab_columns
as well, they're not of use to me.
I can't simply test because I didn't manage to pass the right parameters yet. The Dbi Documentation says it is according to the database driver. The Oracle DBD Documentation wasn't very helpfull to me as well, trial and error so far resulted in getting all objects or nothing at all.
At the moment I'm thinking of executing describe
via sqlplus
through a perl system call and parsing the output....but there has to be a better way.
EDIT:
The view user_tab_columns
works as expected, if checking the right columns (see comments below ).
You might have not found the DBD::Oracle documentation particularly helpful, but did you consider using the source code?
Here is the source for table_info() and column_info(). Both subroutines largely seem to be spent building up SQL statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With