Home » SQL & PL/SQL » SQL & PL/SQL » renaming column at run time
renaming column at run time [message #288543] Mon, 17 December 2007 23:58 Go to next message
hidnana
Messages: 87
Registered: November 2007
Location: chennai
Member
Is it possible to do something like this from a running program ?

alter table xxx rename column c1 to c2;
I'm unable to try this out as I don't have the privilege.
Re: renaming column at run time [message #288551 is a reply to message #288543] Tue, 18 December 2007 00:24 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
Quote:

Is it possible to do something like this from a running program ?


but, why do you want to do that????

Quote:

I don't have the privilege.

are you not the owner of the table.

regards,


[Updated on: Tue, 18 December 2007 00:26]

Report message to a moderator

Re: renaming column at run time [message #288557 is a reply to message #288543] Tue, 18 December 2007 00:34 Go to previous messageGo to next message
hidnana
Messages: 87
Registered: November 2007
Location: chennai
Member
I've asked the same question to the person who had asked me this. As I wasn't sure and unable to try it out, I thought it is better to ask in the forum.
Re: renaming column at run time [message #288559 is a reply to message #288543] Tue, 18 December 2007 00:35 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

but, why do you want to do that????

Because there is only one table and each program renames the table and its columns for its needs.

Regards
Michel
Re: renaming column at run time [message #288561 is a reply to message #288559] Tue, 18 December 2007 00:40 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member

Quote:

Michel Cadot

Quote:

but, why do you want to do that????


Because there is only one table and each program renames the table and its columns for its needs.




i didn't quite understand ?

regards,
Re: renaming column at run time [message #288580 is a reply to message #288561] Tue, 18 December 2007 01:40 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Tongue in cheek response.

Regards
Michel
Re: renaming column at run time [message #288599 is a reply to message #288543] Tue, 18 December 2007 02:50 Go to previous messageGo to next message
MarcS
Messages: 312
Registered: March 2007
Location: Antwerp
Senior Member
1. It is possible to rename your column at runtime, if and only if:

Your program connects to the database via an user with the proper privilege - or as the user owning the table.

Your program is running at a moment where there is no other activity on that table. Renaming a column will ask for an exclusive lock on the table, otherwise the rename will fail.

That answers your question, but:

2. We are all asking ourselves: Why do you need to be able to rename the column at runtime?
Because in all those years working with Oracle I have never had a situation where I had to do something like that.

Regards,
Marc
Re: renaming column at run time [message #288726 is a reply to message #288543] Tue, 18 December 2007 07:46 Go to previous message
Bill B
Messages: 1482
Registered: December 2004
Senior Member
Why do you want to actually rename the columns? what use is this? But if you must here are 3 selects with different names for the columns

select col1,col2,col3 from my_table;

select col1 cola, col2 colb, col3 colc from my_table;

select col1 this, col2 is, col3 stupid from my_table;


Hows this?

Or even

create view my_table_v
as select col1 this, col2 is, col3 stupid from my_table;

[Updated on: Tue, 18 December 2007 07:47]

Report message to a moderator

Previous Topic: Order by
Next Topic: costs of joins
Goto Forum:
  


Current Time: Sat Dec 03 07:45:42 CST 2016

Total time taken to generate the page: 0.12407 seconds