第一个问题的语句 declare type dbcur is ref cursor; dbcursor3 dbcur; strdbcursor3 varchar2(5000); begin open dbcursor3 for 'select '||strTemp||' from '||strdbcursor1; fetch dbcursor3 into strdbcursor3; while dbcursor3%found loop recNum:=recNum+1; insert into testmis.zindex_info (dbbm,flbm,bbm,nr) values ('FXHY','FXHY_NULL',strdbcursor1,strdbcursor3); fetch dbcursor3 into strdbcursor3; end loop; close dbcursor3; end;第二个问题的语句 while dbcursor2%found loop
if strTemp is null then strTemp:=strdbcursor2; else strTemp:=strTemp||'||'' ''|| '||strdbcursor2; end if; fetch dbcursor2 into strdbcursor2; end loop; close dbcursor2; end; execute immediate 'insert into testmis.zindex_info(dbbm,flbm,bbm,nr) '|| 'select ''FXHY'',''FXHY_NULL'','''||strdbcursor1||''','||strTemp||' from '||strdbcursor1 fetch dbcursor1 into strdbcursor1; end loop;
1. open dbcursor3 for 'select '||strTemp||' from '||strdbcursor1; 这样肯定不行,存储过程中游标不能这样使用 2.strdbcursor3 varchar2(4000); ---varchar2最大到4000,超过了用clob或者long
應該是組合語句的問題,你用dbms_output 將'select '||strTemp||' from '||strdbcursor1; 輸出看看是否正確?我有試過,可以這樣組合的
我试过了,我将將'select '||strTemp||' from '||strdbcursor1; 插入一个表中,形成select 语句,都是正确的
declare
type dbcur is ref cursor;
dbcursor3 dbcur;
strdbcursor3 varchar2(5000);
begin
open dbcursor3 for 'select '||strTemp||' from '||strdbcursor1;
fetch dbcursor3 into strdbcursor3;
while dbcursor3%found loop
recNum:=recNum+1;
insert into testmis.zindex_info (dbbm,flbm,bbm,nr) values
('FXHY','FXHY_NULL',strdbcursor1,strdbcursor3);
fetch dbcursor3 into strdbcursor3;
end loop;
close dbcursor3;
end;第二个问题的语句
while dbcursor2%found loop
if strTemp is null then
strTemp:=strdbcursor2;
else
strTemp:=strTemp||'||'' ''|| '||strdbcursor2;
end if;
fetch dbcursor2 into strdbcursor2;
end loop;
close dbcursor2;
end;
execute immediate 'insert into testmis.zindex_info(dbbm,flbm,bbm,nr) '||
'select ''FXHY'',''FXHY_NULL'','''||strdbcursor1||''','||strTemp||' from '||strdbcursor1
fetch dbcursor1 into strdbcursor1;
end loop;
这样肯定不行,存储过程中游标不能这样使用
2.strdbcursor3 varchar2(4000); ---varchar2最大到4000,超过了用clob或者long
輸出看看是否正確?我有試過,可以這樣組合的
插入一个表中,形成select 语句,都是正确的