Home » Developer & Programmer » Precompilers, OCI & OCCI » TABLE NAME / JOIN / ATTR_GET / OCI
TABLE NAME / JOIN / ATTR_GET / OCI [message #113076] Wed, 30 March 2005 18:04 Go to next message
laplante
Messages: 3
Registered: March 2005
Junior Member
When I do a select from two table, can I get the table name
for each column name.

For example:

while (parm_status==OCI_SUCCESS) {
/* Retrieve the column name attribute */
sndb_checkerr(pl, OCIAttrGet((dvoid*) mypard, (ub4)
OCI_DTYPE_PARAM,
(dvoid**) &col_name,(ub4 *
&col_name_len, (ub4) OCI_ATTR_NAME,
(OCIError *) pl -> errhp ));

will retreive the column name but if the 2 tables have the same name, I need to know the name of the table

How do I get the table name for each column if OCI?
Re: TABLE NAME / JOIN / ATTR_GET / OCI [message #113079 is a reply to message #113076] Wed, 30 March 2005 18:18 Go to previous messageGo to next message
Michael Hartley
Messages: 110
Registered: December 2004
Location: West Yorkshire, United Ki...
Senior Member

Hi,

I think you could be approaching this problem from an academic position rather than a practical position.

If I have a query and I wish to list the columns of the query for my report, I would describe the result set.

If 2 or more result set columns have the same name then the query should be modified to include the column alias.

If I really want to know the column names of 2 or more tables then you should be working against the user_tables and user_tab_columns views.

eg.
select * from user_tables;

select * from user_tab_columns where owner = 'OWNER' and table_name = 'TABLE_NAME';

Michael Hartley
Re: TABLE NAME / JOIN / ATTR_GET / OCI [message #113083 is a reply to message #113079] Wed, 30 March 2005 18:30 Go to previous messageGo to next message
laplante
Messages: 3
Registered: March 2005
Junior Member
Interesting point of view. So since Oracle does not return the name of the table user has to adjust and modify his/her SQL request!

This is not a way I like to do my stuff. But its a last solution to my request if I can't find another way.

Thanks.
Re: TABLE NAME / JOIN / ATTR_GET / OCI [message #113087 is a reply to message #113083] Wed, 30 March 2005 18:40 Go to previous message
Michael Hartley
Messages: 110
Registered: December 2004
Location: West Yorkshire, United Ki...
Senior Member

Hi,

if you discover how to dynamically describe a query to include the tablename and column name then post and example. I'd appreciate having a read of your code.

No points for disecting the original sql fragment though, you have to use OCI function calls. Laughing

Michael.
Previous Topic: How can I convert a char to date?
Next Topic: OCILobCreateTemporary Error
Goto Forum:
  


Current Time: Fri Apr 19 13:08:49 CDT 2024