FUNCTION Georgian2Hijri(G_DATE Date) RETURN Varchar2 IS
  H_DAY      NUMBER(2):=0;
  HDAY       VARCHAR2(2);
  H_MONTH    NUMBER(2):=1;
  HMONTH     VARCHAR2(2);
  H_YEAR     NUMBER(4):=1;
  FGDATE     DATE;
  I_LOOP     NUMBER;
  HY         NUMBER;
  MONTH_NAME VARCHAR2(40);
BEGIN
  FGDATE := TO_DATE('14-07-0622','DD-MM-YYYY');
  I_LOOP := G_DATE - FGDATE;
  LOOP
    IF I_LOOP<355 THEN
      EXIT;
    END IF;
    HY := TRUNC( H_YEAR / 30 ) * 30;
    IF (H_YEAR - HY) IN (2,5,7,10,13,16,18,21,24,26,29) THEN
      H_YEAR := H_YEAR + 1;
      I_LOOP := I_LOOP - 355;
    ELSE
      I_LOOP := I_LOOP - 354;
      H_YEAR := H_YEAR + 1;
    END IF;
  END LOOP; 
  FOR I IN 1..I_LOOP LOOP
    H_DAY := H_DAY + 1;
    IF (H_MONTH=1 OR H_MONTH=3 OR H_MONTH=5 OR H_MONTH=7 OR H_MONTH=9 OR H_MONTH=11) AND H_DAY>30 THEN
      H_MONTH := H_MONTH + 1;
      H_DAY   := 1;
    END IF;
    IF (H_MONTH=2 OR H_MONTH=4 OR H_MONTH=6 OR H_MONTH=8 OR H_MONTH=10)AND H_DAY>29 THEN
      H_MONTH := H_MONTH + 1;
      H_DAY   := 1;
    END IF;
    HY := TRUNC( H_YEAR / 30 ) * 30;
    IF (H_YEAR - HY) IN (2,5,7,10,13,16,18,21,24,26,29) THEN
      IF H_MONTH=12 AND H_DAY>30 THEN
        H_MONTH := H_MONTH + 1;
        H_DAY   := 1;
        IF H_MONTH>12 THEN
          H_YEAR  := H_YEAR + 1;
          H_MONTH := 1;
        END IF;
      END IF;
    ELSE
      IF H_MONTH=12 AND H_DAY>29 THEN
        H_MONTH := H_MONTH + 1;
        H_DAY   := 1;
        IF H_MONTH>12 THEN
          H_YEAR  := H_YEAR + 1;
          H_MONTH := 1;
        END IF;
      END IF;
    END IF;
  END LOOP;
  SELECT DECODE(H_MONTH
         ,1,'محمرم'
         ,2,'صفر'
         ,3,'ربيع الأول'
         ,4,'ربيع الثاني'
         ,5,'جمادى الأولى'
         ,6,'جمادى الآخرة'
         ,7,'رجب'
         ,8,'شعبان'
         ,9,'رمضان'
         ,10,'ذو القعدة'
         ,11,'ذو الحجة'
         ,12,'',NULL)
    INTO MONTH_NAME
    FROM DUAL;
  IF H_DAY<10 THEN
    HDAY := '0' || TO_CHAR(H_DAY);
  ELSE
    HDAY := TO_CHAR(H_DAY);
  END IF;
  IF H_MONTH<10 THEN
    HMONTH := '0' || TO_CHAR(H_MONTH);
  ELSE
    HMONTH := TO_CHAR(H_MONTH);
  END IF;
  Return (HDAY || '-' || MONTH_NAME || '-' || TO_CHAR(H_YEAR));
END Georgian2Hijri;
