我想手动将存储过程从 T-SQL(MS SQL Server 2008)转换为 P-SQL(Oracle DB 11g)。我最近尝试使用 SQL Developer 和 SwisSQL Tool 转换此过程,但没有成功。这个存储过程包含一个参数@sptotest 用于搜索一个单词。这是代码:
T-SQL:
CREATE PROCEDURE sp_name @sptotest sysname AS
DECLARE @d datetime,
@tookms int,
@cnt int,
@single_email varchar(80),
@word varchar(50)
DECLARE @testwords TABLE
(no int NOT NULL PRIMARY KEY,
word varchar(80) NOT NULL)
CREATE TABLE #temp(person_id int NOT NULL PRIMARY KEY,
first_name nvarchar(50) NULL,
last_name nvarchar(50) NOT NULL,
birth_date datetime NULL,
email varchar(80) NOT NULL)
SELECT TOP 1 @single_email = email
FROM persons
WHERE person_id BETWEEN 321106 AND 325000 AND email LIKE '%.com'
ORDER BY person_id
INSERT @testwords(no, word)
SELECT 1, 'joy'
UNION ALL
SELECT 4, @single_email
PRINT '------------------ Testing ' + ' ' + quotename(@sptotest) + ' ----'
DECLARE cur CURSOR STATIC LOCAL FOR
SELECT word FROM @testwords ORDER BY no
OPEN cur
WHILE 1 = 1
BEGIN
FETCH cur INTO @word
IF @@fetch_status <> 0
BREAK
TRUNCATE TABLE #temp
CHECKPOINT
DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS
SELECT @d = getdate()
INSERT #temp
EXEC @sptotest @word
SELECT @tookms = datediff(ms, @d, getdate())
SELECT @cnt = COUNT(*) FROM #temp
PRINT ltrim(str(@tookms)) + ' ms, ' +
ltrim(str(@cnt)) + ' rows. Word = "' + @word + '".'
TRUNCATE TABLE #temp
SELECT @d = getdate()
INSERT #temp
EXEC @sptotest @word
SELECT @tookms = datediff(ms, @d, getdate())
SELECT @cnt = COUNT(*) FROM #temp
PRINT ltrim(str(@tookms)) + ' ms, ' +
ltrim(str(@cnt)) + ' rows. Word = "' + @word + '". Data in cache.'
END
DEALLOCATE cur
提前致谢。