开发者社区> 问答> 正文

Write PL/SQL program?

已解决

Write PL/SQL program to convert each digit of a given number into its corresponding word format.

展开
收起
1780169608831412 2021-10-16 18:11:04 617 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。
    采纳回答
    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;
    
    2021-10-16 18:57:39
    赞同 1 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载