Sunday, February 12, 2012

Converting PL/SQL

I have an anonymous PL/SQL block that I'd like to Convert into T-Sql and im completly stumped on 2 things:
    What is the equvilent of a Cursor and how do I declare one?How do I declare an anonymous block?

my code wrote:


Declare
-- Type Declarations
Type ct_UConstr_Cur is REF CURSOR;
v_Begin Integer := 0;
v_End Integer := 0;
v_PageSize Integer :=0;
c_Data ct_UConstr_Cur;

Begin
v_PageSize := :PageSize;
v_Begin := ( v_PageSize * :PageNumber) - 1;
v_End := v_Begin + v_PageSize;

Open c_Data For
Select * from (
Select A, B, C, ROWNUM as RN from Foo;
) where RN >= v_Begin AND RN < v_End;
:cur := c_Data;
END;
/


JeffreyABecker wrote:

What is the equvilent of a Cursor and how do I declare one?


That would be ... a cursor. But how are you using it? If you're trying to pass output cursors from a stored procedure, just use result sets instead (i.e., SELECTs).

JeffreyABecker wrote:

How do I declare an anonymous block?


There is no such thing in T-SQL (thank Microsoft!). Just write your block of code. Here's a rough conversion of yours. Note we do not have ROWNUM in T-SQL. For an alternative, post the specific problem ...
DECLARE @.Begin INTEGER, @.End INTEGER, @.PageSize INTEGER
DECLARE @.Cur CURSOR
SET @.Begin = (@.PageSize * @.PageNumber) -1
SET @.Cur = CURSOR FOR SELECT * FROM A, B,C
OPEN @.Cur
... Do your ugly cursor stuff here, see BOL for how to ...
CLOSE @.Cur
|||

Try this link to test drive a conversion tool. Hope this helps.

http://www.downloadjunction.com/company/store/6265/index.html

No comments:

Post a Comment