Add temp column with default as trim of an existing column in Oracle SQL -
i trying add temporary column table in order fix leading , trailing spaces in original column.
original column values (excluding speech marks):
" john smith " " jay morgan "
temporary column values (excluding speech marks):
"john smith" "jay morgan"
sql:
alter table persons add t_full_name default trim(full_name);
however, not work. trying impossible?
this worked me (oracle 11g):
create table t2 (full_name varchar2(40)); insert t2 (full_name) values (' test '); select * t2; alter table t2 add (fu2 varchar2(40) (trim(full_name))); select * t2;
output
full_name fu2 test test
added after comment. if later want rename columns told, can following:
alter table t2 add fu3 varchar2(40); update t2 set fu3=fu2; alter table t2 drop column fu2; alter table t2 drop column full_name; alter table t2 rename column fu3 full_name;
or directly, if don't want intermediate checks:
update t2 set full_name=fu2; alter table t2 drop column fu2;
Comments
Post a Comment