写了个存储过程,编译的时候通过了,执行的时候报错 提示execute immediate语句无效
createorreplaceprocedurepro_tiscursorcisselecttable_namefromuser_all_tableswheretable...
create or replace procedure pro_t is cursor c is select table_name from user_all_tables where table_name in (select table_name from user_tab_columns where column_name = 'POSITION_ID'); tablename varchar2(100); strinsert varchar2(1000);
begin open c; loop fetch c into tablename; strinsert:= 'update' || tablename || 'set POSITION_ID =' || 1 ;execute immediate strinsert;
end loop; commit; close c;end; 展开
begin open c; loop fetch c into tablename; strinsert:= 'update' || tablename || 'set POSITION_ID =' || 1 ;execute immediate strinsert;
end loop; commit; close c;end; 展开
1个回答
展开全部
create or replace procedure pro_t is
cursor c is
select table_name
from user_all_tables
where table_name in (select table_name
from user_tab_columns
where column_name = 'POSITION_ID');
tablename varchar2(100);
strinsert varchar2(1000);
begin
open c;
loop
fetch c
into tablename;
exit when c%notfound;--你之前没有循环退出条件
strinsert:= 'update '|| tablename ||' set POSITION_ID =1' ;--之前sql语句拼的有问题
execute immediate strinsert;
end loop;
commit;
close c;
end;
cursor c is
select table_name
from user_all_tables
where table_name in (select table_name
from user_tab_columns
where column_name = 'POSITION_ID');
tablename varchar2(100);
strinsert varchar2(1000);
begin
open c;
loop
fetch c
into tablename;
exit when c%notfound;--你之前没有循环退出条件
strinsert:= 'update '|| tablename ||' set POSITION_ID =1' ;--之前sql语句拼的有问题
execute immediate strinsert;
end loop;
commit;
close c;
end;
更多追问追答
追问
你好 我想再更新个字段该怎么写? 前面条件都一样 想strinsert := 'update ' || tablename || ' set POSITION_ID =1 and POSITION_NAME = 新院区';就是同时也更新position_name这个字段 我这样写法是报错的 麻烦说清楚好不
追答
strinsert := 'update ' || tablename || ' set POSITION_ID =1 and POSITION_NAME = ''新院区''';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询