CREATE OR REPLACE PROCEDURE HRIS_INSERT_MENU(
    P_MENU_NAME HRIS_MENUS.MENU_NAME%TYPE,
    P_ROUTE HRIS_MENUS.ROUTE%TYPE,
    P_ACTION HRIS_MENUS.ACTION%TYPE,
    P_PARENT_MENU HRIS_MENUS.PARENT_MENU%TYPE,
    P_MENU_INDEX HRIS_MENUS.MENU_INDEX%TYPE,
    P_ICON_CLASS HRIS_MENUS.ICON_CLASS%TYPE,
    P_IS_VISIBLE HRIS_MENUS.IS_VISIBLE%TYPE)
AS
  ALREADY_EXISTS CHAR;
  V_MENU_ID HRIS_MENUS.MENU_ID%TYPE;
BEGIN
  SELECT (
    CASE
      WHEN COUNT(*) >0
      THEN 'Y'
      ELSE 'N'
    END)
  INTO ALREADY_EXISTS
  FROM HRIS_MENUS
  WHERE PARENT_MENU =P_PARENT_MENU
  AND ROUTE         =P_ROUTE
  AND ACTION        = P_ACTION;
  IF ALREADY_EXISTS ='N' THEN
    SELECT NVL(MAX(MENU_ID),0)+1 INTO V_MENU_ID FROM HRIS_MENUS;
    INSERT
    INTO HRIS_MENUS
      (
        MENU_ID,
        MENU_NAME,
        PARENT_MENU,
        ROUTE,
        STATUS,
        CREATED_DT,
        ICON_CLASS,
        ACTION,
        MENU_INDEX,
        IS_VISIBLE
      )
      VALUES
      (
        V_MENU_ID,
        P_MENU_NAME,
        P_PARENT_MENU,
        P_ROUTE,
        'E',
        TRUNC(SYSDATE),
        P_ICON_CLASS,
        P_ACTION,
        P_MENU_INDEX,
        P_IS_VISIBLE
      );
  END IF;
END;