Oracle将pl/sql函数转换为sql

falq053o  于 2023-02-21  发布在  Oracle
关注(0)|答案(2)|浏览(193)

我需要把这个pl/sql转换成non pl/sql,因为我们不能访问oracle fusion中的函数和包,但是目前我对pl/sql一无所知,所以我不知道这个函数是做什么的,有人能帮忙吗?

FUNCTION numb(CNUMBER IN NUMBER) RETURN VARCHAR2 IS
    TR          NUMBER;
    FR          NUMBER;
    fakat       VARCHAR2(20) := 'فقط';
    l_vc_ar_num VARCHAR2(32766);
  BEGIN

    IF cnumber > 999999999999.99 THEN
      RETURN 'Please enter a number less than 1 Trillion (1,000,000,000,000.00).';
    END IF;

    TR := TRUNC(CNUMBER, 0);

    FR := (ROUND(CNUMBER, 2) - TRUNC(CNUMBER, 0)) * 100;

    --if fractional part exists then do not append fakat
    --EXCEPTION IS 1 halala where we have to append fakat
    IF FR > 0 THEN

      IF TR = 0 THEN
        IF FR = 1 THEN
          l_vc_ar_num := fraction(FR) || ' ' || fakat;
        ELSE
          l_vc_ar_num := fraction(FR);
        END IF;
      ELSE

        l_vc_ar_num := anumb(TR) || ' و' || fraction(FR);

      END IF;
    ELSE

      l_vc_ar_num := anumb(TR) || ' ' || fakat;

    END IF;

    RETURN REPLACE(REPLACE(l_vc_ar_num, '   ', ' '), '  ', ' ');
  EXCEPTION
    WHEN OTHERS THEN
      RETURN 'function numb. Others. Ex.' || SQLERRM;
  END;
soat7uwm

soat7uwm1#

WITH tmp AS (
    SELECT 
        CNUMBER
        , TRUNC(CNUMBER, 0) TR
        , (ROUND(CNUMBER, 2) - TRUNC(CNUMBER, 0)) * 100 FR
        , 'فقط' fakat
    FROM
    (
        SELECT 
            123332 CNUMBER
        FROM dual
    )
)

SELECT   
    CASE 
        WHEN CNUMBER > 999999999999.99 THEN 
            'Please enter a number less than 1 Trillion (1,000,000,000,000.00).' 
        ELSE 
            REPLACE(
                REPLACE(
                    CASE WHEN FR > 0 THEN
                        CASE WHEN TR = 0 THEN
                            CASE WHEN FR = 1 THEN
                                fraction(FR) || ' ' || fakat
                            ELSE
                                fraction(FR)
                            END
                        ELSE
                            anumb(TR) || ' و' || fraction(FR)
                        END
                    ELSE
                        anumb(TR) || ' ' || fakat 
                    END
                    , '   ', ' '
                )
                , '  ', ' '
            )
        END numb
FROM tmp;
v1uwarro

v1uwarro2#

如果该函数位于与应用程序连接到数据库的用户不同的用户模式中,则可以请求grant execute。如果该函数相当简单,则可以使用case语句实现逻辑。然而,在该函数中,我可以看到对fraction和anumb的调用,我猜这是其他函数,但我无法想象它们在做什么。

相关问题