Tuesday, March 20, 2012

PL-SQL LOOP equivilant in TRANSACT-SQL

Hi,

I need to convert this anonymous pl-sql block into transact-sql to run
in Microsoft SQL Server Query Analyser.

Does anyone know what the conversion syntax would be?

I know that to declare variables to use the @..
PRINT for printing the output.

No idea for the LOOP.

Any suggestions greatly appreciated.

Many thanks.

Thiko!
____________________________________________

SET SERVEROUTPUT ON

DECLARE
recordcount NUMBER;

BEGIN
DBMS_OUTPUT.ENABLE(5000000); -- Sets buffer size.
recordcount := 0;

LOOP
INSERT INTO RecoverTest VALUES (SYSDATE - (recordcount / 4));
COMMIT; -- frees up rollback segment;
recordcount := recordcount + 1;
DBMS_OUTPUT.PUT_LINE('INSERT: ' || recordcount || ' - 45000 ');
EXIT WHEN recordcount > 45000;
END LOOP;
END;
/Not certain about the Oracle date arithmetic but take a look at this post
which was a very similar requirement:
http://tinyurl.com/tlpi

--
David Portas
----
Please reply only to the newsgroup
--

No comments:

Post a Comment