如何用字显示数字值 [英] how to display number value in words

查看:96
本文介绍了如何用字显示数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问在单词中显示数字值,输出应如下所示

SAL        In_Words
--------- -----------------------------------------------------
800       eight hundred
1600      one thousand six hundred
1250      one thousand two hundred fifty

而且,我仍然不知道该查询如何作为上述输出的解决方案.

select sal, to_char(to_date(sal,'j'),'Jsp') in_words from emp

to_date在这里做什么?任何人对此查询有任何想法吗?

解决方案

那么查询如何工作?嗯,这就是原因:

select to_char(to_date(:number,'j'),'jsp') from dual;

如果您查询查询的最内层部分to_date(:number,'j'),则'j'或J是儒略历(Julian Date)(公元前4713年1月1日),基本上该日期用于天文研究

因此to_date(:number,'j')接受由数字表示的数字,并假装它是一个儒略日,转换为日期.

如果将3传递给数字,则它将日期转换为公元前4713年1月3日,这意味着儒略历日期将加3.

select to_char(to_date(3,'j'),'jsp') from dual;

现在to_char(to_date(3,'j'),'jsp'),jsp = Now;取那个日期(to_date(3,'j'))并拼写它代表的朱利安数字,输出为:

TO_CH
-----
three

使用儒略日期时有一个限制,范围是1到5373484.这就是为什么如果将值放在5373484之后,则会引发错误,如下所示:

ORA-01854: julian date must be between 1 and 5373484

大家好,这个话题很有趣.我记得2005年我在学习Oracle时,一位指导老师要求我编写一个PL/SQL代码以将数字转换为单词,达到这一目标需要一整整两页的代码.

这里有一些参考资料可以帮助我们理解儒略日,这就是为什么我们在此操作中使用字母'j'或'J'的原因.

首先,有一个网站提供有关如何使用Oracle SQL查询将数字转换为单词"的示例和说明:

http://viralpatel.net/blogs/convert -number-into-words-oracle-sql-query/

第二,如果您想进一步了解朱利安日",请访问:

http://en.wikipedia.org/wiki/Julian_day

第三,如果您想进一步了解谁提出了1583年的儒略日编号,它是约瑟夫·斯卡利格"的写法:

http://en.wikipedia.org/wiki/Joseph_Justus_Scaliger

对于我来说,继续在这些网站上发表其他作者的言论并没有意义,这就是为什么我刚刚发布了链接,您可以访问它们并阅读所需的内容,以了解像这样的查询是如何工作的:

SELECT TO_CHAR (TO_DATE (2447834, 'j'), 'jsp') FROM DUAL;

//输出:24.478.438万

Q. Display the number value in Words and output should look like this

SAL        In_Words
--------- -----------------------------------------------------
800       eight hundred
1600      one thousand six hundred
1250      one thousand two hundred fifty

And, I'm still didn't figure out, how this query is the solution for the above output.

select sal, to_char(to_date(sal,'j'),'Jsp') in_words from emp

What to_date is doing here ? Anyone have any idea about this query ?

解决方案

So how the query works? Well here’s why:

select to_char(to_date(:number,'j'),'jsp') from dual;

If you look into the inner most part of the query to_date(:number,'j') the ‘j’ or J is the Julian Date (January 1, 4713 BC), basically this date is been used for astronomical studies.

So to_date(:number,'j') it take the number represented by number and pretend it is a julian date, convert into a date.

If you pass 3 to number, so it will convert date to 3rd Jan 4713 BC, it means 3 is added to the Julian date.

select to_char(to_date(3,'j'),'jsp') from dual;

Now to_char(to_date(3,'j'),'jsp'), jsp = Now; take that date(to_date(3,'j')) and spell the julian number it represents, the output is:

TO_CH
-----
three

There is a limitation while using Julian dates ,It ranges from 1 to 5373484. That’s why if you put the values after 5373484, it will throw you an error as shown below:

ORA-01854: julian date must be between 1 and 5373484

Hi everyone, it is interesting this topic. I remember when I was learning Oracle in 2005 one of the instructor required me to write a PL/SQL code to convert numbers in words, it was a whole two pages code to reach this.

Here is some reference that could help us to understand the Julian day, that is why we use the letter 'j' or 'J' during this operation.

First there is a website that has the example and explanation about "How To Convert Number Into Words Using Oracle SQL Query":

http://viralpatel.net/blogs/convert-number-into-words-oracle-sql-query/

Second if you want to know more about "Julian day" go to:

http://en.wikipedia.org/wiki/Julian_day

Third if you want to know more about who proposed the Julian day number in 1583, it was by "Joseph Scaliger":

http://en.wikipedia.org/wiki/Joseph_Justus_Scaliger

It is not make sence for me continue repiting what another author in these websites have made, that is why I just posted the link you can access them and read what you need to understand how query like this works:

SELECT TO_CHAR (TO_DATE (2447834, 'j'), 'jsp') FROM DUAL;

//Output: two million four hundred forty-seven thousand eight hundred thirty-four

这篇关于如何用字显示数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆