What command did you use to rename the column?
Printable View
What command did you use to rename the column?
Here it is. I got this long time ago from DBA Consultant and I use it many times before.
___________________________________________________________________
procedure chg_colnm(user in varchar2, -- name of the schema.
table_name in varchar2, -- name of the table.
old_name in varchar2, -- name of the column to be renamed.
new_name in varchar2 -- new name of the column.
) as
id number;
col_id number;
cursor_name1 INTEGER;
cursor_name2 INTEGER;
ret1 INTEGER;
ret2 INTEGER;
begin
select object_id into id from dba_objects where
object_name=UPPER(table_name)
and owner=UPPER(user) and object_type='TABLE';
select col# into col_id from col$ where obj#=id and
name=UPPER(old_name);
update col$ set name=UPPER(new_name)
where obj#=id and col#=col_id;
commit;
cursor_name1 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_name1, 'ALTER SYSTEM FLUSH SHARED_POOL',DBMS_SQL.native);
ret1 := DBMS_SQL.EXECUTE(cursor_name1);
DBMS_SQL.CLOSE_CURSOR(cursor_name1);
cursor_name2:= DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_name2, 'ALTER SYSTEM CHECKPOINT',DBMS_SQL.native);
ret2:= DBMS_SQL.EXECUTE(cursor_name2);
DBMS_SQL.CLOSE_CURSOR(cursor_name2);
END;
I wouldn't use that proecedure, it could corrupt you database. It was probably written for an older version of Oracle and isn't valid for the current version.
You should do this!
ALTER TABLE CUSTOMER_SITES
RENAME COLUMN oldname TO SITE_PRIM_DATA_SOURCE;
Try that command before you do anything else,
and throw away that code.
I am getting following error
ORA-14155 Missing PARTITION OR SUBPARTITION KEYWORD
We have Oracle 8i
Would this command works in this version?
you just lost your support by updating system data dictionary
What do you mean. Could you explain it to me.
you are not allowed to update data dictionary
Ok. Do you know what I can do to fix it. Because I will need to make some changes in future.
Thanks for help!
First you need to undo the changes you made to the data dictionary. You might have to run that same program again to change the new column name back to the old column name. I don't think that you can directly rename a column in 8i. You will need to create a temporary table and when you do that you rename the column.
1) CREATE tmp AS SELECT col1, col2, col3 new_name from old_table;
2) Make sure that all of the data exists in the new table.
3) drop table old_table;
4) rename table tmp to old_table;
5) add back the indexes and constraints, including foreign keys.
You need to do this when no one is using the database. Once you repair the damage that your procedure caused, you should do a backup.
And then throw away that procedure.
You can directly rename a column in 9i.