Thursday, January 21, 2021

Oracle Package

Oracle package with procedure, function and global variable

CREATE OR REPLACE PACKAGE my_package AS
    g_fav_num NUMBER := 5;
    PROCEDURE my_proc (val INTEGER);
    FUNCTION  double_func (in_val IN NUMBER) RETURN NUMBER; 
END my_package;
/

CREATE OR REPLACE PACKAGE BODY my_package ASPROCEDURE my_proc (val INTEGER) IS
  BEGIN
      g_fav_num := g_fav_num + val;
      INSERT INTO my_table ( total ) VALUES ( double_func(g_fav_num) );
  END;

  FUNCTION double_func (in_val IN NUMBER) RETURN NUMBER IS 
  BEGIN 
    RETURN in_val*2;
  END;

END my_package;
/

exec my_package.my_proc(1000);

No comments:

Post a Comment