Indian money to character conversion

A script that converts numbers in the form of Indian money (rupees, paises, etc) into characters.

This solution is designed to convert numbers into words: for example, 100 to One Hundred. Since I am from India,...

this example uses rupees (for dollars), paises (for cents), lacs (10 lac=one milion), and so on, so you'll need to modify it to fit your needs. Here is the code for Oracle:

```*/

create or replace package num_to_word is
function to_num(num number) return char;
end;
/
create or replace package body num_to_word is

function num_to_char1 (num number) return char is
a number;
var_return  varchar(100);
begin
if num=1 then
return 'One';
elsif num=2 then
return 'Two';
elsif num=3 then
return 'Three';
elsif num=4 then
return 'Four';
elsif num=5 then
return 'Five';
elsif num=6 then
return 'Six';
elsif num=7 then
return 'Seven';
elsif num=8 then
return 'Eight';
elsif num=9 then
return 'Nine';
elsif num =0 then
return null;
end if;
end;

function num_to_char2 (num number) return char is
a number;
var_return  varchar(100);
begin
if  num=20 then
return ' Twenty';
elsif num=30 then
return ' Thirty';
elsif num=40 then
return ' Fourty';
elsif num=50 then
return ' Fifty';
elsif num=60 then
return ' Sixty';
elsif num=70 then
return ' Seventy';
elsif num=80 then
return ' Eighty';
elsif num=90 then
return ' Ninety';
else
return null;
end if;
end;

function num_to_char3 (num number) return char is
a number;
var_return  varchar(100);
begin
if  num=11 then
return 'Eleven';
elsif num=12 then
return 'Twelve';
elsif num=13 then
return 'Thirteen';
elsif num=14 then
return 'Fourteen';
elsif num=15 then
return 'Fifteen';
elsif num=16 then
return 'Sixteen';
elsif num=17 then
return 'Seventeen';
elsif num=18 then
return 'Eighteen';
elsif num =19 then
return 'Nineteen';
else return null;
end if;
end;

function to_num(num number) return char is
a number;
var_return   varchar(500);
num1   number:=num;
var_remain1   number;
begin

a:=length(num1);
if a=6 or a=7 then
var_remain1:=(trunc(num1/100000));
a:=length(var_remain1);
if a=2 then
if var_remain1=10 then
var_return:=var_return||' Ten ';
elsif var_remain1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(var_remain1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(var_remain1,-1));
var_remain1:=mod(var_remain1,10);
end loop;
end if;
end if;
a:=length(var_remain1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(var_remain1);
end if;
var_return:=var_return||' Lac ';
num1:=mod(num1,100000);
end if;

a:=length(num1);
if a =5 or a=4 then
var_remain1:=(trunc(num1/1000));
a:=length(var_remain1);
if a=2 then
if var_remain1=10 then
var_return:=var_return||' Ten ';
elsif var_remain1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(var_remain1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(var_remain1,-1));
var_remain1:=mod(var_remain1,10);
end loop;
end if;
end if;

a:=length(var_remain1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(var_remain1);
end if;
var_return:=var_return||' Thousand ';
num1:=mod(num1,1000);
end if;

a:=length(num1);
if a =3 then
for i in 1..9 loop
if trunc(num1/100)=i then
var_return:=var_return|| num_to_char1(i)||' Hundered';
num1:=mod(num1,100);
end if;
end loop;
end if;

a:=length(num1);
if a=2 then
if num1=10 then
var_return:=var_return||' Ten';
elsif num1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(num1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(num1,-1));
num1:=mod(num1,10);
end loop;
end if;
end if;

a:=length(num1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(num1);
end if;
return var_return;
end;

end ;
/
```

• The Best Oracle Web Links: tips, tutorials, scripts, and more.
• Have an Oracle tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
• Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was last published in November 2001

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

SearchDataManagement

• Cross-platform integration, data preparation process grows in cloud

While cloud computing may be convenient and more cost-effective for users, it can also lead to new challenges and requirements in...

• Graph data model cements tight relationships between data elements

Graph databases can help define and discover relationships between entities -- and offer increased flexibility and better ...

• Microsoft SQL Server 2016 relational DBMS overview

Microsoft SQL Server 2016 for Windows comes in four editions, with updates that include a new stretch database feature, Polybase,...

• Creative projects leave people guessing about future impact of AI

A push is underway to write creative AI algorithms that can engage in music, film and design projects. So far, they have ...

• Data visualization plays an important role in a big data environment

Enterprises are increasingly putting data visualization tools, like Tableau, at the top of their big data platforms to start ...

SearchSAP

• Does SAP ONE Support Launchpad make SAP support any easier to use?

The new Fiori user experience makes it easier to access applications and support services, but product-specific support still ...

• At SME Summit, SAP Anywhere growing pains revealed

Attendees at an SAP SME Summit lauded the e-commerce front end, but some said back-end integration and payment-processing ...

• Planning a HANA big data strategy with SAP HANA Vora

SAP has worked hard to position HANA as a big data platform. To formulate a viable big data strategy, you need to know the tools,...

SearchSQLServer

• SQL Server on Linux signals Microsoft's changing development landscape

Expert Joey D'Antoni explains what SQL Server on Linux and the addition of Enterprise Edition features to Standard Edition say ...

• How to get the most out of virtual SQL Server with Microsoft Hyper-V

SQL Server is a CPU-intensive technology, which can make it tricky to run in a virtualized environment. Keep your SQL Server ...

• Microsoft previews SQL Server on Linux, opens features across editions

Microsoft looks to broaden the horizons of SQL Server, as it moves some Enterprise features to Standard Edition and issues the ...

TheServerSide

• Docker instances become the new norm and adoption goes mainstream

Many organizations use Docker instances for many reasons, although security, data storage and monolithic fears remain barriers to...

• How to turn your DevOps failures into ALM successes

Doing the right thing doesn't always mean you're doing things right. But don't fret, because short-term DevOps failures can mean ...

• From chatbots to IBM's Watson: How software deals with conversational language

The next big thing in software development is conquering the conversational language development hurdle. Here's how the big ...

SearchDataCenter

• Build a data center shutdown procedure to prepare for the worst

A data center shutdown checklist helps IT teams focus on backup, testing and system verification before pulling the plug and ...

• Telcos purge colocation data centers, open door to neutral connections

Enterprise customers in Verizon and CenturyLink's colocation data centers should expect better cloud and network connection ...

• IT slowly embraces composable infrastructure

If there will be a way to make an enterprise data center as efficient and optimized as cloud computing, composable infrastructure...

SearchContentManagement

• Users prefer Office 365 suite collaboration features over SharePoint

Users don't want to jump through hoops, and they want applications to work on mobile devices. Those needs may kill traditional ...

• What new SharePoint features to expect in the next 12 months

Now that Microsoft is developing its SharePoint features, there are new feature rollouts all the time. Here's a rundown of the ...

• How WCM and AI promote smart digital user experiences

Digital user experiences and other business processes are poised to become much richer with artificial intelligence at the helm.

SearchFinancialApplications

• Project planning for a new corporate performance management system

A corporate performance management system touches most aspects of any business. You need a carefully thought-out plan to ensure a...

• No one-size-fits-all strategy for cloud ERP software migration

Experts say a cloud ERP transition plan will vary according to a variety of factors, from company size to an organization's ...

• HR video apps spreading beyond training to recruiting, engagement

Users say cost savings, faster turnaround and better corporate branding are some of the benefits from using video at more stages ...

Close