以下是我的表格:
ENAME SALARY
AAAA $1254.20
GGGG $4565
RRRR $7889.60
WEFDSF $0.00
XXXX N/A
我希望用单词显示薪水,例如:1254.20应显示为一千二百五十四美元二十美分
答案 0 :(得分:1)
显然有一个使用转换为julian日期的整数的黑客攻击:HOW TO: Spell a number or convert a number to words
SELECT TO_CHAR (TO_DATE (1234567, 'j'), 'jsp') FROM DUAL;
您可以将SALARY
拆分为整数美元和美分并应用黑客攻击:
Select
TO_CHAR (TO_DATE (Dollars, 'j'), 'jsp') || ' dollars ' ||
TO_CHAR (TO_DATE (Cents, 'j'), 'jsp') || ' cents' As Spelling
From (
Select
TRUNC(1254.20) As Dollars,
(1254.20 - TRUNC(1254.20)) * 100 As Cents
From DUAL);
不可否认,你还需要支付单一美元/分。 最好在功能中完成。
CREATE OR REPLACE FUNCTION spell_amount
(srcAmnt IN NUMBER)
RETURN VARCHAR2
IS
Dollars INT;
Cents INT;
Result VARCHAR2(1000);
BEGIN
Dollars := Trunc(srcAmnt);
Cents := Trunc((srcAmnt - Dollars)*100);
IF Dollars = 0 THEN
Result := 'no dollars';
ELSIF Dollars = 1 THEN
Result := 'one dollar';
ELSE
Result := TO_CHAR (TO_DATE (Dollars, 'j'), 'jsp') || ' dollars';
END IF;
IF Cents = 0 THEN
Result := Result || ' no cents';
ELSIF Cents = 1 THEN
Result := Result || ' one cent';
ELSE
Result := Result || ' ' || TO_CHAR (TO_DATE (Cents, 'j'), 'jsp') || ' cents';
END IF;
RETURN Result;
END spell_amount;
/
然后
Select spell_amount(132.01) From DUAL;
关于朱利安日期的ORA-01854: julian date must be between 1 and 5373484
限制和可能的解决方案的更多内容:How To Convert Number into Words using Oracle SQL Query
答案 1 :(得分:0)
用您的列名替换12345.15并在替换前从列中删除$ sign。
选择TO_CHAR(TO_DATE(floor(12345.15),'J'),'JSP')||'美元'||案件 当12345.15 - FLOOR(12345.15)> 0然后'And'|| TO_CHAR(TO_DATE(substr('12345.15',instr('12345.15','。')+ 1),'J'),'JSP')| | '美分' INWORDS 来自双重;