%TYPE is available only in PL / SQL and can only be used in the declaration section . Thus, you cannot do what you are trying.
You might think you could declare your own PL / SQL (sub) type and use this in a statement:
declare subtype my_type is t1.v%type; begin insert into t1 select cast(v as my_type) from t2; end; /
... but that won't work either, because cast() is a non-PL / SQL SQL function and only recognizes data collection types at assembly and schema level; and you cannot create an SQL type using %TYPE .
As a nasty hack, you can do something like:
insert into t1 select substr(v, 1, select data_length from user_tab_columns where table_name = 'T1' and column_name = 'V') from t2;
Which would be a bit more acceptable if you could keep this length in a variable - a replacement or binding in SQL * Plus or a local variable in PL / SQL. For example, if this is a simple SQL update through SQL * Plus, you can use the bind variable:
var t1_v_len number; begin select data_length into :t1_v_len from user_tab_columns where table_name = 'T1' and column_name = 'V'; end; / insert into t1 select substr(v, 1, :t1_v_len) from t2;
Something similar can be done in other settings, it depends on where the insertion is performed.
source share