Convert Function from English to Bengali digits

Sometimes we may want to convert digits in English to Bengali or a Different Language.
We might use the following function to convert - 

CREATE OR REPLACE FUNCTION F_Bdigits(input_value IN NUMBER)
RETURN VARCHAR2
IS 
bengali_digits CONSTANT VARCHAR2(5000) := '০১২৩৪৫৬৭৮৯'; -- Bengali digits in order
  result VARCHAR2(4000);
  input_string VARCHAR2(4000);
BEGIN
  -- Handle NULL input gracefully
  IF input_value IS NULL THEN
    RETURN NULL;
  END IF;
  -- Format the number in Indian style with commas
  input_string := TO_CHAR(input_value, 'FM99,99,99,99,990.00');
  -- Replace each digit (0-9) with its Bengali equivalent
  result := input_string;
  FOR i IN 0..9 LOOP
    result := REPLACE(result, TO_CHAR(i), SUBSTR(bengali_digits, i + 1, 1));
  END LOOP;
  RETURN result;
EXCEPTION
  WHEN OTHERS THEN
    RETURN 'Error in conversion'; -- Graceful error handling
END;
/

Check in sqlplus :

SELECT F_bdigits(1234567890) FROM DUAL;




Muhammad Abdullah Al Noor

Muhammad Abdullah Al Noor, An Oracle Apex Consultants and founder of Noors Technology (www.noorstech.com). Core Expertise : Database Administration, Oracle Forms and Reports Development, Oracle Apex Application Designer and Development, Linux Professional etc. Also the owner of TrainerBD Training and OraDemy E-Learning. WhatsApp +8801790721177

Post a Comment

Previous Post Next Post