Time taken to modify a column datatype [message #443179] |
Sat, 13 February 2010 06:01 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
Hello,
I have a table with some 50 columns out of which I need to modify the datatype for two columns which happen to be empty. But the table has data in other columns (around 191 lakh rows) I gave an ALTER TABLE table_name modify column_name column_datatype query. But it seems to be taking forver to execute. I tried the same with a table with 5000 rows & it got done quickly.
My question is , the more the data in The table, would the time taken to alter a column datatype be more ???
Thanks in advance!
|
|
|
|
|
Re: Time taken to modify a column datatype [message #443241 is a reply to message #443191] |
Sat, 13 February 2010 22:44 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
Michel Cadot wrote on Sat, 13 February 2010 20:35Quote:My question is , the more the data in The table, would the time taken to alter a column datatype be more
It depends on on the current datatype and the type of modification (increase, decrease, change datatype...).
Regards
Michel
Hey michel,
Am trying to change a column of data type DATE to VARCHAR2( 8 )
The version is Oracle 9i installed in a UNIX environment & am using SQL Navigator to run The queries. So when am attempting the above in a table with 191 lac rows , with the column in question being empty , would it take a long time ?? The query just says processing...
Thanks,
Ayesha
|
|
|
|
|
|
|
Re: Time taken to modify a column datatype [message #443268 is a reply to message #443267] |
Sun, 14 February 2010 11:40 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
BlackSwan wrote on Sun, 14 February 2010 22:58>Now my point is why is it taking so long to get modified ?
Post Operating System (OS) name & version for DB server system.
Post results of
SELECT * from v$version
Is DB actively making changes?
Or is DB "hung" & just sitting idle.
Hey I have posted the version above, taht is all the info I know. See the query executed finally after an hour. But I just wanted to know why it takles long just to alter a datatype !!!
|
|
|
|
|
Re: Time taken to modify a column datatype [message #443274 is a reply to message #443266] |
Sun, 14 February 2010 12:24 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote: I know that we cannot change the datatype when a column has data.
How could we know that you know it?
Quote:Now my point is why is it taking so long to get modified ? Is that expected ? If yes, why ? The syntax & everything else is fine..
1/ Why don't you post what you did as asked instead of blablabla?
2/ How do you think Oracle knows there is no value in the column?
Regards
Michel
[Updated on: Sun, 14 February 2010 12:28] Report message to a moderator
|
|
|
|
Re: Time taken to modify a column datatype [message #443276 is a reply to message #443275] |
Sun, 14 February 2010 12:55 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
Actually, what I meant to suggest was NOT to convert a DATE column into a CHARACTER one, but alter a table and add another (character) column and insert values from date datatype column in there. Something likeSQL> desc this_table;
Name Null? Type
----------------------------------------- -------- ------------------------
EMPNO NOT NULL NUMBER(4)
DATE_COLUMN DATE
SQL> select * from this_table;
EMPNO DATE_COLUM
---------- ----------
7788 09.12.1982
7876 12.01.1983
7934 23.01.1982
SQL> alter table this_table add char_column varchar2(8);
Table altered.
SQL> update this_table set char_column = to_char(date_column, 'ddmmyyyy');
3 rows updated.
SQL> select * From this_table;
EMPNO DATE_COLUM CHAR_COL
---------- ---------- --------
7788 09.12.1982 09121982
7876 12.01.1983 12011983
7934 23.01.1982 23011982
SQL> alter table this_table drop column date_column;
Table altered.
SQL> alter table this_table rename column char_column to date_column;
Table altered.
SQL> select * from this_table;
EMPNO DATE_COL
---------- --------
7788 09121982
7876 12011983
7934 23011982
SQL> desc this_table;
Name Null? Type
----------------------------------------- -------- ------------------------
EMPNO NOT NULL NUMBER(4)
DATE_COLUMN VARCHAR2(8)
SQL>
If it were me (I wouldn't do it at all, but OK ...), I'd avoid the last two steps (dropping the original column above all!) because - sooner or later - the OP might be back with another question, having problems with date arithmetic, invalid month values, etc. etc. (shortly, anything you can think of when storing dates into character columns).
As you guessed my thoughts right, this smells like a stupid idea, but we can't be sure until the OP explains the reason - maybe it is absolutely legitimate.
|
|
|
|
|
Re: Time taken to modify a column datatype [message #443337 is a reply to message #443334] |
Mon, 15 February 2010 03:33 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:The business requires it to be varchar2( 8 ) .
No, the business does NOT require that.
It requires that something represents a date, it does NOT require it is VARCHAR2(8). Business does not care of implementation, it just wants feature.
Quote:1/ Why don't you post what you did as asked instead of blablabla?
2/ How do you think Oracle knows there is no value in the column?
Please post what is asked, answer questions that are asked.
Regards
Michel
[edited by LF: disabled smilies]
[Updated on: Mon, 15 February 2010 07:31] by Moderator Report message to a moderator
|
|
|
Re: Time taken to modify a column datatype [message #443339 is a reply to message #443274] |
Mon, 15 February 2010 03:39 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
Michel Cadot wrote on Sun, 14 February 2010 23:54Quote: I know that we cannot change the datatype when a column has data.
How could we know that you know it?
Quote:Now my point is why is it taking so long to get modified ? Is that expected ? If yes, why ? The syntax & everything else is fine..
1/ Why don't you post what you did as asked instead of blablabla?
2/ How do you think Oracle knows there is no value in the column?
Regards
Michel
> How do you think Oracle knows there is no value in the column?
How do you expect me to know what oracle knows !! I am just saying from the error thrown from queries like the one u posted above!
Michel , there is no necessity whatsoever to be rude OK. Now that i think about it, I can do without your sarcasm or your solutions ! Thanks !!!
|
|
|
Re: Time taken to modify a column datatype [message #443341 is a reply to message #443337] |
Mon, 15 February 2010 03:49 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
Michel Cadot wrote on Mon, 15 February 2010 15:03Quote:The business requires it to be varchar2( 8 ) .
No, the business does NOT require that.
It requires that something represents a date, it does NOT require it is VARCHAR2(. Business does not care of implementation, it just wants feature.
Quote:1/ Why don't you post what you did as asked instead of blablabla?
2/ How do you think Oracle knows there is no value in the column?
Please post what is asked, answer questions that are asked.
Regards
Michel
How do u know what my business requires? Don't you think we are digressing away from the issue ? why it has to be changed is irrelevant ! Am sorry I even joined this forum in the first place ! If I knew there were going to be people like you to put junior members down , I would have NEVER joined.
You please answer what is asked , do not speak irrelevant things
[Updated on: Mon, 15 February 2010 03:49] Report message to a moderator
|
|
|
Re: Time taken to modify a column datatype [message #443344 is a reply to message #443341] |
Mon, 15 February 2010 03:56 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
1/ Oracle must scan ALL blocks to know if a column has a value => more blocks, more time.
2/ Do not attack us because we give you advices. Remember that we are trying to help in the best way. Take care that if you insult us the only result will be that you will no more get help.
3/ A developer is also a person that is able to think and MUST feedback to a requirement that seems to be wrong.
Regards
Michel
[Updated on: Mon, 15 February 2010 03:58] Report message to a moderator
|
|
|
Re: Time taken to modify a column datatype [message #443346 is a reply to message #443344] |
Mon, 15 February 2010 04:06 |
dancingdaisies
Messages: 9 Registered: February 2010
|
Junior Member |
|
|
Michel Cadot wrote on Mon, 15 February 2010 15:261/ Oracle must scan ALL blocks to know if a column has a value => more blocks, more time.
2/ Do not attack us because we give you advices. Remember that we are trying to help in the best way. Take care that if you insult us the only result will be that you will no more get help.
3/ A developer is also a person that is able to think and MUST feedback to a requirement that seems to be wrong.
Regards
Michel
Advice could be given in the right way rather than blending it with sarcasm & rudeness. I honestly did not think what you gave was Advice. Was more like a mockery. And please do not say that I attacked YOU ! I merely responded to your queries & I do not think i insulted anyone. If I did , i did not intend to.
I was just trying to learn why something is happening and is there any logical reason behind that. But now that urge to learn also disappeared, seeing the reception in this forum .
I have been part of various forums & have given advice & answers to the silliest of questions -- because people learn only when they ask. But am sorry to say that, never have I seen such sarcasm & bullying in any forum.
[Updated on: Mon, 15 February 2010 04:07] Report message to a moderator
|
|
|
Re: Time taken to modify a column datatype [message #443374 is a reply to message #443179] |
Mon, 15 February 2010 06:19 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
@dancingdasies - despite the unfortunate tone of this thread there is a lot of good advice here on how to work out what your problem is.
Changing the datatype of an empty column in oracle should be very fast, and we can't think of any reason why it wouldn't be.
The size of the table should make some difference but not that much. (Michel I know what you mean about scanning the blocks but I just knocked up a 1.5 million row table and tried it - took 2 seconds).
The only way to know for sure what the issue is is to run a sql trace and look at the trace file. Blackswan asked you to do this earlier.
It could be a bug in your specific version of oracle, which is why we asked you for the full version number. Blackswan also gave you the query to get this - select * from v$version.
As for the comments about this not being a good idea - I'm with the others, it's never a good idea to store dates in a varchar.
I don't know who has told you to do this or why but at the end of the day business users are only ever interested in getting the right answer efficiently.
Storing dates in varchars makes that unnecessarily hard.
Oracle has all sorts of algorithms to allow it to efficiently scan dates in queries, but it'll only use them if you tell it the data is a date type.
And of course using a varchar allows people to store invalid dates, which'll mean you spend a lot of time writing code to cope with invalid dates when you really shouldn't need to.
We go on about this simply because we see a lot of questions on this site and others where people are having problems caused by these two issues and our recommendation every time is to store dates in date columns.
So if I were you I'd work out why someone wants this date stored as a varchar and see if there is another way to achieve whatever they need will keeping the data in a date column.
|
|
|
|
|
Re: Time taken to modify a column datatype [message #443388 is a reply to message #443341] |
Mon, 15 February 2010 07:58 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
dancingdaisies wrote on Mon, 15 February 2010 04:49Michel Cadot wrote on Mon, 15 February 2010 15:03Quote:The business requires it to be varchar2( 8 ) .
No, the business does NOT require that.
It requires that something represents a date, it does NOT require it is VARCHAR2(. Business does not care of implementation, it just wants feature.
Quote:1/ Why don't you post what you did as asked instead of blablabla?
2/ How do you think Oracle knows there is no value in the column?
Please post what is asked, answer questions that are asked.
Regards
Michel
How do u know what my business requires? Don't you think we are digressing away from the issue ? why it has to be changed is irrelevant ! Am sorry I even joined this forum in the first place ! If I knew there were going to be people like you to put junior members down , I would have NEVER joined.
You please answer what is asked , do not speak irrelevant things
I just wanted to jump in here in a nice way, really.
A business will not ask to use a VARCHAR2 column instead of a DATE. They should have no idea how a database is storing data.
They will ask for something like "give me the monthly totals" and not "give me the monthly totals but you have to use loops instead of any analytic functions."
If a manager is asking you this then they are telling you how to do your job. See how they feel if you tell them how to do their job.
[Updated on: Mon, 15 February 2010 08:01] Report message to a moderator
|
|
|