将 PlSql 函数转换为 Tsql

发布于 2024-11-02 11:45:00 字数 1904 浏览 0 评论 0原文

我想将以下函数从 plsql 转换为 tsql。但是我不擅长 tsql,而且 swisssql 也无法正确转换它。你能看一下吗?谢谢

CREATE OR REPLACE function yonetici_kontrol_musteri (p_ID_MUSTERI_SIRKET in number, p_ID_YONETICI in number) 
return number
is
v_unvan number;
v_yonetici number;
v_tmp_unvan number;
v_tmp_yonetici number;
v_result number;

begin

v_result:=-1;


SELECT id_unvan  INTO v_unvan  FROM lu_yonetici WHERE id_yonetici=p_ID_YONETICI;


for c in (  SELECT NVL (b.id_mufettis, 0) id_mufettis, b.id_sef
              FROM cr_rut_musteri c, lu_bayi_temsilci b
             WHERE c.id_musteri_sirket = p_id_musteri_sirket
               AND c.id_temsilci = b.id_temsilci
               AND c.valid = 1
               AND b.valid = 1
               AND c.aktif = 1
               AND b.aktif = 1
          ) 
loop

    CASE v_unvan
    WHEN 1 THEN
        if c.id_mufettis = p_ID_YONETICI then
           v_result:=1;
        else
           v_result:=0;
        end if;
    WHEN 2 THEN -- satis sefi
        if c.id_sef = p_ID_YONETICI then
           v_result:=1;
        else
           v_result:=0;
        end if;
    ELSE 
        v_yonetici:=c.id_sef;

        loop
            SELECT uy.id_unvan, uy.id_yonetici INTO v_tmp_unvan, v_tmp_yonetici  
              FROM lu_yonetici y, lu_yonetici uy 
             WHERE y.id_ust_yonetici=uy.id_yonetici
               AND y.id_yonetici=v_yonetici;

             if v_tmp_unvan=v_unvan then
                 if v_tmp_yonetici=p_ID_YONETICI then
                    v_result:=1;
                 else
                    v_result:=0;             
                 end if;
             else
                 v_yonetici:=v_tmp_yonetici;
             end if;

             exit when v_result=1 or v_tmp_unvan>=v_unvan;
        end loop;       
    END CASE;
    exit when v_result=1;

end loop;         

return v_result;
exception 
when others then 
return 0;
end;

I want to convert following function from plsql into tsql.But i am not good at in tsql and also swisssql couldnt convert it correctly.Can u look at it?Thanks

CREATE OR REPLACE function yonetici_kontrol_musteri (p_ID_MUSTERI_SIRKET in number, p_ID_YONETICI in number) 
return number
is
v_unvan number;
v_yonetici number;
v_tmp_unvan number;
v_tmp_yonetici number;
v_result number;

begin

v_result:=-1;


SELECT id_unvan  INTO v_unvan  FROM lu_yonetici WHERE id_yonetici=p_ID_YONETICI;


for c in (  SELECT NVL (b.id_mufettis, 0) id_mufettis, b.id_sef
              FROM cr_rut_musteri c, lu_bayi_temsilci b
             WHERE c.id_musteri_sirket = p_id_musteri_sirket
               AND c.id_temsilci = b.id_temsilci
               AND c.valid = 1
               AND b.valid = 1
               AND c.aktif = 1
               AND b.aktif = 1
          ) 
loop

    CASE v_unvan
    WHEN 1 THEN
        if c.id_mufettis = p_ID_YONETICI then
           v_result:=1;
        else
           v_result:=0;
        end if;
    WHEN 2 THEN -- satis sefi
        if c.id_sef = p_ID_YONETICI then
           v_result:=1;
        else
           v_result:=0;
        end if;
    ELSE 
        v_yonetici:=c.id_sef;

        loop
            SELECT uy.id_unvan, uy.id_yonetici INTO v_tmp_unvan, v_tmp_yonetici  
              FROM lu_yonetici y, lu_yonetici uy 
             WHERE y.id_ust_yonetici=uy.id_yonetici
               AND y.id_yonetici=v_yonetici;

             if v_tmp_unvan=v_unvan then
                 if v_tmp_yonetici=p_ID_YONETICI then
                    v_result:=1;
                 else
                    v_result:=0;             
                 end if;
             else
                 v_yonetici:=v_tmp_yonetici;
             end if;

             exit when v_result=1 or v_tmp_unvan>=v_unvan;
        end loop;       
    END CASE;
    exit when v_result=1;

end loop;         

return v_result;
exception 
when others then 
return 0;
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

無心 2024-11-09 11:45:00

您可能想尝试 SwisSQL 在线迁移工具

它给出以下结果:

--SWISSQL DROP SCRIPTS 
If Exists ( SELECT name 
            FROM sysobjects  
            WHERE name = 'yonetici_kontrol_musteri'
            AND type = 'FN')
    DROP FUNCTION yonetici_kontrol_musteri
GO 
CREATE FUNCTION yonetici_kontrol_musteri
(
    @p_ID_MUSTERI_SIRKET                      FLOAT ,
    @p_ID_YONETICI                            FLOAT 
)
RETURNS FLOAT 
AS 
    BEGIN


        DECLARE @adv_error INT

        DECLARE @v_unvan                                  FLOAT 
        DECLARE @v_yonetici                               FLOAT 
        DECLARE @v_tmp_unvan                              FLOAT 
        DECLARE @v_tmp_yonetici                           FLOAT 
        DECLARE @v_result                                 FLOAT 
        SELECT @v_result  = - 1 
        SELECT @v_unvan  =  id_unvan
        FROM  lu_yonetici 
        WHERE    id_yonetici  = @p_ID_YONETICI


        SELECT @adv_error = @@ERROR
        IF @adv_error != 0 
        BEGIN
            GOTO Exception1
        END



        DECLARE cursor_for_inline_select1 CURSOR LOCAL FOR 
        SELECT
                 ISNULL(b.id_mufettis, 0) id_mufettis,
                 b.id_sef
        FROM  cr_rut_musteri c,
             lu_bayi_temsilci b 
        WHERE    c.id_musteri_sirket  = @p_id_musteri_sirket
         AND    c.id_temsilci  = b.id_temsilci
         AND    c.valid  = 1
         AND    b.valid  = 1
         AND    c.aktif  = 1
         AND    b.aktif  = 1

        OPEN cursor_for_inline_select1 

        FETCH NEXT FROM  cursor_for_inline_select1 INTO 
                            /* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */

        WHILE (@@FETCH_STATUS <> -1)

        BEGIN

            IF @v_unvan  = 1 
            BEGIN 
            IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_mufettis = @p_ID_YONETICI 
            BEGIN 
                SELECT @v_result  = 1 
            END
            ELSE
            BEGIN 
                SELECT @v_result  = 0 
            END
            END 
            ELSE
            IF @v_unvan  = 2 
            BEGIN 
            -- satis sefi

            IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_sef = @p_ID_YONETICI 
            BEGIN 
                SELECT @v_result  = 1 
            END
            ELSE
            BEGIN 
                SELECT @v_result  = 0 
            END
            END 
            ELSE 
            BEGIN 
            SELECT @v_yonetici  = /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_sef 
            DECLARE @count       INT 
        SELECT @count = 1 
        WHILE (0 = 0) 
            BEGIN --( 
                SELECT
                         @v_tmp_unvan  =  uy.id_unvan,
                         @v_tmp_yonetici  =  uy.id_yonetici
                FROM  lu_yonetici y,
                     lu_yonetici uy 
                WHERE    y.id_ust_yonetici  = uy.id_yonetici
                 AND    y.id_yonetici  = @v_yonetici


                SELECT @adv_error = @@ERROR
                IF @adv_error != 0 
                BEGIN
                    GOTO Exception1
                END

                IF @v_tmp_unvan = @v_unvan 
                BEGIN 
                    IF @v_tmp_yonetici = @p_ID_YONETICI 
                    BEGIN 
                        SELECT @v_result  = 1 
                    END
                    ELSE
                    BEGIN 
                        SELECT @v_result  = 0 
                    END

                END
                ELSE
                BEGIN 
                    SELECT @v_yonetici  = @v_tmp_yonetici 
                END

                IF @v_result = 1 or @v_tmp_unvan >= @v_unvan 
                BREAK

            SELECT @count=@count +1
            END --) 

            END 
            IF @v_result = 1 
            BREAK



        FETCH NEXT FROM  cursor_for_inline_select1 INTO 
                            /* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */
        END
        CLOSE cursor_for_inline_select1
        DEALLOCATE cursor_for_inline_select1


 DEALLOCATE cursor_for_inline_select1
        return @v_result
        GOTO ExitLabel1
        Exception1:

            BEGIN

 DEALLOCATE cursor_for_inline_select1
            return 0 
            /* SwisSQL (Oracle To SQL Server) : Manual Intervention to verify Exception is required */
            END
        ExitLabel1:

        return @v_result

    END


GO
 ########################################################################################################

编辑:有关更多详细信息,请参阅 这个问题

You might want to try the SwisSQL Online migration tool

It gives the following result:

--SWISSQL DROP SCRIPTS 
If Exists ( SELECT name 
            FROM sysobjects  
            WHERE name = 'yonetici_kontrol_musteri'
            AND type = 'FN')
    DROP FUNCTION yonetici_kontrol_musteri
GO 
CREATE FUNCTION yonetici_kontrol_musteri
(
    @p_ID_MUSTERI_SIRKET                      FLOAT ,
    @p_ID_YONETICI                            FLOAT 
)
RETURNS FLOAT 
AS 
    BEGIN


        DECLARE @adv_error INT

        DECLARE @v_unvan                                  FLOAT 
        DECLARE @v_yonetici                               FLOAT 
        DECLARE @v_tmp_unvan                              FLOAT 
        DECLARE @v_tmp_yonetici                           FLOAT 
        DECLARE @v_result                                 FLOAT 
        SELECT @v_result  = - 1 
        SELECT @v_unvan  =  id_unvan
        FROM  lu_yonetici 
        WHERE    id_yonetici  = @p_ID_YONETICI


        SELECT @adv_error = @@ERROR
        IF @adv_error != 0 
        BEGIN
            GOTO Exception1
        END



        DECLARE cursor_for_inline_select1 CURSOR LOCAL FOR 
        SELECT
                 ISNULL(b.id_mufettis, 0) id_mufettis,
                 b.id_sef
        FROM  cr_rut_musteri c,
             lu_bayi_temsilci b 
        WHERE    c.id_musteri_sirket  = @p_id_musteri_sirket
         AND    c.id_temsilci  = b.id_temsilci
         AND    c.valid  = 1
         AND    b.valid  = 1
         AND    c.aktif  = 1
         AND    b.aktif  = 1

        OPEN cursor_for_inline_select1 

        FETCH NEXT FROM  cursor_for_inline_select1 INTO 
                            /* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */

        WHILE (@@FETCH_STATUS <> -1)

        BEGIN

            IF @v_unvan  = 1 
            BEGIN 
            IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_mufettis = @p_ID_YONETICI 
            BEGIN 
                SELECT @v_result  = 1 
            END
            ELSE
            BEGIN 
                SELECT @v_result  = 0 
            END
            END 
            ELSE
            IF @v_unvan  = 2 
            BEGIN 
            -- satis sefi

            IF /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_sef = @p_ID_YONETICI 
            BEGIN 
                SELECT @v_result  = 1 
            END
            ELSE
            BEGIN 
                SELECT @v_result  = 0 
            END
            END 
            ELSE 
            BEGIN 
            SELECT @v_yonetici  = /* SwisSQL (Oracle To SQL Server) : Manual Conversion Required */   c.id_sef 
            DECLARE @count       INT 
        SELECT @count = 1 
        WHILE (0 = 0) 
            BEGIN --( 
                SELECT
                         @v_tmp_unvan  =  uy.id_unvan,
                         @v_tmp_yonetici  =  uy.id_yonetici
                FROM  lu_yonetici y,
                     lu_yonetici uy 
                WHERE    y.id_ust_yonetici  = uy.id_yonetici
                 AND    y.id_yonetici  = @v_yonetici


                SELECT @adv_error = @@ERROR
                IF @adv_error != 0 
                BEGIN
                    GOTO Exception1
                END

                IF @v_tmp_unvan = @v_unvan 
                BEGIN 
                    IF @v_tmp_yonetici = @p_ID_YONETICI 
                    BEGIN 
                        SELECT @v_result  = 1 
                    END
                    ELSE
                    BEGIN 
                        SELECT @v_result  = 0 
                    END

                END
                ELSE
                BEGIN 
                    SELECT @v_yonetici  = @v_tmp_yonetici 
                END

                IF @v_result = 1 or @v_tmp_unvan >= @v_unvan 
                BREAK

            SELECT @count=@count +1
            END --) 

            END 
            IF @v_result = 1 
            BREAK



        FETCH NEXT FROM  cursor_for_inline_select1 INTO 
                            /* SwisSQL (Oracle To SQL Server) : Table Information is not found in METADATA for the CURSOR used by the record-index */
        END
        CLOSE cursor_for_inline_select1
        DEALLOCATE cursor_for_inline_select1


 DEALLOCATE cursor_for_inline_select1
        return @v_result
        GOTO ExitLabel1
        Exception1:

            BEGIN

 DEALLOCATE cursor_for_inline_select1
            return 0 
            /* SwisSQL (Oracle To SQL Server) : Manual Intervention to verify Exception is required */
            END
        ExitLabel1:

        return @v_result

    END


GO
 ########################################################################################################

edit:for further details look into this question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文