开发者

Converting Oracle stored procedure to MSSQL

开发者 https://www.devze.com 2023-03-08 08:36 出处:网络
I\'m trying to convert some Oracle stored procedures to MSSQL I did some basic SP\'s but I\'m having a trouble converting SP\'s with cursors.

I'm trying to convert some Oracle stored procedures to MSSQL I did some basic SP's but I'm having a trouble converting SP's with cursors.

here's a example :-

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_开发者_JS百科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;  

I'm not familiar with MSSQL cursors so I got no clue on this issue.

Thanks.


There are examples in the msdn article: 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;


You could try a made for this purpose conversion application such as http://www.convert-in.com/ora2mss.htm --> Unfortunately, at $49 it ain't cheap.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号