It depends a bit on what you want to accomplish. This works:
select substr(column4, 0, 5), t1.* from sometable t1;
However, it returns column4 twice. Once with 5 characters (use length as in the other answers if you want to discard the last 5 rather than using a fixed length, not clear what your goal is) and once with all characters.
You could also generate the SQL with PL/SQL using user_tab_columns. If you just want to save yourself some typing something like this might work:
declare
v_sql varchar2(1024) := null;
begin
for rec in (select column_name, table_name from user_tab_columns
where table_name = 'TEST1') loop
if v_sql is null then
v_sql := 'select ';
else
v_sql := v_sql || ',';
end if;
if rec.column_name = 'C2' then
v_sql := v_sql || ' substr(' || rec.table_name || '.c2, 0, 5)';
else
v_sql := v_sql || rec.table_name || '.' || rec.column_name;
end if;
end loop;
v_sql := v_sql || ' from test1';
dbms_output.put_line(v_sql);
end;
/
No points for code style, but it works and prints the SQL. Add more special cases if you need to truncate multiple columns and add the other tables as needed.