Reputation: 829
Description of my problem: For example I have a table "Item" and columns "id", "name", "color", but for some weird reason (please don't ask why - it wasn't me) in the "color" column there is an information about the item and it essentially should be called "description" A lot of code in the project depends on it and simply renaming the column name will take a tremendous amount of time.
Question: Is there a way to create some kind of pointer to that column and call it correctly so the sql below will work as expected:
select i.id, i.name, i.description from Item i
(it will know that when I type "description" it should look into "color" column.
Upvotes: 0
Views: 1864
Reputation: 23796
Short answer: no. Long answer: you could create insert and update triggers in Oracle that always keep those column in sync. But, the best thing to do would be to live with it, or rename it and fix your code. Having triggers and storing data in two columns just so your old code doesn't break, but lets your new code use the new column feels like an anti-pattern to me. Frankly, even if Oracle DID have what you were asking for out of the box it STILL feels like an anti pattern. As a developer I would be scratching my head with things like: "Let's see all the places where we ever select color
." Oops, you just missed all the places where you use description
instead. It seems VERY confusing to try and go this route. Again, I suggest living with it, or taking the time to update the project with the new correct name
Upvotes: 2
Reputation: 16389
This is called a column alias, the example is clunky
select BB from
(select column1 AA, column2 BB, column3 CCC from mytable);
Upvotes: 0
Reputation: 11209
You can create an updatable view with properly named column.
See https://msdn.microsoft.com/en-us/library/ms180800.aspx
Upvotes: 1