Write PL/SQL program to convert each digit of a given number into its corresponding word format.
DECLARE
-- declare necessary variables
-- num represents the given number
-- number_to_word represents the word format of the number
-- str, len and digit are the intermediate variables used for program execution
num INTEGER;
number_to_word VARCHAR2(100);
digit_str VARCHAR2(100);
len INTEGER;
digit INTEGER;
BEGIN
num := 123456;
len := LENGTH(num);
dbms_output.PUT_LINE('Input: ' ||num);
-- Iterate through the number one by one
FOR i IN 1..len LOOP
digit := SUBSTR(num, i, 1);
-- Using DECODE, get the str representation of the digit
SELECT Decode(digit, 0, 'Zero ',
1, 'One ',
2, 'Two ',
3, 'Three ',
4, 'Four ',
5, 'Five ',
6, 'Six ',
7, 'Seven ',
8, 'Eight ',
9, 'Nine ')
INTO digit_str
FROM dual;
-- Append the str representation of digit to final result.
number_to_word := number_to_word || digit_str;
END LOOP;
dbms_output.PUT_LINE('Output: ' ||number_to_word);
END;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。