Oracle SQL function overloading

前端之家收集整理的这篇文章主要介绍了Oracle SQL function overloading前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Sample of implement Oracle sql function overloading,and default parameter.


To define your own to_char(...) function support different kinds of input data type.
Please notice they must be defined in a function package.

CREATE OR REPLACE PACKAGE <PKGNAME> AS
  FUNCTION MY_tochAR(PVALUE IN TIMESTAMP) RETURN VARCHAR2;
  FUNCTION MY_tochAR(PVALUE IN DATE,PFORMAT IN VARCHAR DEFAULT 'YYYY-MM-DD') RETURN VARCHAR2;
  FUNCTION MY_tochAR(PVALUE IN NUMBER,PRECISION IN INT DEFAULT 0,SCALE IN INT DEFAULT 0) RETURN VARCHAR2;
END;
/

CREATE OR REPLACE PACKAGE BODY <PKGNAME> AS
  FUNCTION MY_tochAR(PVALUE IN TIMESTAMP)
    RETURN VARCHAR2
  IS
  BEGIN
    RETURN TO_CHAR(PVALUE,'YYYY-MM-DD-HH24.MI.SS.FF6');
  END;

  FUNCTION MY_tochAR(PVALUE IN DATE,PFORMAT IN VARCHAR)
    RETURN VARCHAR2
  IS
  BEGIN
    RETURN TO_CHAR(PVALUE,PFORMAT);
  END;

  FUNCTION MY_tochAR(PVALUE IN NUMBER,PRECISION IN INT,SCALE IN INT)
    RETURN VARCHAR2
  IS
    VFORMAT VARCHAR2(100);
  BEGIN
    IF PRECISION > 0 THEN
      VFORMAT := ...;
      IF SCALE > 0 THEN
        VFORMAT := ...;
      END IF;
      RETURN LTRIM(TO_CHAR(PVALUE,VFORMAT));
    ELSE
      RETURN TO_CHAR(PVALUE);
    END IF;
  END;

END;
/
原文链接:https://www.f2er.com/oracle/211728.html

猜你在找的Oracle相关文章