您好我是 Oracle 的新手,请帮我将以下 SQL Server 存储过程转换为 Oracle 存储过程。
下面显示了我试图转换为 Oracle 的 SQL Server 存储过程,但由于时间太短我无法找到解决方案,请帮助我。
Create PROCEDURE dbo.myprocedure
@name VarChar(50),
@columnid VarChar(50),
@max Int OUTPUT
AS
DECLARE @period int,
@myStatement varChar(255)
SET @period = 99999
SET @max = 0
Create Table #newtable
(
valu INT
)
SET @myStatement = 'Insert INTO #newtable(valu) SELECT max( ' + @columnid + ') FROM ' + @name + ' WHERE ' +
@columnid+ ' <= ' + Convert(varChar(5), @period)
EXEC ( @myStatement )
SELECT @max = valu FROM #newtable
IF (@max = @period)
SET @max =-1
ELSE
SET @max= @max+ 1
DROP Table #newtable
GO
这就是我如何更改为 oracle 存储过程
Create Table newtable( valu INT );
CREATE OR REPLACE
PROCEDURE PROCEDURE1
( name IN VARCHAR2
, columnid IN VARCHAR2
, maxid IN OUT VARCHAR2
)
as
period number;
mystatement varChar(255);
BEGIN
period:= 99999;
maxid:= 0;
mystatement:= 'Insert INTO newtable(valu) SELECT max(columnid) FROM name WHERE columnid <= Convert(varChar(5), period)';
SELECT maxid = valu FROM newtable;
EXECUTE immediate mystatement;
IF (maxid= period)
return maxid:=-1;
ELSE
return maxid:= maxid + 1;
DROP Table newtable;
END PROCEDURE1;