sqlserver存储过程转微oracle的存储过程求教,在线等

USE [chss_back]
GO
/****** 对象: StoredProcedure [dbo].[sp_Public_PyWbmGet] 脚本日期: 07/28/2015 10:54:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[sp_Public_PyWbmGet]
@tablename varchar(32),
@fieldname1 varchar(32),
@fieldname2 varchar(32),
@pybz char(1) = '0'
as
set nocount on

exec('declare @name varchar(255),@shortcut varchar(255)'+
' declare cs_py cursor for select '+@fieldname1+','+@fieldname2+
' from '+@tablename+
' where '+@fieldname2+ ' is null'+
' for update of '+@fieldname2+
' open cs_py'+
' fetch cs_py into @name,@shortcut'+
' while @@fetch_status=0'+
' begin exec sp_Public_PyWbm @name,'+@pybz+',@shortcut output'+
' update '+@tablename+' set '+@fieldname2+'=convert(varchar(40),@shortcut)'+
' where current of cs_py'+
' fetch cs_py into @name,@shortcut end'+
' close cs_py deallocate cs_py'
)
GO

上面太乱了

 1. declare
  2. type empdtlrec is record (empno number(4),
  3. ename varchar2(20),
  4. deptno number(2));
  5. empdtl empdtlrec;
  6. begin
  7. execute immediate ‘select empno, ename, deptno ’ ||
  8. ‘from emp where empno = 7934’
  9. into empdtl;
  10. end;

可参考

http://blog.csdn.net/xiooix2012/article/details/6895594

exec在oracle可以用execute来代替,例如

  1. declare   2. l_routin varchar2(100) := ‘gen2161.get_rowcnt’;   3. l_tblnam varchar2(20) := ‘emp’;   4. l_cnt number;   5. l_status varchar2(200);   6. begin   7. execute immediate ‘begin ’ || l_routin || ‘(:2, :3, :4); end;’   8. using in l_tblnam, out l_cnt, in out l_status;   9. if l_status != ‘OK’ then   10. dbms_output.put_line(‘error’);   11. end if;   12. end;
  1. declare   2. type empdtlrec is record (empno number(4),   3. ename varchar2(20),   4. deptno number(2));   5. empdtl empdtlrec;   6. begin   7. execute immediate ‘select empno, ename, deptno ’ ||   8. ‘from emp where empno = 7934’   9. into empdtl;   10. end;