I have two tables which one is created from the data of the other fields:
CREATE TABLE1(
CAMPO1 VARCHAR2(15),
CAMPO2 VARCHAR2(15),
CAMPO3 VARCHAR2(5),
CAMPO4 VARCHAR(20));
CREATE TABLE2(
CAMPO1 VARCHAR(20),
CAMPO2 VARCHAR(30));
I want to insert table 1, table 1 in the following way:
- table1.field1 inside table2.field1
- table1.field2, table1.field3 and table1.field4 within table2.field2.
The problem is that table2.field2 only accepts 30 characters (and I can not directly alter with alter table the size of this field since I can not modify the table) and I want to put 40. I found a way to solve-it and is with dynamic querys:
querySql in varchar2;
queryInsert in varchar2;
queryValues in varchar2;
queryValuesTab1 in varchar2;
queryValuesTab2 in varchar2;
queryInsert := 'INSERT INTO TABLE2(campo1,campo2)';
queryValuesTab1 := 'SELECT campo1, campo2||campo3 from TABLE1';
queryValuesTab2 := 'SELECT campo1, campo4 from TABLE1';
v_num_reg in number := 1;
queryValues := queryValuesTab1;
querySql := queryInsert || ' ' || queryValues;
execute immediate querysql;
rc := sql%rowcount;
v_num_reg in number := 2;
queryValues := queryValuesTab2;
querySql := queryInsert || ' ' || queryValues;
execute immediate querysql;
rc := sql%rowcount;
Now the next step I would like to make would be to consult table2. The problem is that when the data has been entered in table2.field2 these have been entered segmented. How can I recover all this data (the 40 characters) and not just the 30 characters accepted by table2.field2?
Many thanks !!!