Urgent help needed! Trouble getting column names from tables

Good morning,

I was given some tables on an Oracle database, but unfortunately I do
not know the field/column names of the table. I've made numerous
attempts to print such a list for a given table, but they never seem
to work. I've been trying SQL queries such as:

SELECT column_name FROM user_tab_cols WHERE table_name =
'mytable'sname'

Sometimes I'm able to get them to run with no errors... yet no result
is produced when I try to print them. I'm not sure if there is some
trick with DBI that I'm overlooking. Any tips would be greatly
appreciated!

Cheers,
Kacey
intel.g33k [ Di, 26 Juni 2007 14:31 ] [ ID #1749227 ]

Re: Urgent help needed! Trouble getting column names from tables

intel.g33k [at] gmail.com wrote:
> Good morning,
>
> I was given some tables on an Oracle database, but unfortunately I do
> not know the field/column names of the table. I've made numerous
> attempts to print such a list for a given table, but they never seem
> to work. I've been trying SQL queries such as:
>
> SELECT column_name FROM user_tab_cols WHERE table_name =
> 'mytable'sname'
>
> Sometimes I'm able to get them to run with no errors... yet no result
> is produced when I try to print them. I'm not sure if there is some
> trick with DBI that I'm overlooking. Any tips would be greatly
> appreciated!
>
> Cheers,
> Kacey
>
>

If you only want the info about columns in a table have you tried:

$sth = $dbh->column_info( $catalog, $schema, $table, $column );

I would guess if you get no result, the where clause is not matching a
table.

column_info is the portable way to do it.

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
Martin.Evans [ Di, 26 Juni 2007 16:00 ] [ ID #1749228 ]

Re: Urgent help needed! Trouble getting column names from tables

i think there is a syscolumns and systables tables that contain that
data.


On Jun 26, 2007, at 7:31 AM, intel.g33k [at] gmail.com wrote:

> Good morning,
>
> I was given some tables on an Oracle database, but unfortunately I do
> not know the field/column names of the table. I've made numerous
> attempts to print such a list for a given table, but they never seem
> to work. I've been trying SQL queries such as:
>
> SELECT column_name FROM user_tab_cols WHERE table_name =
> 'mytable'sname'
>
> Sometimes I'm able to get them to run with no errors... yet no result
> is produced when I try to print them. I'm not sure if there is some
> trick with DBI that I'm overlooking. Any tips would be greatly
> appreciated!
>
> Cheers,
> Kacey
>
hwigoda [ Di, 26 Juni 2007 16:01 ] [ ID #1749229 ]

RE: Urgent help needed! Trouble getting column names from tables

intel.g33k [at] gmail.com wrote:
> Good morning,
>
> I was given some tables on an Oracle database, but unfortunately I do
> not know the field/column names of the table. I've made numerous
> attempts to print such a list for a given table, but they never seem
> to work. I've been trying SQL queries such as:
>
> SELECT column_name FROM user_tab_cols WHERE table_name =3D
> 'mytable'sname'
>
> Sometimes I'm able to get them to run with no errors... yet no result
> is produced when I try to print them. I'm not sure if there is some
> trick with DBI that I'm overlooking. Any tips would be greatly
> appreciated!


Well I suppose you could use DBI for this, but why? Just run "desc
<tablename>" in sqlplus.

- Philip
Philip.Garrett [ Di, 26 Juni 2007 16:25 ] [ ID #1749230 ]

Re: Urgent help needed! Trouble getting column names from tables

On Jun 26, 10:25 am, Philip.Garr... [at] manheim.com (Philip Garrett)
wrote:
> intel.g... [at] gmail.com wrote:
> > Good morning,
>
> > I was given some tables on an Oracle database, but unfortunately I do
> > not know the field/column names of the table. I've made numerous
> > attempts to print such a list for a given table, but they never seem
> > to work. I've been trying SQL queries such as:
>
> > SELECT column_name FROM user_tab_cols WHERE table_name =
> > 'mytable'sname'
>
> > Sometimes I'm able to get them to run with no errors... yet no result
> > is produced when I try to print them. I'm not sure if there is some
> > trick with DBI that I'm overlooking. Any tips would be greatly
> > appreciated!
>
> Well I suppose you could use DBI for this, but why? Just run "desc
> <tablename>" in sqlplus.
>
> - Philip


Thank you everyone for your help! I was eventually able to get it to
work using:

$sth = $dbh->prepare("select table_name, column_name from
all_tab_columns where table_name = 'mytablesname'");

I will test out your other solutions, though. I appreciate the help
greatly!
intel.g33k [ Mi, 27 Juni 2007 17:56 ] [ ID #1751659 ]

Re: Urgent help needed! Trouble getting column names from tables

Hi Folks

There are Perl modules designed to solve this problem. One is:

http://search.cpan.org/~rsavage/DBIx-Admin-TableInfo-2.00/

--
Ron Savage
ron [at] savage.net.au
ron [ Do, 28 Juni 2007 02:18 ] [ ID #1751661 ]
Perl » perl.dbi.users » Urgent help needed! Trouble getting column names from tables

Vorheriges Thema: DBD::mysql connect dying with "Can't initialize character set latin1"
Nächstes Thema: DBI-1.58 test failure on Windows