Presumably, you want to do this for each column in the schema, not the database. Trying to do this with vocabulary tables would be a bad idea ...
declare v_schema varchar2(30) := 'YOUR_SCHEMA_NAME'; cursor cur_tables (p_schema_name varchar2) is select owner, table_name, column_name from all_tables at, inner join all_tab_columns atc on at.owner = atc.owner and at.table_name = atc.table_name where atc.data_type = 'VARCHAR2' and at.owner = p_schema; begin for r_table in cur_tables loop execute immediate 'update ' || r.owner || '.' || r.table_name || ' set ' || r.column_name || ' = trim(' || r.column_name ||');'; end loop; end;
This will only work for fields that are VARCHAR2s in the first place. If your database contains CHAR fields, you are out of luck, because CHAR fields are always filled to the maximum length.
Allan source share