create or replace procedure PROC_His_Table_Test(fromtablename in varchar2,totablename in varchar2,condtion in varchar2,otherpropertis in varchar2,otherpropertisValue in varchar2,excludeColumn in varchar2,returnMessage out varchar2)
as
table_column_name varchar2(2000):='';
table_sql varchar2(2000):='';
table_insert_sql varchar2(10000):='';
other_propertis varchar2(2000):='';
other_propertis_Value varchar2(2000):='';
begin
if length(otherpropertis)>0 then
other_propertis:=','||otherpropertis;
end if;
if length( otherpropertisValue)>0 then
other_propertis_Value:=','||otherpropertisValue;
end if;
if length( excludeColumn)>0 then
table_sql:='select wm_concat(COLUMN_NAME) from all_tab_columns where lower(table_name)=lower('''||fromtablename||''') and (lower(COLUMN_NAME) not in ('||excludeColumn||')) ';
else
table_sql:='select wm_concat(COLUMN_NAME) from all_tab_columns where lower(table_name)=lower('''||fromtablename||''') ';
end if;
Execute immediate table_sql into table_column_name;
table_insert_sql:='insert into '||totablename||' ('||table_column_name||other_propertis||') '
||' select '||table_column_name||other_propertis_Value||' from '
||fromtablename ||' where 1=1'||' and '||condtion;
Execute immediate table_insert_sql;
returnMessage:='';
EXCEPTION
WHEN OTHERS THEN
returnMessage:=sqlerrm||table_sql||table_insert_sql;
end;