我正在尝试将一些Oracle存储过程转换为MSSQL我做了一些基本的SP但是我在使用游标转换SP时遇到了麻烦。
这是一个例子: -
create or replace procedure PR_DELETE_FOLDER(indexedFolder NUMBER,indexedPath VARCHAR2,userCode VARCHAR2,folpath VARCHAR2,idpath VARCHAR2,folderid NUMBER) as
cursor c1(pfolid in NUMBER) is
SELECT folder.PARENTFOLDER, folder.FOLDERNAME, folder.FOLDERID ,sys_connect_by_path(folder.FOLDERNAME,'>>') FOLDERPATH , sys_connect_by_path(folder.FOLDERID,'>>') FOLDERIDPATH
FROM T_FOLDER folder
START WITH folder.PARENTFOLDER =pfolid
CONNECT BY PRIOR folder.FOLDERID=folder.PARENTFOLDER;
cursor c2(folid in NUMBER) is SELECT DOCUMENTID,DOCUMENTNAME from T_DOCUMENT where folder = folid;
begin
for r1 in c1(folderid) loop
update T_FOLDER set last_update=sysdate,STATUS=0 where folderid=r1.FOLDERID;
update T_FOLDER set foldercount = foldercount-1 where folderid = r1.PARENTFOLDER;
-- insert into T_FOLDER_AUDIT values(SEQ_FOLDER_AUDIT.nextval,r1.FOLDERID,'Delete a folder',userCode,sysdate,sysdate,userCode,userCode,1);
insert into t_historical_event values(SEQ_HISTORICAL_EVENT.nextval,r1.FOLDERID,null,'com.affno.adms.folder.Folder',null,'Updated',userCode,r1.FOLDERNAME,sysdate,sysdate,sysdate,userCode,userCode,1);
for r2 in c2(r1.FOLDERID) loop
update T_DOCUMENT set LAST_UPDATE = sysdate,ISUPDATEINDEXES=1,MODIFIEDBY=userCode,STATUS=0 where documentid = r2.DOCUMENTID;
update T_FOLDER set doccount=doccount-1 where folderid=r1.FOLDERID;
insert into T_DOCUMENT_AUDIT values(SEQ_DOC_AUDIT.nextval,'delete',r2.DOCUMENTID,'Original',sysdate,sysdate,userCode,userCode,1,userCode);
insert into t_historical_event values(SEQ_HISTORICAL_EVENT.nextval,r2.DOCUMENTID,null,'com.affno.adms.document.Document',null,'Deleted',userCode,r2.DOCUMENTNAME,sysdate,sysdate,sysdate,userCode,userCode,1);
end loop;
end LOOP;
end;
我不熟悉MSSQL游标,所以我对此问题一无所知。
感谢。
答案 0 :(得分:0)
msdn文章中有一些例子: DECLARE CURSOR (Transact-SQL)
USE AdventureWorks2008R2;
GO
DECLARE vend_cursor CURSOR
FOR SELECT BusinessEntityID, Name, CreditRating FROM Purchasing.Vendor
OPEN vend_cursor
FETCH NEXT FROM vend_cursor;
答案 1 :(得分:0)
您可以尝试为此目的转换应用程序,例如http://www.convert-in.com/ora2mss.htm - >不幸的是,49美元并不便宜。