存储过程。将t-sql转换成pl / sql

时间:2011-08-07 15:16:49

标签: oracle tsql sql-server-2008 stored-procedures plsql

你好有谁知道如何将以下t-sql存储过程转换为pl / sql:

ALTER FUNCTION [dbo].[AverageAndTall]()
    RETURNS @Players TABLE
    (
        Number INT,
        Name VARCHAR(20),
        Surname VARCHAR(40),
        Height float,
        Position VARCHAR(40),
        FuzzinessLevel float(3)
    )
AS
BEGIN
    DECLARE  @FuzzyLevel float
    INSERT   @Players (Number, Name, Surname, Height, Position, FuzzinessLevel)
    SELECT   Number, Name, Surname, Height, Position, dbo.MembershipLevel_AverageAndTall(Height) 
    FROM     FuzzyFootballTeam       
    RETURN
END

感谢任何提示!

1 个答案:

答案 0 :(得分:2)

您有一个表值用户定义的函数。将其转换为PL / SQL的一种方法是使用返回REF CURSOR的函数。由于涉及某些类型定义,因此最好将其放入包中:

CREATE OR REPLACE PACKAGE FootballTeam
IS

  TYPE AverageAndTallResult IS RECORD (
    NMBR INT,
    NAME VARCHAR2(20),
    SURNAME VARCHAR2(40),
    HEIGHT NUMBER,
    POSITION VARCHAR2(40),
    FUZZINESS_LEVEL NUMBER );

  TYPE AverageAndTallCursor IS REF CURSOR RETURN AverageAndTallResult;

  FUNCTION AverageAndTall
    RETURN AverageAndTallCursor;

END FootballTeam;
/

CREATE OR REPLACE PACKAGE BODY FootballTeam
IS

  FUNCTION AverageAndTall
    RETURN AverageAndTallCursor
  IS

    l_cursor AverageAndTallCursor;

  BEGIN

    OPEN l_cursor FOR
    SELECT  Number, Name, Surname, Height, Position, MembershipLevel_AverageAndTall(Height) 
    FROM    FuzzyFootballTeam;

    RETURN l_cursor;

  END AverageAndTall;

END FootballTeam;
/