sql 存储过称 循环

来源:百度知道 编辑:UC知道 时间:2024/09/24 11:28:48
我在存储过程中
SELECT a FROM T_A
这个a字段出来的数据有很多条
我想将每一条数据INSERT到T_B表中的b字段去
不知道怎样写?

T_A
a
1
2
3
4
5
T_B
b
我想把从T_A表中查出来的1,2,3,4,5分别插到T_B表中
T_B
b
1
2
3
4
5

为什么要用存储过程呢?就一个语句啊
select a into T_B from T_A order by a

declare
cursor T_cursor is SELECT a FROM T_A ; --定义个游标
T_a T_A.a%type ;

begin
open T_cursor ;

loop --循环
fetch T_cursor into T_a ;
exit when T_cursor%notfound ;
insert into T_B(b)values(T_a);
end loop ;

close T_cursor ;
comit ;
end ;

insert into T_B (b) select A from t_A

insert into T_B select from T_A;