日期:2014-05-17  浏览次数:20972 次

求助用存储过程为表循环增加字段??
我写的存储过程如下:
create or replace procedure project_temp as
 v_exe_sql varchar2(200);
 vnumber number;
 gnum number;
  begin
  begin
  gnum :=0;
  vnumber :=1;
  for vnumber in 1..50 loop  
  gnum := gnum+1;
  begin
  v_exe_sql:='alter table temp_ras_project add 偿'||gnum||'number';
  execute immediate v_exe_sql; 
  end;
  end loop;  
  end;
end project_temp;

这个存储过程的用途是为表temp_ras_project增加50个字段不知道存储过程能不能实现,编译没有错误,但是执行就报错了。
请高手给予指点。

------解决方案--------------------
create or replace procedure project_temp as
 v_exe_sql varchar2(200);
 vnumber number;
 gnum number;
begin
begin
gnum :=0;
vnumber :=1;
for vnumber in 1..50 loop
gnum := gnum+1;
begin
v_exe_sql:='alter table temp_ras_project add 偿'||gnum||' number';
execute immediate v_exe_sql;
end;
end loop;
end;
end project_temp;


加个空格
------解决方案--------------------
SQL code

create or replace procedure project_temp as
 v_exe_sql varchar2(200);
 vnumber number;
 gnum number;
  begin
  begin
  gnum :=0;
  vnumber :=1;
  for vnumber in 1..50 loop  
  gnum := gnum+1;
  begin
  v_exe_sql:='alter table temp_ras_project add 偿'[color=#FF0000]||gnum||'  number'[/color];
  execute immediate v_exe_sql; 
  end;
  end loop;  
  end;
end project_temp;