I have an existing new table that has no columns yet. I want to copy all 10 columns in my old table. How do i do that? I don't want to drop the table so I could perform: create table newTable as select * from oldTable.
I don't want to drop the table so I could perform:
create table newTable as select * from oldTable.
Assuming your new table has at least 1 column BobC told you cannot have a table without any column, you can alter your table.
Alter new_table add (col1 varchar2(10)) , col2 ...);
Note that you need to mention all the column same as old table manually here.
If you don't want to do this manually then probably you would need a PLSQL block to do this.
CREATE OR REPLACE PROCEDURE creat_tbl_frm_tbl (tablname VARCHAR2)
AS
db_user VARCHAR2 (100) := USER;
TYPE t_rec IS RECORD
(
COLUMN_NAME VARCHAR2 (30 BYTE),
DATA_TYPE VARCHAR2 (106 BYTE),
DATA_LENGTH NUMBER
);
TYPE t_record IS TABLE OF t_rec;
-- initialization of record
v_record t_record := t_record ();
v_cntr NUMBER := 0;
v_status NUMBER;
sql_stmt VARCHAR2 (2000);
BEGIN
---dropping Already Existing temporary table
BEGIN
SELECT 1
INTO v_status
FROM all_objects
WHERE UPPER (object_name) = UPPER (tablname) AND owner = db_user;
--dbms_output.put_line( v_status );
IF v_status = 1
THEN
sql_stmt := 'drop table ' || tablname || '_new';
EXECUTE IMMEDIATE sql_stmt;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('Table not found--' || tablname);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (
'Error while dropping table-' || SQLCODE || SQLERRM);
END;
---------------------------------------------------------------------------
---- retrieving the columns of the table
BEGIN
SELECT column_name, data_type, data_length
BULK COLLECT INTO v_record
FROM all_tab_columns
WHERE table_name = UPPER (tablname)
ORDER BY column_id;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (
'Error while retrieving the column details-' || SQLCODE || SQLERRM);
END;
FOR i IN 1 .. v_record.COUNT
LOOP
v_cntr := v_cntr + 1;
IF v_cntr = 1
THEN
IF v_record (i).data_type = 'DATE'
OR UPPER (v_record (i).data_type) = 'TIMESTAMP(6)'
THEN
sql_stmt :=
'create table '
|| ' '
|| tablname
|| '_new'
|| '('
|| v_record (i).column_name
|| ' '
|| v_record (i).data_type
|| ')';
ELSE
sql_stmt :=
'create table '
|| ' '
|| tablname
|| '_new'
|| '('
|| v_record (i).column_name
|| ' '
|| v_record (i).data_type
|| '('
|| v_record (i).data_length
|| '))';
END IF;
--dbms_output.put_line(sql_stmt);
EXECUTE IMMEDIATE sql_stmt;
ELSE
IF v_record (i).data_type = 'DATE'
OR UPPER (v_record (i).data_type) = 'TIMESTAMP(6)'
THEN
sql_stmt :=
'alter table'
|| ' '
|| tablname
|| '_new'
|| ' '
|| 'add ('
|| v_record (i).column_name
|| ' '
|| v_record (i).data_type
|| ')';
ELSE
sql_stmt :=
'alter table'
|| ' '
|| tablname
|| '_new'
|| ' '
|| 'add ('
|| v_record (i).column_name
|| ' '
|| v_record (i).data_type
|| '('
|| v_record (i).data_length
|| '))';
END IF;
--dbms_output.put_line(sql_stmt);
EXECUTE IMMEDIATE sql_stmt;
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('Process Completed Successfully..!!');
END;
Output:
SQL> exec creat_tbl_frm_tbl('table2')
Process Completed Successfully..!!
PL/SQL procedure successfully completed.
SQL> select * from table2;
no rows selected
-- This is created with same columns as of passed table table2
SQL> select * from table2_new;
no rows selected
SELECT col1,col2,col3 --...
INTO newTable
FROM oldTable
Related
I have a database wherein there are multiple owners and some tables are empty.
Currently I want to sequentially execute the same fetch query against all non-empty tables of a specific owner.
I wrote the PL/SQL below, but got this error "ORA-06550: line 8, column 41: PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list 06550. 00000 - "line %s, column %s:\n%s".
DECLARE
CURSOR details IS
SELECT table_name
FROM all_tables
WHERE owner = 'emp' AND num_rows > 0;
myvar all_tables.table_name%TYPE;
rows_num NATURAL := 2;
sql_stmt VARCHAR2(1000);
BEGIN
OPEN details;
LOOP
FETCH details BULK COLLECT INTO myvar LIMIT rows_num;
END LOOP;
CLOSE details;
END;
How can I fix this?
edit: New code with SELECT included:
BEGIN
OPEN details;
LOOP
FETCH details INTO my_var;
EXIT WHEN myvar%NOTFOUND;
sql_stmt := 'SELECT * FROM ' || my_var|| ' WHERE ROWNUM <= :rows_num';
EXECUTE IMMEDIATE sql_stmt;
DBMS_OUTPUT.PUT_LINE(sql_stmt);
END LOOP;
CLOSE table_cur;
END;
No more errors now but I couldn't see anything in the Dbms output.
As P3CONSULTING said - declare TYPE of TABLE of CURSOR%ROWTYPE and then a variable that has type that newly declared TABLE OF type. Also please do not forget to add condition in loop to avoid infinite loop. Please try this code:
DECLARE
CURSOR details IS
SELECT table_name
FROM all_tables
WHERE owner = 'emp' AND num_rows > 0;
type t_var is table of details%rowtype;
myvar t_var;
rows NATURAL := 2;
BEGIN
OPEN details;
LOOP
FETCH details BULK COLLECT INTO myvar LIMIT rows;
EXIT WHEN myvar.count = 0;
END LOOP;
CLOSE details;
END;
The variable into which you "BULK COLLECT" must be a "TABLE OF..." not a single ROWTYPE.
If you do not need an output to be of specific format, then you may use dbms_xmlgen to execute dynamic SQL and serialize result into XML document.
Setup:
create table t0
as
select *
from user_tables
where 1=0
create table t1
as
select level as id
from dual
connect by level < 5
4 rows affected
create table t2
as
select *
from all_objects
where rownum = 1
1 rows affected
create table t3
as
select *
from all_source
where rownum < 5
4 rows affected
The query:
select * from (
select
owner, table_name
, dbms_xmlgen.getxml(
replace(replace (
'select * from "schema"."table" where rownum < 3'
, 'schema', owner)
, 'table', table_name
)
) as res
from all_tables
where owner = user
)
where res is not null
OWNER
TABLE_NAME
RES
FIDDLE_AIMBWFSLKTLDLGCECWIY
T1
<?xml version="1.0"?><ROWSET> <ROW> <ID>1</ID> </ROW> <ROW> <ID>2</ID> </ROW></ROWSET>
FIDDLE_AIMBWFSLKTLDLGCECWIY
T2
<?xml version="1.0"?><ROWSET> <ROW> <OWNER>SYS</OWNER> <OBJECT_NAME>ORA$BASE</OBJECT_NAME> <OBJECT_ID>134</OBJECT_ID> <OBJECT_TYPE>EDITION</OBJECT_TYPE> <CREATED>17-AUG-21</CREATED> <LAST_DDL_TIME>17-AUG-21</LAST_DDL_TIME> <TIMESTAMP>2021-08-17:23:05:16</TIMESTAMP> <STATUS>VALID</STATUS> <TEMPORARY>N</TEMPORARY> <GENERATED>N</GENERATED> <SECONDARY>N</SECONDARY> <NAMESPACE>64</NAMESPACE> <SHARING>NONE</SHARING> <ORACLE_MAINTAINED>Y</ORACLE_MAINTAINED> <APPLICATION>N</APPLICATION> <DUPLICATED>N</DUPLICATED> <SHARDED>N</SHARDED> <IMPORTED_OBJECT>N</IMPORTED_OBJECT> </ROW></ROWSET>
FIDDLE_AIMBWFSLKTLDLGCECWIY
T3
<?xml version="1.0"?><ROWSET> <ROW> <OWNER>SYS</OWNER> <NAME>STANDARD</NAME> <TYPE>PACKAGE</TYPE> <LINE>1</LINE> <TEXT>package STANDARD AUTHID CURRENT_USER is -- careful on this line; SED edit occurs!</TEXT> <ORIGIN_CON_ID>1</ORIGIN_CON_ID> </ROW> <ROW> <OWNER>SYS</OWNER> <NAME>STANDARD</NAME> <TYPE>PACKAGE</TYPE> <LINE>2</LINE> <TEXT></TEXT> <ORIGIN_CON_ID>1</ORIGIN_CON_ID> </ROW></ROWSET>
fiddle
Combining everything you need the below.Which satisfies all your requirements.The Sql fiddle here
DECLARE
CURSOR details IS
SELECT a.table_name, a.owner
FROM all_tables a
WHERE a.owner = user
AND a.num_rows > 0;
type t_var is table of details%rowtype;
myvar t_var;
rows1 NATURAL := 2;
v_plsql varchar2(32767);
i number := 0;
BEGIN
OPEN details;
LOOP
dbms_output.enable;
FETCH details BULK COLLECT
INTO myvar;
if NOT myvar.EXISTS(1) THEN
EXIT;
end if;
for i in myvar.first .. myvar.last loop
if NOT myvar.EXISTS(i) THEN
EXIT;
end if;
v_plsql := 'DECLARE ' || ' type rec_row is table of ' || myvar(i)
.table_name || '%rowtype; ' || 'l_row rec_row;' || 'BEGIN ' ||
' SELECT * ' || ' BULK COLLECT INTO l_row ' ||
' FROM ' || myvar(i).table_name || ' where rownum<=' ||
rows1 || ';' ||
' if l_row.EXISTS(1) then dbms_output.put_line(''' || i ||
' table and 1 row' || '''' || '); dbms_output.put_line(''';
for rec in (select a.*,
(select max(column_id)
from all_tab_cols a
where table_name = myvar(i).table_name) max_column
from all_tab_cols a
where table_name = myvar(i).table_name
order by column_id) loop
v_plsql := v_plsql || rec.column_name;
if rec.column_id <> rec.max_column then
v_plsql := v_plsql || ',';
end if;
end loop;
v_plsql := v_plsql || '''); dbms_output.put_line(';
for rec in (select a.*,
(select max(column_id)
from all_tab_cols a
where table_name = myvar(i).table_name) max_column
from all_tab_cols a
where table_name = myvar(i).table_name
order by column_id) loop
v_plsql := v_plsql || ' l_row(1).' || rec.column_name;
if rec.column_id <> rec.max_column then
v_plsql := v_plsql || '||'',''||';
end if;
end loop;
v_plsql := v_plsql || '); end if;';
v_plsql := v_plsql ||
'if l_row.EXISTS(2) then dbms_output.put_line(''' || i ||
' table and 2 row' || '''' || '); dbms_output.put_line(''';
for rec in (select a.*,
(select max(column_id)
from all_tab_cols a
where table_name = myvar(i).table_name) max_column
from all_tab_cols a
where table_name = myvar(i).table_name
order by column_id) loop
v_plsql := v_plsql || rec.column_name || '';
if rec.column_id <> rec.max_column then
v_plsql := v_plsql || ',';
end if;
end loop;
v_plsql := v_plsql || '''); dbms_output.put_line(';
for rec in (select a.*,
(select max(column_id)
from all_tab_cols a
where table_name = myvar(i).table_name) max_column
from all_tab_cols a
where table_name = myvar(i).table_name
order by column_id) loop
v_plsql := v_plsql || ' l_row(2).' || rec.column_name;
if rec.column_id <> rec.max_column then
v_plsql := v_plsql || '||'',''||';
end if;
end loop;
v_plsql := v_plsql || '); end if;';
v_plsql := v_plsql || ' end;';
--dbms_output.put_line(v_plsql);
execute immediate v_plsql;
end loop;
exit;
END LOOP;
CLOSE details;
END;
/
Let's assume following table:
drop table test1;
create table test1(
A number(10)
);
insert into test1 values (1);
insert into test1 values (10);
So as you can see table TEST1 is already populated. What i need to do is to change types of column A to varchar2. Since this column has values we can't just use following code:
alter table test1 modify A varchar2(10);
So i have wrote stored procedure which:
Renames column A to A1 ->
Then adds new column called A of type varchar2 ->
Then updates column A with values from column A1 ->
And ultimately drops old column A1.
Code which runs this process is following:
create or replace procedure change_col_type_to_varchar2(p_tab in varchar2, p_col in varchar2)
is
v_string clob;
cursor cur is
select column_name
from all_tab_columns
where table_name = upper(p_tab) and
column_name in (select regexp_substr(p_col,'[^,]+', 1, level) from dual
connect by regexp_substr(p_col, '[^,]+', 1, level) is not null);
begin
for i in cur loop
v_string := 'alter table ' || p_tab || ' rename column ' || i.column_name || ' to ' || i.column_name || '1' || ';';
dbms_lob.append(v_string,''||chr(10)||'');
dbms_lob.append(v_string, 'alter table ' || p_tab || ' add ' || i.column_name || ' varchar2(10);');
dbms_lob.append(v_string,''||chr(10)||'');
dbms_lob.append(v_string, 'update ' || p_tab || ' set ' || i.column_name || ' = ' || i.column_name || '1' || ';');
dbms_lob.append(v_string,''||chr(10)||'');
dbms_lob.append(v_string, 'alter table ' || p_tab || ' drop column ' || i.column_name || '1' || ';');
EXECUTE IMMEDIATE v_string;
DBMS_OUTPUT.PUT_LINE(v_string);
v_string := NULL;
end loop;
end;
I'am trying to apply this procedure to TEST1:
begin
change_col_type_to_varchar2('TEST1', 'A');
end;
And get error:
Error report -
ORA-23290: This operation may not be combined with any other operation
ORA-06512: at "YAVORSKYIY_DM.CHANGE_COL_TYPE_TO_VARCHAR2", line 19
ORA-06512: at "YAVORSKYIY_DM.CHANGE_COL_TYPE_TO_VARCHAR2", line 19
ORA-06512: at line 2
23290. 00000 - "This operation may not be combined with any other operation"
*Cause: ALTER TABLE RENAME COLUMN/CONSTRAINT operation was given in
conjunction with another ALTER TBALE Operation. This is not
allowed.
*Action: Ensure that RENAME COLUMN/CONSTRAINT is the only operation
specified in the ALTER TABLE.
But just typing :
alter table test1 rename column A to A1;
alter table test1 add A varchar2(100);
update test1 set A = A1;
alter table test1 drop column A1;
Works perfect.
Does anybody have any ideas about how to overcome this problem?
Appreciate your help.
the below will do what you asked for.
declare
procedure change_col_type_to_varchar2(p_tab in varchar2, p_col in varchar2)
is
v_string clob;
cursor cur is
select column_name
from all_tab_columns
where table_name = upper(p_tab) and
column_name in (select regexp_substr(p_col,'[^,]+', 1, level)
from dual
connect by regexp_substr(p_col, '[^,]+', 1, level) is not null);
begin
for i in cur loop
v_string := 'alter table ' || p_tab || ' rename column ' || i.column_name || ' to ' || i.column_name || '1';
execute immediate v_string;
v_string := 'alter table ' || p_tab || ' add ' || i.column_name || ' varchar2(10)';
execute immediate v_string;
v_string := 'update ' || p_tab || ' set ' || i.column_name || ' = ' || i.column_name || '1' ;
execute immediate v_string;
v_string := 'alter table ' || p_tab || ' drop column ' || i.column_name || '1' ;
execute immediate v_string;
v_string := NULL;
end loop;
end;
begin
DBMS_OUTPUT.PUT_LINE('Before calling');
change_col_type_to_varchar2('TEST1','A');
DBMS_OUTPUT.PUT_LINE('After calling');
end;
Well, execute each statement alone, instead of concatenating them. And you don't need LOBs, varchar2 for each one should be enough.
I propose other algorithm.
create new table 'table2' with varchar column;
select all values from table1.A and insert to table2 with to_char() conversion;
drop table1;
rename table2 to table1;
profit!
DECLARE
CURSOR c_ddy (p_table_name VARCHAR2, p_table_name_2 VARCHAR2)
IS
(SELECT column_name
FROM ( SELECT column_name
FROM user_tab_columns
WHERE table_name = p_table_name
ORDER BY column_name));
TYPE t_content IS TABLE OF VARCHAR2 (9000)
INDEX BY BINARY_INTEGER;
a_content t_content;
l_sql VARCHAR2 (1000);
BEGIN
FOR r_ddy IN c_ddy ('TABLE_a', 'TABLE_B')
LOOP
l_sql :=
'SELECT '
|| r_ddy.column_name
|| ' FROM TABLE_A '
|| 'MINUS'
|| 'SELECT '
|| r_ddy.column_name
|| 'FROM TABLE_B';
EXECUTE IMMEDIATE l_sql BULK COLLECT INTO a_content;
DBMS_OUTPUT.put_line (l_sql);
END LOOP;
END;
Trying to output every column in TABLE_A minus every column in TABLE_B.
A space is missing in the SQL string.
Try this:
l_sql :=
'SELECT '
|| r_ddy.column_name
|| ' FROM TABLE_A '
|| ' MINUS '
|| ' SELECT '
|| r_ddy.column_name
|| ' FROM TABLE_B';
UPD: For some reason the spaces were gone before. Now I put them again.
Can you tell me what is wrong with this procedure that I'm trying to create?
CREATE OR REPLACE PROCEDURE create_audit_tables (table_owner VARCHAR2)
IS
CURSOR c_tables (
table_owner VARCHAR2)
IS
SELECT ot.owner AS owner, ot.table_name AS table_name
FROM all_tables ot
WHERE ot.owner = table_owner
AND ot.table_name NOT LIKE 'AUDIT_%'
AND ot.table_name <> 'EXAUDIT'
AND NOT EXISTS
(SELECT 1
FROM EXAUDIT efa
WHERE ot.table_name = efa.tname)
AND NOT EXISTS
(SELECT 1
FROM all_tables at
WHERE at.table_name = 'AUDIT_'||ot.table_name);
v_sql VARCHAR2 (8000);
v_count NUMBER := 0;
v_aud VARCHAR2 (30);
BEGIN
FOR r_table IN c_tables (table_owner)
LOOP
BEGIN
v_aud := 'AUDIT_'||r_table.table_name;
v_sql :=
'create table '
|| v_aud
|| ' as select * from '
|| r_table.owner
|| '.'
|| r_table.table_name
|| ' where 1 = 1';
DBMS_OUTPUT.put_line ('Info: ' || v_sql);
EXECUTE IMMEDIATE v_sql;
v_sql :=
'alter table '
|| v_aud
|| ' add ( AUDIT_ACTION char(1), AUDIT_BY varchar2(50), AUDIT_AT TIMESTAMP)';
EXECUTE IMMEDIATE v_sql;
v_count := c_tables%ROWCOUNT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (
'Failed to create table '
|| v_aud
|| ' due to '
|| SQLERRM);
END;
END LOOP;
IF v_count = 0
THEN
DBMS_OUTPUT.put_line ('No audit tables created');
ELSE
DBMS_OUTPUT.put_line (v_count || ' audit tables created.');
END IF;
END;
/
I checked it with show errors function and it gave me this:
LINE/COL ERROR
-------- --------------------------------------------
6/1 PL/SQL: SQL Statement ignored
16/3 PL/SQL: ORA-00906: missing left parenthesis
Perhaps the problem is quite simple, but I can't see it, so please help me if you can
I can compile procedure without problems after creating table
create table EXAUDIT (tname varchar2(100));
Check status of procedure:
select status from user_objects where lower(object_name) = 'create_audit_tables';
This is first my stint with procedure and I am trying to execute below oracle procedure but facing some issue. Any inputs on this would be really helpful:
Issue:-----
I have a select query that returns two values:
src_Columns contains:
ID_ELEMENT
ID_ELEMENT_SA
Now, When I am trying to travesre a select-query(single column) result using "For Loop", I am not getting the values of the column rather I am getting its name only.
FOR columnItem IN (SELECT src_Columns FROM ELEM90_LNK_ELEM_BOSE)
LOOP
dbms_output.put_line('src_Columns 3: ' || columnItem.src_Columns);
query_test:= 'insert into ' || destination_Table || '(NAME,' || dest_Columns_Value || ') VALUES( ''' || src_name_Value || ''',''' || columnItem.dummyValue || ''')';
dbms_output.put_line('query_test:' || query_test);
execute immediate query_test;
END LOOP;
I mean the test query generated is following when i use variable name(src_columns):
insert into ATT_WTPART(NAME,STRINGVALUE) VALUES( 'ID_ELEMENT_SA','ID_ELEMENT_SA')
whereas if I use ID_ELEMENT_SA instead of src_Columns in FOR LOOP
FOR columnItem IN (SELECT ID_ELEMENT FROM ELEM90_LNK_ELEM_BOSE)
then I get proper values that are desired like
insert into ATT_WTPART(NAME,STRINGVALUE) VALUES( 'ID_ELEMENT_SA','ID05')
How can I make sure that I get the values even when I am using the variable name instead of any hard-coding
Below is the Complete Procedure:-------------
create or replace
PROCEDURE ELEM90_Lnk_Elem_ATT_WTPART_MK
AS
CURSOR targ_dest_relation IS
SELECT sourcecolumn FROM mapping where destinationtable='ATT_WTPART';
BEGIN
DECLARE
dest_Columns varchar2(1000);
src_Columns varchar2(1000);
src_Type varchar2(1000);
destination_Table varchar2(1000) := 'ATT_WTPART';
source_Table varchar2(1000) := 'ELEM90_LNK_ELEM_BOSE';
query_test varchar2(1000);
query_test2 varchar2(1000);
src_name varchar2(255);
src_Type_Value varchar2(255);
dest_Columns_Value varchar2(255);
src_name_Value varchar2(255);
for_query varchar2(1000);
for_query_data varchar2(1000);
dummyValue varchar2(1000);
BEGIN
FOR rec IN targ_dest_relation loop
dbms_output.put_line('destination_Table: ' || destination_Table);
dbms_output.put_line('source_Table: ' || source_Table);
src_Columns := rec.sourcecolumn;
dbms_output.put_line('src_Columns: ' || src_Columns);
src_Type := 'select data_type from user_tab_columns where table_name ='''||source_Table||'''and column_name='''|| src_Columns ||'''';
dbms_output.put_line('src_Type: ' || src_Type);
execute immediate src_Type INTO src_Type_Value;
dbms_output.put_line('src_Type_Value: ' || src_Type_Value);
dest_Columns := 'select DEST_COLUMN from ATT_PART_MAPPING where SOURCETYPE='''|| src_Type_Value || '''';
dbms_output.put_line('dest_Columns: ' || dest_Columns);
execute immediate dest_Columns INTO dest_Columns_Value;
dbms_output.put_line('dest_Columns_Value: ' || dest_Columns_Value);
src_name := 'select column_name from user_tab_columns where table_name ='''|| source_Table ||''' and column_name= ''' || src_Columns || '''';
dbms_output.put_line('src_name: ' || src_name);
execute immediate src_name INTO src_name_Value;
dbms_output.put_line('src_name_Value: ' || src_name_Value);
FOR columnItem IN (SELECT src_Columns FROM ELEM90_LNK_ELEM_BOSE)
LOOP
dbms_output.put_line('src_Columns 3: ' || columnItem.src_Columns);
query_test:= 'insert into ' || destination_Table || '(NAME,' || dest_Columns_Value || ') VALUES( ''' || src_name_Value || ''',''' || columnItem.dummyValue || ''')';
dbms_output.put_line('query_test:' || query_test);
execute immediate query_test;
END LOOP;
END loop;
END;
END;
The problem with the line
FOR columnItem IN (SELECT src_Columns FROM ELEM90_LNK_ELEM_BOSE)
is that src_Columns is a local variable. As a result, you end up selecting the same value for each row in ELEM90_LNK_ELEM_BOSE.
If you want the value of the local variable to be used as a column name in the query, you must use dynamic SQL instead. Try replacing FOR columnItem ... LOOP ... END LOOP with the following:
OPEN curs FOR 'SELECT ' || src_Columns || ' FROM ELEM90_LNK_ELEM_BOSE';
LOOP
FETCH curs INTO column_value;
EXIT WHEN curs%NOTFOUND;
dbms_output.put_line('src_Columns 3: ' || column_value);
query_test:= 'insert into ' || destination_Table || '(NAME,' || dest_Columns_Value || ') VALUES( ''' || src_name_Value || ''',''' || column_value || ''')';
dbms_output.put_line('query_test:' || query_test);
execute immediate query_test;
END LOOP;
CLOSE curs;
You will need to declare the following extra variables:
curs SYS_REFCURSOR;
column_value VARCHAR2(4000);
However, in truth it would probably be better to remove the loop entirely. You can replace it with an INSERT INTO ... SELECT ... FROM ... statement instead, such as the following:
EXECUTE IMMEDIATE 'INSERT INTO ' || destination_Table || ' (NAME,' ||
dest_Columns_Value || ') SELECT :name,' || src_Columns ||
' FROM ELEM90_LNK_ELEM_BOSE' USING src_name_Value;
This also gets rid of the need for the two local variables curs and column_value, and is also likely to be considerably faster, as there's no need to parse dynamic SQL once for each row in the destination table.
Is it working better if you try this one:
query_test:= 'insert into ' || destination_Table ||
'(NAME,'||dest_Columns_Value||') VALUES (:p1, :p2)';
execute immediate query_test USING src_name_Value, columnItem.dummyValue;
At least it should have a positive impact on performance.