是这样,我的表是通过select语句查询出来的两个表;例如
select a,b,c from tb1;结果1
select a,b,c from tb2;结果2
如何将结果2追加到结果1的同名列下?我这个追加过程是在存储过程当中完成的,如果结果2有数据,就追加,没有数据只返回结果1就可以,请大家多多指教,谢谢
select a,b,c from tb1;结果1
select a,b,c from tb2;结果2
如何将结果2追加到结果1的同名列下?我这个追加过程是在存储过程当中完成的,如果结果2有数据,就追加,没有数据只返回结果1就可以,请大家多多指教,谢谢
union all
select a,b,c from tb2;
union all
select a,b,c from tb2);
楼主这是追加的查询结果 用union就可以
看你的问题 还以为是要往表里追加 这得用merge into
--将数据列相同的两个表中的数据追加到一个表下
create or replace procedure add_table is
begin
if exit(select 1 from tb2) then
insert into tb1 select * from tb2;
commit;
else
dbms_output('数据表tb2中无数据');
rollback;
end if;
end;
--执行过程
execute add_table;
--将数据列相同的两个表中的数据追加到一个表下
create or replace procedure add_table is
begin
if exit(select 1 from tb2) then
--此if条件还可以改进
insert into tb1 select * from tb2;
commit;
else
dbms_output.put('数据表tb2中无数据');
rollback;
end if;
end;
--执行过程
execute add_table;
cursor v_row_tbs2 is
select * from tbs2;
v_row v_row_tbs2%rowtype;
begin
open v_row_tbs2;
loop
fetch v_row_tbs2 into v_row;
if v_row_tbs2%notfound then
dbms_output.put_line('no data foune in tbs2 or insert over');
exit;
else
insert into tbs1 values(v_row.a,v_row.b,v_row.c);
end if;
end loop;
end;